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)); }
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)); }
public virtual void TestEmpty() { QueryBuilder builder = new QueryBuilder(new MockAnalyzer(Random)); Assert.IsNull(builder.CreateBooleanQuery("field", "")); }
public virtual void TestCJKSloppyPhrase() { // individual CJK chars as terms SimpleCJKAnalyzer analyzer = new SimpleCJKAnalyzer(this); PhraseQuery expected = new PhraseQuery(); expected.Slop = 3; expected.Add(new Term("field", "中")); expected.Add(new Term("field", "国")); QueryBuilder builder = new QueryBuilder(analyzer); Assert.AreEqual(expected, builder.CreatePhraseQuery("field", "中国", 3)); }
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")); }
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")); }
public virtual void TestSynonymsPhrase() { MultiPhraseQuery expected = new MultiPhraseQuery(); expected.Add(new Term("field", "old")); expected.Add(new Term[] { new Term("field", "dogs"), new Term("field", "dog") }); QueryBuilder builder = new QueryBuilder(new MockSynonymAnalyzer()); Assert.AreEqual(expected, builder.CreatePhraseQuery("field", "old dogs")); }
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)); }
public virtual void TestPhraseQueryPositionIncrements() { PhraseQuery expected = new PhraseQuery(); expected.Add(new Term("field", "1")); expected.Add(new Term("field", "2"), 2); CharacterRunAutomaton stopList = new CharacterRunAutomaton((new RegExp("[sS][tT][oO][pP]")).ToAutomaton()); Analyzer analyzer = new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false, stopList); QueryBuilder builder = new QueryBuilder(analyzer); Assert.AreEqual(expected, builder.CreatePhraseQuery("field", "1 stop 2")); }
public virtual void TestMinShouldMatch() { BooleanQuery expected = new BooleanQuery(); expected.Add(new TermQuery(new Term("field", "one")), BooleanClause.Occur.SHOULD); expected.Add(new TermQuery(new Term("field", "two")), BooleanClause.Occur.SHOULD); expected.Add(new TermQuery(new Term("field", "three")), BooleanClause.Occur.SHOULD); expected.Add(new TermQuery(new Term("field", "four")), BooleanClause.Occur.SHOULD); expected.MinimumNumberShouldMatch = 0; QueryBuilder builder = new QueryBuilder(new MockAnalyzer(Random())); Assert.AreEqual(expected, builder.CreateMinShouldMatchQuery("field", "one two three four", 0.1f)); Assert.AreEqual(expected, builder.CreateMinShouldMatchQuery("field", "one two three four", 0.24f)); expected.MinimumNumberShouldMatch = 1; Assert.AreEqual(expected, builder.CreateMinShouldMatchQuery("field", "one two three four", 0.25f)); Assert.AreEqual(expected, builder.CreateMinShouldMatchQuery("field", "one two three four", 0.49f)); expected.MinimumNumberShouldMatch = 2; Assert.AreEqual(expected, builder.CreateMinShouldMatchQuery("field", "one two three four", 0.5f)); Assert.AreEqual(expected, builder.CreateMinShouldMatchQuery("field", "one two three four", 0.74f)); expected.MinimumNumberShouldMatch = 3; Assert.AreEqual(expected, builder.CreateMinShouldMatchQuery("field", "one two three four", 0.75f)); Assert.AreEqual(expected, builder.CreateMinShouldMatchQuery("field", "one two three four", 0.99f)); }
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)); }
public virtual void TestEmpty() { QueryBuilder builder = new QueryBuilder(new MockAnalyzer(Random())); Assert.IsNull(builder.CreateBooleanQuery("field", "")); }
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", "中国")); }
public virtual void TestCJKSynonymsPhrase() { MultiPhraseQuery expected = new MultiPhraseQuery(); expected.Add(new Term("field", "中")); expected.Add(new Term[] { new Term("field", "国"), new Term("field", "國") }); QueryBuilder builder = new QueryBuilder(new MockCJKSynonymAnalyzer()); Assert.AreEqual(expected, builder.CreatePhraseQuery("field", "中国")); expected.Slop = 3; Assert.AreEqual(expected, builder.CreatePhraseQuery("field", "中国", 3)); }
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", "中国国")); }