public void TestStaticMethod2Old() { String[] fields = { "b", "t" }; Occur[] flags = { Occur.MUST, Occur.MUST_NOT }; StandardQueryParser parser = new StandardQueryParser(); parser.SetMultiFields(fields); parser.Analyzer = (new MockAnalyzer(Random)); Query q = QueryParserUtil.Parse("one", fields, flags, new MockAnalyzer(Random));// , fields, flags, new // MockAnalyzer()); assertEquals("+b:one -t:one", q.toString()); q = QueryParserUtil.Parse("one two", fields, flags, new MockAnalyzer(Random)); assertEquals("+(b:one b:two) -(t:one t:two)", q.toString()); try { Occur[] flags2 = { Occur.MUST }; q = QueryParserUtil.Parse("blah", fields, flags2, new MockAnalyzer(Random)); fail(); } catch (Exception e) when(e.IsIllegalArgumentException()) { // expected exception, array length differs } }
public void TestStaticMethod3Old() { String[] queries = { "one", "two" }; String[] fields = { "b", "t" }; Occur[] flags = { Occur.MUST, Occur.MUST_NOT }; Query q = QueryParserUtil.Parse(queries, fields, flags, new MockAnalyzer(Random)); assertEquals("+b:one -t:two", q.toString()); try { Occur[] flags2 = { Occur.MUST }; q = QueryParserUtil .Parse(queries, fields, flags2, new MockAnalyzer(Random)); fail(); } catch (Exception e) when(e.IsIllegalArgumentException()) { // expected exception, array length differs } }
public void TestStaticMethod3Old() { String[] queries = { "one", "two" }; String[] fields = { "b", "t" }; Occur[] flags = { Occur.MUST, Occur.MUST_NOT }; Query q = QueryParserUtil.Parse(queries, fields, flags, new MockAnalyzer(Random())); assertEquals("+b:one -t:two", q.toString()); try { Occur[] flags2 = { Occur.MUST }; q = QueryParserUtil .Parse(queries, fields, flags2, new MockAnalyzer(Random())); fail(); } #pragma warning disable 168 catch (ArgumentException e) #pragma warning restore 168 { // expected exception, array length differs } }
public void TestStaticMethod3() { String[] queries = { "one", "two", "three" }; String[] fields = { "f1", "f2", "f3" }; BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST, BooleanClause.Occur.MUST_NOT, BooleanClause.Occur.SHOULD }; Query q = QueryParserUtil.Parse(queries, fields, flags, new MockAnalyzer(Random())); assertEquals("+f1:one -f2:two f3:three", q.toString()); try { BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST }; q = QueryParserUtil .Parse(queries, fields, flags2, new MockAnalyzer(Random())); fail(); } #pragma warning disable 168 catch (ArgumentException e) #pragma warning restore 168 { // expected exception, array length differs } }
public void TestStaticMethod2() { String[] fields = { "b", "t" }; BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST, BooleanClause.Occur.MUST_NOT }; Query q = QueryParserUtil.Parse("one", fields, flags, new MockAnalyzer(Random())); assertEquals("+b:one -t:one", q.toString()); q = QueryParserUtil.Parse("one two", fields, flags, new MockAnalyzer(Random())); assertEquals("+(b:one b:two) -(t:one t:two)", q.toString()); try { BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST }; q = QueryParserUtil.Parse("blah", fields, flags2, new MockAnalyzer(Random())); fail(); } #pragma warning disable 168 catch (ArgumentException e) #pragma warning restore 168 { // expected exception, array length differs } }
public void TestStaticMethod1() { String[] fields = { "b", "t" }; String[] queries = { "one", "two" }; Query q = QueryParserUtil.Parse(queries, fields, new MockAnalyzer(Random())); assertEquals("b:one t:two", q.toString()); String[] queries2 = { "+one", "+two" }; q = QueryParserUtil.Parse(queries2, fields, new MockAnalyzer(Random())); assertEquals("b:one t:two", q.toString()); String[] queries3 = { "one", "+two" }; q = QueryParserUtil.Parse(queries3, fields, new MockAnalyzer(Random())); assertEquals("b:one t:two", q.toString()); String[] queries4 = { "one +more", "+two" }; q = QueryParserUtil.Parse(queries4, fields, new MockAnalyzer(Random())); assertEquals("(b:one +b:more) t:two", q.toString()); String[] queries5 = { "blah" }; try { q = QueryParserUtil.Parse(queries5, fields, new MockAnalyzer(Random())); fail(); } #pragma warning disable 168 catch (ArgumentException e) #pragma warning restore 168 { // expected exception, array length differs } // check also with stop words for this static form (qtxts[], fields[]). TestQPHelper.QPTestAnalyzer stopA = new TestQPHelper.QPTestAnalyzer(); String[] queries6 = { "((+stop))", "+((stop))" }; q = QueryParserUtil.Parse(queries6, fields, stopA); assertEquals("", q.toString()); String[] queries7 = { "one ((+stop)) +more", "+((stop)) +two" }; q = QueryParserUtil.Parse(queries7, fields, stopA); assertEquals("(b:one +b:more) (+t:two)", q.toString()); }
// verify parsing of query using a stopping analyzer private void assertStopQueryEquals(String qtxt, String expectedRes) { String[] fields = { "b", "t" }; Occur[] occur = { Occur.SHOULD, Occur.SHOULD }; TestQPHelper.QPTestAnalyzer a = new TestQPHelper.QPTestAnalyzer(); StandardQueryParser mfqp = new StandardQueryParser(); mfqp.SetMultiFields(fields); mfqp.Analyzer = (a); Query q = mfqp.Parse(qtxt, null); assertEquals(expectedRes, q.toString()); q = QueryParserUtil.Parse(qtxt, fields, occur, a); assertEquals(expectedRes, q.toString()); }
// verify parsing of query using a stopping analyzer private void assertStopQueryEquals(String qtxt, String expectedRes) { String[] fields = { "b", "t" }; BooleanClause.Occur[] occur = { BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD }; // LUCENENET TODO: Make this Occur.Should instead of BooleanClause.Occur.Should TestQPHelper.QPTestAnalyzer a = new TestQPHelper.QPTestAnalyzer(); StandardQueryParser mfqp = new StandardQueryParser(); mfqp.SetMultiFields(fields); mfqp.Analyzer = (a); Query q = mfqp.Parse(qtxt, null); assertEquals(expectedRes, q.toString()); q = QueryParserUtil.Parse(qtxt, fields, occur, a); assertEquals(expectedRes, q.toString()); }