Lucene.Net.TestSearchForDuplicates.DoTest C# (CSharp) Method

DoTest() private method

private DoTest ( Random random, TextWriter @out, bool useCompoundFiles, int MAX_DOCS ) : void
random System.Random
@out TextWriter
useCompoundFiles bool
MAX_DOCS int
return void
        private void DoTest(Random random, TextWriter @out, bool useCompoundFiles, int MAX_DOCS)
        {
            Store.Directory directory = NewDirectory();
            Analyzer analyzer = new MockAnalyzer(random);
            IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
            MergePolicy mp = conf.MergePolicy;
            mp.NoCFSRatio = useCompoundFiles ? 1.0 : 0.0;
            IndexWriter writer = new IndexWriter(directory, conf);
            if (VERBOSE)
            {
                Console.WriteLine("TEST: now build index MAX_DOCS=" + MAX_DOCS);
            }

            for (int j = 0; j < MAX_DOCS; j++)
            {
                Documents.Document d = new Documents.Document();
                d.Add(NewTextField(PRIORITY_FIELD, HIGH_PRIORITY, Field.Store.YES));
                d.Add(NewTextField(ID_FIELD, Convert.ToString(j), Field.Store.YES));
                writer.AddDocument(d);
            }
            writer.Dispose();

            // try a search without OR
            IndexReader reader = DirectoryReader.Open(directory);
            IndexSearcher searcher = NewSearcher(reader);

            Query query = new TermQuery(new Term(PRIORITY_FIELD, HIGH_PRIORITY));
            @out.WriteLine("Query: " + query.ToString(PRIORITY_FIELD));
            if (VERBOSE)
            {
                Console.WriteLine("TEST: search query=" + query);
            }

            Sort sort = new Sort(SortField.FIELD_SCORE, new SortField(ID_FIELD, SortField.Type_e.INT));

            ScoreDoc[] hits = searcher.Search(query, null, MAX_DOCS, sort).ScoreDocs;
            PrintHits(@out, hits, searcher);
            CheckHits(hits, MAX_DOCS, searcher);

            // try a new search with OR
            searcher = NewSearcher(reader);
            hits = null;

            BooleanQuery booleanQuery = new BooleanQuery();
            booleanQuery.Add(new TermQuery(new Term(PRIORITY_FIELD, HIGH_PRIORITY)), BooleanClause.Occur.SHOULD);
            booleanQuery.Add(new TermQuery(new Term(PRIORITY_FIELD, MED_PRIORITY)), BooleanClause.Occur.SHOULD);
            @out.WriteLine("Query: " + booleanQuery.ToString(PRIORITY_FIELD));

            hits = searcher.Search(booleanQuery, null, MAX_DOCS, sort).ScoreDocs;
            PrintHits(@out, hits, searcher);
            CheckHits(hits, MAX_DOCS, searcher);

            reader.Dispose();
            directory.Dispose();
        }