public void Index(string name, string value) { var doc = new Document(); doc.Add(new Field(name, value, Field.Store.YES, Field.Index.ANALYZED)); Writer.AddDocument(doc); Writer.Optimize(); Writer.Commit(); }
public void Index(DataTable table) { var docs = TableToDocuments(table); foreach (var doc in docs) { Writer.AddDocument(doc); } Writer.Optimize(); Writer.Commit(); }
public void Add(Document doc) { Requires.NotNull("searchDocument", doc); if (doc.GetFields().Count > 0) { try { Writer.AddDocument(doc); } catch (OutOfMemoryException) { lock (_writerLock) { // as suggested by Lucene's doc DisposeWriter(); Writer.AddDocument(doc); } } } }
public Task Aggregate(ArticleSummary article) { Task Aggregate() { Indexing = true; var doc = new Document { new TextField("abstract", article.Abstract, Field.Store.YES), new TextField("title", article.Title, Field.Store.YES), new StringField("tag", article.Tags.First(), Field.Store.YES), new TextField("author", article.Author.Name, Field.Store.YES), new TextField("id", article.Id.ToString(), Field.Store.YES) }; Writer.AddDocument(doc); Writer.Commit(); Indexing = false; return(Task.CompletedTask); } CommitChanges(); return(SerialExecutor.AddNext(Aggregate)); }
public void Index(Dictionary <string, string> values) { if (values == null) { return; } var doc = new Document(); foreach (var value in values) { if (!doc.GetFields().Select(f => f.Name == value.Key).FirstOrDefault()) { doc.Add(new Field(value.Key, value.Value, Field.Store.YES, Field.Index.ANALYZED)); } } Writer.AddDocument(doc); Writer.Optimize(); Writer.Commit(); }
public bool InsertDocument(FileFolder file) { try { if (file != null) { Document doc = new Document(); doc.Add(new Field("FileName", file.Name, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("FilePath", file.FilePath, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("FileType", Enum.GetName(typeof(FileFolder.FileType), file.Type), Field.Store.YES, Field.Index.NOT_ANALYZED)); Writer.AddDocument(doc); //Console.WriteLine(string.Format("File {0} added to index", file.FilePath)); return(true); } return(false); } catch (Exception ex) { logger.WriteToLog(ex.Message); return(false); } }