public void IndexDocument(BaristaIndexDefinition indexDefinition, string documentId, DocumentDto document)
 {
     ExecuteRestRequest("IndexDocument", Method.POST, request => request.AddBody(new
     {
         indexDefinition,
         document
     }));
 }
Exemple #2
0
        public void IndexDocument(BaristaIndexDefinition indexDefinition, string documentId, DocumentDto document)
        {
            try
            {
                if (documentId.IsNullOrWhiteSpace())
                {
                    throw new ArgumentNullException("documentId", @"A document id must be specified.");
                }

                if (document == null)
                {
                    throw new ArgumentNullException("document", @"A document must be specified.");
                }

                var index = GetOrAddIndex(indexDefinition, true);

                try
                {
                    //Add it to the index.
                    var luceneDocument = DocumentDto.ConvertToLuceneDocument(document);

                    var batch = new IndexingBatch();
                    batch.Add(new BatchedDocument
                    {
                        DocumentId          = documentId,
                        Document            = luceneDocument,
                        SkipDeleteFromIndex = false,
                    });

                    index.IndexDocuments(batch);
                }
                catch (OutOfMemoryException)
                {
                    CloseIndexWriter(indexDefinition, false);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }
 public void IndexDocument(BaristaIndexDefinition indexDefinition, string documentId, DocumentDto document)
 {
     Channel.IndexDocument(indexDefinition, documentId, document);
 }
Exemple #4
0
        public static Lucene.Net.Documents.Document ConvertToLuceneDocument(DocumentDto document)
        {
            //Convert WCF document to Lucene document
            var luceneDocument = new Lucene.Net.Documents.Document();

            foreach (var field in document.Fields)
            {
                Lucene.Net.Documents.Field.Index indexType;
                switch (field.Index)
                {
                case FieldIndexType.NotIndexed:
                    indexType = Field.Index.NO;
                    break;

                case FieldIndexType.Analyzed:
                    indexType = Field.Index.ANALYZED;
                    break;

                case FieldIndexType.AnalyzedNoNorms:
                    indexType = Field.Index.ANALYZED_NO_NORMS;
                    break;

                case FieldIndexType.NotAnalyzed:
                    indexType = Field.Index.NOT_ANALYZED;
                    break;

                case FieldIndexType.NotAnalyzedNoNorms:
                    indexType = Field.Index.NOT_ANALYZED_NO_NORMS;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("Unknown or invalid field index type: " + field.Index);
                }

                Lucene.Net.Documents.Field.Store storeType;
                switch (field.Store)
                {
                case FieldStorageType.Stored:
                    storeType = Field.Store.YES;
                    break;

                case FieldStorageType.NotStored:
                    storeType = Field.Store.NO;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("Unknown or invalid field store type: " + field.Store);
                }

                Lucene.Net.Documents.Field.TermVector termVectorType;
                switch (field.TermVector)
                {
                case FieldTermVectorType.Yes:
                    termVectorType = Field.TermVector.YES;
                    break;

                case FieldTermVectorType.WithOffsets:
                    termVectorType = Field.TermVector.WITH_OFFSETS;
                    break;

                case FieldTermVectorType.WithPositions:
                    termVectorType = Field.TermVector.WITH_POSITIONS;
                    break;

                case FieldTermVectorType.WithPositionsOffsets:
                    termVectorType = Field.TermVector.WITH_POSITIONS_OFFSETS;
                    break;

                case FieldTermVectorType.No:
                    termVectorType = Field.TermVector.NO;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("Unknown or invalid field term vector type: " + field.TermVector);
                }

                IFieldable luceneField;

                if (field is StringFieldDto)
                {
                    var stringField = field as StringFieldDto;

                    luceneField = new Lucene.Net.Documents.Field(stringField.Name, true, stringField.Value,
                                                                 storeType, indexType, termVectorType);
                }
                else if (field is DateFieldDto)
                {
                    var dateField = field as DateFieldDto;

                    var dateString = DateTools.DateToString(dateField.Value, DateTools.Resolution.MILLISECOND);
                    luceneField = new Field(dateField.Name, dateString, storeType, Field.Index.NOT_ANALYZED, termVectorType);
                }
                else if (field is NumericFieldDto)
                {
                    var numericField = field as NumericFieldDto;

                    luceneField = new Lucene.Net.Documents.NumericField(numericField.Name, numericField.PrecisionStep,
                                                                        storeType,
                                                                        field.Index != FieldIndexType.NotIndexed);
                }
                else
                {
                    throw new NotImplementedException();
                }

                if (field.Boost.HasValue)
                {
                    luceneField.Boost = field.Boost.Value;
                }

                luceneDocument.Add(luceneField);
            }

            return(luceneDocument);
        }