public void TestEFDb_BasicIO() { using (EFDbDirectory dir = EFDbDirectory.OpenDir("test")) { // Write into indexes. using (IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), true, IndexWriter.MaxFieldLength.UNLIMITED)) { Tuple <string, string>[] testSet = new[] { Tuple.Create("Kitty", "A cat named with Hello Kitty. It is very cute cat, and it earns more than I do."), Tuple.Create("Snoopy", "A dog named with Snoopy. The dog is very humor, and it earns more than I do too. It never become older. A dog with magic power."), Tuple.Create("TestUpdate", "Nothing"), }; foreach (var t in testSet) { Document doc = new Document(); doc.Add(new Field("main", t.Item1, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS)); doc.Add(new Field("body", t.Item2, Field.Store.NO, Field.Index.ANALYZED)); writer.AddDocument(doc); } } // Search from indexes. using (IndexSearcher searcher = new IndexSearcher(dir)) { QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "body", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30)); Query q = parser.Parse("dog"); TopDocs hits = searcher.Search(q, 2); Assert.IsTrue(hits.TotalHits == 1); } } }
public void TestEFDb_IndexBigFile() { using (EFDbDirectory dir = EFDbDirectory.OpenDir("file")) { dir.BufferSize = 1024; // 1KB, to test multiple File Blocks. // Write into indexes. using (IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), true, IndexWriter.MaxFieldLength.UNLIMITED)) { Tuple <string, string>[] testSet = new[] { Tuple.Create("IndexReader.cs", Properties.Resources.IndexReader), Tuple.Create("IndexWriter.cs", Properties.Resources.IndexWriter), }; foreach (var t in testSet) { Document doc = new Document(); doc.Add(new Field("main", t.Item1, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS)); doc.Add(new Field("body", t.Item2, Field.Store.NO, Field.Index.ANALYZED)); writer.AddDocument(doc); } } // Search from indexes. using (IndexSearcher searcher = new IndexSearcher(dir)) { QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "body", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30)); Query q = parser.Parse("\"public class IndexWriter\""); TopDocs hits = searcher.Search(q, 2); Assert.IsTrue(hits.TotalHits == 1); } } }