Ejemplo n.º 1
0
 public void TestBasicQueryParser()
 {
     var query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "description", new SimpleAnalyzer())
         .Parse("partnum:Q36 AND SPACE");
     Assert.AreEqual("+partnum:q +description:space", query.ToString(), "note Q36 -> q");
     Assert.AreEqual(0, searcher.Search(query, 10).ScoreDocs.Length, "doc not found :(");
 }
Ejemplo n.º 2
0
 public void TestPerFieldAnalyzer()
 {
     var analyzer = new PerFieldAnalyzerWrapper(new SimpleAnalyzer());
     analyzer.AddAnalyzer("partnum", new KeywordAnalyzer());
     var query =
         new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "description", analyzer)
             .Parse("partnum:Q36 AND SPACE");
     Assert.AreEqual("+partnum:Q36 +space", query.ToString("description"), "Q36 kept as-is");
     Assert.AreEqual(1, searcher.Search(query, searcher.MaxDoc()).ScoreDocs.Length, "docs found!!!");
 }
Ejemplo n.º 3
0
        public void TestWithQueryParser()
        {
            var query =
                new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "contents", synonymAnalyzer).Parse("\"fox jumps\"");
            Assert.AreEqual(1, indexSearcher.Search(query, 10).TotalHits);
            Console.WriteLine("With SynonymAnalyzer, \"fox jumps\" parses to {0}", query.ToString("content"));

            query =
                new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "contents",
                                new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("\"fox jumps\"");

            Assert.AreEqual(1, indexSearcher.Search(query, 10).TotalHits);
            Console.WriteLine("With StandardAnalyzer, \"fox jumps\" parses to {0}", query.ToString("content"));
        }