示例#1
0
 public virtual void TestCJKSynonym()
 {
     BooleanQuery expected = new BooleanQuery(true);
     expected.Add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);
     expected.Add(new TermQuery(new Term("field", "國")), BooleanClause.Occur.SHOULD);
     QueryBuilder builder = new QueryBuilder(new MockCJKSynonymAnalyzer());
     Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "国"));
     Assert.AreEqual(expected, builder.CreatePhraseQuery("field", "国"));
     Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "国", BooleanClause.Occur.MUST));
 }
示例#2
0
        public virtual void TestSynonyms()
        {
            BooleanQuery expected = new BooleanQuery(true);

            expected.Add(new TermQuery(new Term("field", "dogs")), Occur.SHOULD);
            expected.Add(new TermQuery(new Term("field", "dog")), Occur.SHOULD);
            QueryBuilder builder = new QueryBuilder(new MockSynonymAnalyzer());

            Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "dogs"));
            Assert.AreEqual(expected, builder.CreatePhraseQuery("field", "dogs"));
            Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "dogs", Occur.MUST));
            Assert.AreEqual(expected, builder.CreatePhraseQuery("field", "dogs"));
        }
示例#3
0
        public virtual void TestTerm()
        {
            TermQuery    expected = new TermQuery(new Term("field", "test"));
            QueryBuilder builder  = new QueryBuilder(new MockAnalyzer(Random));

            Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "test"));
        }
示例#4
0
 public virtual void TestBooleanMust()
 {
     BooleanQuery expected = new BooleanQuery();
     expected.Add(new TermQuery(new Term("field", "foo")), BooleanClause.Occur.MUST);
     expected.Add(new TermQuery(new Term("field", "bar")), BooleanClause.Occur.MUST);
     QueryBuilder builder = new QueryBuilder(new MockAnalyzer(Random()));
     Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "foo bar", BooleanClause.Occur.MUST));
 }
示例#5
0
 public virtual void TestBooleanMust()
 {
     BooleanQuery expected = new BooleanQuery();
     expected.Add(new TermQuery(new Term("field", "foo")), BooleanClause.Occur.MUST);
     expected.Add(new TermQuery(new Term("field", "bar")), BooleanClause.Occur.MUST);
     QueryBuilder builder = new QueryBuilder(new MockAnalyzer(Random()));
     Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "foo bar", BooleanClause.Occur.MUST));
 }
示例#6
0
        public virtual void TestBoolean()
        {
            BooleanQuery expected = new BooleanQuery();

            expected.Add(new TermQuery(new Term("field", "foo")), Occur.SHOULD);
            expected.Add(new TermQuery(new Term("field", "bar")), Occur.SHOULD);
            QueryBuilder builder = new QueryBuilder(new MockAnalyzer(Random));

            Assert.IsTrue(expected.Equals(builder.CreateBooleanQuery("field", "foo bar")));
            //Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "foo bar"));
        }
示例#7
0
        public virtual void TestCJKTerm()
        {
            // individual CJK chars as terms
            SimpleCJKAnalyzer analyzer = new SimpleCJKAnalyzer(this);

            BooleanQuery expected = new BooleanQuery();
            expected.Add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.SHOULD);
            expected.Add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);

            QueryBuilder builder = new QueryBuilder(analyzer);
            Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "中国"));
        }
示例#8
0
        public virtual void TestCJKSynonymsAND()
        {
            BooleanQuery expected = new BooleanQuery();

            expected.Add(new TermQuery(new Term("field", "中")), Occur.MUST);
            BooleanQuery inner = new BooleanQuery(true);

            inner.Add(new TermQuery(new Term("field", "国")), Occur.SHOULD);
            inner.Add(new TermQuery(new Term("field", "國")), Occur.SHOULD);
            expected.Add(inner, Occur.MUST);
            QueryBuilder builder = new QueryBuilder(new MockCJKSynonymAnalyzer());

            Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "中国", Occur.MUST));
        }
示例#9
0
        public virtual void TestEmpty()
        {
            QueryBuilder builder = new QueryBuilder(new MockAnalyzer(Random));

            Assert.IsNull(builder.CreateBooleanQuery("field", ""));
        }
示例#10
0
 public virtual void TestTerm()
 {
     TermQuery expected = new TermQuery(new Term("field", "test"));
     QueryBuilder builder = new QueryBuilder(new MockAnalyzer(Random()));
     Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "test"));
 }
示例#11
0
 public virtual void TestMinShouldMatchNone()
 {
     QueryBuilder builder = new QueryBuilder(new MockAnalyzer(Random()));
     Assert.AreEqual(builder.CreateBooleanQuery("field", "one two three four"), builder.CreateMinShouldMatchQuery("field", "one two three four", 0f));
 }
示例#12
0
 public virtual void TestMinShouldMatchAll()
 {
     QueryBuilder builder = new QueryBuilder(new MockAnalyzer(Random()));
     Assert.AreEqual(builder.CreateBooleanQuery("field", "one two three four", BooleanClause.Occur.MUST), builder.CreateMinShouldMatchQuery("field", "one two three four", 1f));
 }
示例#13
0
 public virtual void TestEmpty()
 {
     QueryBuilder builder = new QueryBuilder(new MockAnalyzer(Random()));
     Assert.IsNull(builder.CreateBooleanQuery("field", ""));
 }
示例#14
0
        public virtual void TestCJKTerm()
        {
            // individual CJK chars as terms
            SimpleCJKAnalyzer analyzer = new SimpleCJKAnalyzer(this);

            BooleanQuery expected = new BooleanQuery();
            expected.Add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.SHOULD);
            expected.Add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);

            QueryBuilder builder = new QueryBuilder(analyzer);
            Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "中国"));
        }
示例#15
0
 public virtual void TestCJKSynonymsOR2()
 {
     BooleanQuery expected = new BooleanQuery();
     expected.Add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.SHOULD);
     BooleanQuery inner = new BooleanQuery(true);
     inner.Add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);
     inner.Add(new TermQuery(new Term("field", "國")), BooleanClause.Occur.SHOULD);
     expected.Add(inner, BooleanClause.Occur.SHOULD);
     BooleanQuery inner2 = new BooleanQuery(true);
     inner2.Add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);
     inner2.Add(new TermQuery(new Term("field", "國")), BooleanClause.Occur.SHOULD);
     expected.Add(inner2, BooleanClause.Occur.SHOULD);
     QueryBuilder builder = new QueryBuilder(new MockCJKSynonymAnalyzer());
     Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "中国国"));
 }
示例#16
0
        public virtual void TestMinShouldMatchAll()
        {
            QueryBuilder builder = new QueryBuilder(new MockAnalyzer(Random));

            Assert.AreEqual(builder.CreateBooleanQuery("field", "one two three four", Occur.MUST), builder.CreateMinShouldMatchQuery("field", "one two three four", 1f));
        }
示例#17
0
 public virtual void TestSynonyms()
 {
     BooleanQuery expected = new BooleanQuery(true);
     expected.Add(new TermQuery(new Term("field", "dogs")), BooleanClause.Occur.SHOULD);
     expected.Add(new TermQuery(new Term("field", "dog")), BooleanClause.Occur.SHOULD);
     QueryBuilder builder = new QueryBuilder(new MockSynonymAnalyzer());
     Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "dogs"));
     Assert.AreEqual(expected, builder.CreatePhraseQuery("field", "dogs"));
     Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "dogs", BooleanClause.Occur.MUST));
     Assert.AreEqual(expected, builder.CreatePhraseQuery("field", "dogs"));
 }