public SearchService( Func <INoSqlSession> noSqlSessionFactory, ILogger logger) { this.noSqlSessionFactory = noSqlSessionFactory; this.logger = logger; analyzer = new LithuanianAnalyzer(); parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", analyzer); parser.SetMultiTermRewriteMethod(Lucene.Net.Search.MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE); }
public virtual void TestFarsiRangeCollating() { RAMDirectory ramDir = new RAMDirectory(); IndexWriter iw = new IndexWriter(ramDir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED); Document doc = new Document(); doc.Add(new Field("content", "\u0633\u0627\u0628", Field.Store.YES, Field.Index.UN_TOKENIZED)); iw.AddDocument(doc); iw.Close(); IndexSearcher is_Renamed = new IndexSearcher(ramDir); QueryParser qp = new QueryParser("content", new WhitespaceAnalyzer()); // Neither Java 1.4.2 nor 1.5.0 has Farsi Locale collation available in // RuleBasedCollator. However, the Arabic Locale seems to order the Farsi // characters properly. System.Globalization.CompareInfo c = new System.Globalization.CultureInfo("ar").CompareInfo; qp.SetRangeCollator(c); // Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi // orders the U+0698 character before the U+0633 character, so the single // index Term below should NOT be returned by a ConstantScoreRangeQuery // with a Farsi Collator (or an Arabic one for the case when Farsi is not // supported). // Test ConstantScoreRangeQuery qp.SetMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE); ScoreDoc[] result = is_Renamed.Search(qp.Parse("[ \u062F TO \u0698 ]"), null, 1000).ScoreDocs; Assert.AreEqual(0, result.Length, "The index Term should not be included."); result = is_Renamed.Search(qp.Parse("[ \u0633 TO \u0638 ]"), null, 1000).ScoreDocs; Assert.AreEqual(1, result.Length, "The index Term should be included."); // Test TermRangeQuery qp.SetMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE); result = is_Renamed.Search(qp.Parse("[ \u062F TO \u0698 ]"), null, 1000).ScoreDocs; Assert.AreEqual(0, result.Length, "The index Term should not be included."); result = is_Renamed.Search(qp.Parse("[ \u0633 TO \u0638 ]"), null, 1000).ScoreDocs; Assert.AreEqual(1, result.Length, "The index Term should be included."); is_Renamed.Close(); }
public virtual void TestRange() { AssertQueryEquals("[ a TO z]", null, "[a TO z]"); Assert.AreEqual(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT, ((TermRangeQuery) GetQuery("[ a TO z]", null)).GetRewriteMethod()); QueryParser qp = new QueryParser("field", new SimpleAnalyzer()); qp.SetMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE); Assert.AreEqual(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE, ((TermRangeQuery) qp.Parse("[ a TO z]")).GetRewriteMethod()); AssertQueryEquals("[ a TO z ]", null, "[a TO z]"); AssertQueryEquals("{ a TO z}", null, "{a TO z}"); AssertQueryEquals("{ a TO z }", null, "{a TO z}"); AssertQueryEquals("{ a TO z }^2.0", null, "{a TO z}^2.0"); AssertQueryEquals("[ a TO z] OR bar", null, "[a TO z] bar"); AssertQueryEquals("[ a TO z] AND bar", null, "+[a TO z] +bar"); AssertQueryEquals("( bar blar { a TO z}) ", null, "bar blar {a TO z}"); AssertQueryEquals("gack ( bar blar { a TO z}) ", null, "gack (bar blar {a TO z})"); }