Esempio n. 1
0
 public void RemoveFromIndex(string[] keys, string value)
 {
     var analyzer = new AccentedAnalyzer();
     var query = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, keys, analyzer);
     var directory = FSDirectory.Open(System.IO.Directory.GetParent(IndexPath));
     IndexReader idxReader = IndexReader.Open(indexPath);
     var searcher = new IndexSearcher(directory, true);
     query.SetDefaultOperator(QueryParser.Operator.AND);
     var q = query.Parse(value);
     int top = idxReader.MaxDoc();
     var results = TopScoreDocCollector.create(top, true);
     searcher.Search(q, results);
     ScoreDoc[] hits = results.TopDocs().scoreDocs;
     Document[] documents = new Document[hits.Length];
     IndexReader indexReader = null;
     for (int i = 0; i < hits.Length; i++)
     {
         int docId = hits[i].doc;
         indexReader = IndexReader.Open(directory, false);
         indexReader.DeleteDocument(docId);
         indexReader.Commit();
         indexReader.Flush();
         indexReader.Close();
     }
     searcher.Close();
     directory.Close();
 }
Esempio n. 2
0
 public void Index(List<Field> fields)
 {
     var analyzer = new AccentedAnalyzer();
     var directory = FSDirectory.Open(System.IO.Directory.GetParent(IndexPath));
     var writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.LIMITED);
     AddDocument(writer, fields);
     writer.Optimize();
     writer.Commit();
     writer.Close();
 }