private void doTestIndexProperties(bool setIndexProps, bool indexPropsVal, int numExpectedResults) { Dictionary <string, string> props = new Dictionary <string, string>(); // Indexing configuration. props["analyzer"] = typeof(WhitespaceAnalyzer).AssemblyQualifiedName; props["content.source"] = typeof(OneDocSource).AssemblyQualifiedName; props["directory"] = "RAMDirectory"; if (setIndexProps) { props["doc.index.props"] = indexPropsVal.ToString(); } // Create PerfRunData Config config = new Config(props); PerfRunData runData = new PerfRunData(config); TaskSequence tasks = new TaskSequence(runData, TestName, null, false); tasks.AddTask(new CreateIndexTask(runData)); tasks.AddTask(new AddDocTask(runData)); tasks.AddTask(new CloseIndexTask(runData)); tasks.DoLogic(); IndexReader reader = DirectoryReader.Open(runData.Directory); IndexSearcher searcher = NewSearcher(reader); TopDocs td = searcher.Search(new TermQuery(new Term("key", "value")), 10); assertEquals(numExpectedResults, td.TotalHits); reader.Dispose(); }
public static void Main(string[] args) { var p = InitProps(); Config conf = new Config(p); PerfRunData runData = new PerfRunData(conf); // 1. top sequence TaskSequence top = new TaskSequence(runData, null, null, false); // top level, not parallel // 2. task to create the index CreateIndexTask create = new CreateIndexTask(runData); top.AddTask(create); // 3. task seq to add 500 docs (order matters - top to bottom - add seq to top, only then add to seq) TaskSequence seq1 = new TaskSequence(runData, "AddDocs", top, false); seq1.SetRepetitions(500); seq1.SetNoChildReport(); top.AddTask(seq1); // 4. task to add the doc AddDocTask addDoc = new AddDocTask(runData); //addDoc.setParams("1200"); // doc size limit if supported seq1.AddTask(addDoc); // order matters 9see comment above) // 5. task to close the index CloseIndexTask close = new CloseIndexTask(runData); top.AddTask(close); // task to report RepSumByNameTask rep = new RepSumByNameTask(runData); top.AddTask(rep); // print algorithm Console.WriteLine(top.ToString()); // execute top.DoLogic(); }
private void doIndexAndSearchTestWithRepeats(FileInfo file, Type lineParserClass, int numAdds, String storedField) { IndexReader reader = null; IndexSearcher searcher = null; PerfRunData runData = null; try { Dictionary <string, string> props = new Dictionary <string, string>(); // LineDocSource specific settings. props["docs.file"] = file.FullName; if (lineParserClass != null) { props["line.parser"] = lineParserClass.AssemblyQualifiedName; } // Indexing configuration. props["analyzer"] = typeof(WhitespaceAnalyzer).AssemblyQualifiedName; props["content.source"] = typeof(LineDocSource).AssemblyQualifiedName; props["directory"] = "RAMDirectory"; props["doc.stored"] = "true"; props["doc.index.props"] = "true"; // Create PerfRunData Config config = new Config(props); runData = new PerfRunData(config); TaskSequence tasks = new TaskSequence(runData, "testBzip2", null, false); tasks.AddTask(new CreateIndexTask(runData)); for (int i = 0; i < numAdds; i++) { tasks.AddTask(new AddDocTask(runData)); } tasks.AddTask(new CloseIndexTask(runData)); try { tasks.DoLogic(); } finally { tasks.Dispose(); } reader = DirectoryReader.Open(runData.Directory); searcher = NewSearcher(reader); TopDocs td = searcher.Search(new TermQuery(new Term("body", "body")), 10); assertEquals(numAdds, td.TotalHits); assertNotNull(td.ScoreDocs[0]); if (storedField is null) { storedField = DocMaker.BODY_FIELD; // added to all docs and satisfies field-name == value } assertEquals("Wrong field value", storedField, searcher.Doc(0).Get(storedField)); } finally { IOUtils.Dispose(reader, runData); } }