/// <summary> /// Deletes the index. /// </summary> /// <param name="indexPath">The index path.</param> /// <param name="docList">The doc list.</param> /// <returns></returns> public bool DeleteIndex(string indexPath, List <string> docList) { bool result = false; try { using (Lucene.Net.Store.Directory directory = FSDirectory.Open(new DirectoryInfo(indexPath))) { Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29); var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, RegularExpression, analyzer); IndexModifier modifier = new Lucene.Net.Index.IndexModifier(indexPath, analyzer, false); foreach (string doc in docList) { modifier.DeleteDocuments(new Lucene.Net.Index.Term(FilePath, doc)); } modifier.Flush(); modifier.Close(); } } catch (Exception ex) { // Swallow Exceptions here } return(result); }
public virtual void TestIndex() { Directory ramDir = new RAMDirectory(); IndexModifier i = new IndexModifier(ramDir, new StandardAnalyzer(), true); i.AddDocument(GetDoc()); Assert.AreEqual(1, i.DocCount()); i.Flush(); i.AddDocument(GetDoc(), new SimpleAnalyzer()); Assert.AreEqual(2, i.DocCount()); i.Optimize(); Assert.AreEqual(2, i.DocCount()); i.Flush(); i.DeleteDocument(0); Assert.AreEqual(1, i.DocCount()); i.Flush(); Assert.AreEqual(1, i.DocCount()); i.AddDocument(GetDoc()); i.AddDocument(GetDoc()); i.Flush(); // depend on merge policy - Assert.AreEqual(3, i.docCount()); i.DeleteDocuments(allDocTerm); Assert.AreEqual(0, i.DocCount()); i.Optimize(); Assert.AreEqual(0, i.DocCount()); // Lucene defaults: Assert.IsNull(i.GetInfoStream()); Assert.IsTrue(i.GetUseCompoundFile()); Assert.AreEqual(IndexWriter.DISABLE_AUTO_FLUSH, i.GetMaxBufferedDocs()); Assert.AreEqual(10000, i.GetMaxFieldLength()); Assert.AreEqual(10, i.GetMergeFactor()); // test setting properties: i.SetMaxBufferedDocs(100); i.SetMergeFactor(25); i.SetMaxFieldLength(250000); i.AddDocument(GetDoc()); i.SetUseCompoundFile(false); i.Flush(); Assert.AreEqual(100, i.GetMaxBufferedDocs()); Assert.AreEqual(25, i.GetMergeFactor()); Assert.AreEqual(250000, i.GetMaxFieldLength()); Assert.IsFalse(i.GetUseCompoundFile()); // test setting properties when internally the reader is opened: i.DeleteDocuments(allDocTerm); i.SetMaxBufferedDocs(100); i.SetMergeFactor(25); i.SetMaxFieldLength(250000); i.AddDocument(GetDoc()); i.SetUseCompoundFile(false); i.Optimize(); Assert.AreEqual(100, i.GetMaxBufferedDocs()); Assert.AreEqual(25, i.GetMergeFactor()); Assert.AreEqual(250000, i.GetMaxFieldLength()); Assert.IsFalse(i.GetUseCompoundFile()); i.Close(); try { i.DocCount(); Assert.Fail(); } catch (System.SystemException e) { // expected exception } }
public void threadproc_update(object obj) { lock (locker) // If a thread is updating the index, no other thread should be doing anything with it. { try { if (searcher != null) { try { searcher.Close(); } catch (Exception e) { } searcher = null; } Lucene.Net.Index.IndexModifier modifier = new Lucene.Net.Index.IndexModifier(DBNLConfigurationManager.LuceneElement.IndexingFolder, analyzer, false); // same as build, but uses "modifier" instead of write. // uses additional "where" clause for bugid int id = (int)obj; modifier.DeleteDocuments(new Lucene.Net.Index.Term("id", Convert.ToString(id))); var item = new ContentService().GetContentById(id); modifier.AddDocument(create_doc( item.ContentId, item.Content1)); modifier.Flush(); modifier.Close(); } catch (Exception e) { } } }