// verify parsing of query using a stopping analyzer private void AssertStopQueryEquals(string qtxt, string expectedRes) { string[] fields = new string[]{"b", "t"}; Occur[] occur = new Occur[]{Occur.SHOULD, Occur.SHOULD}; TestQueryParser.QPTestAnalyzer a = new TestQueryParser.QPTestAnalyzer(); MultiFieldQueryParser mfqp = new MultiFieldQueryParser(Util.Version.LUCENE_CURRENT, fields, a); Query q = mfqp.Parse(qtxt); Assert.AreEqual(expectedRes, q.ToString()); q = MultiFieldQueryParser.Parse(Util.Version.LUCENE_CURRENT, qtxt, fields, occur, a); Assert.AreEqual(expectedRes, q.ToString()); }
// verify parsing of query using a stopping analyzer private void AssertStopQueryEquals(System.String qtxt, System.String expectedRes) { System.String[] fields = new System.String[]{"b", "t"}; Occur[] occur = new Occur[]{Occur.SHOULD, Occur.SHOULD}; TestQueryParser.QPTestAnalyzer a = new TestQueryParser.QPTestAnalyzer(); MultiFieldQueryParser mfqp = new MultiFieldQueryParser(fields, a); Query q = mfqp.Parse(qtxt); Assert.AreEqual(expectedRes, q.ToString()); q = MultiFieldQueryParser.Parse(qtxt, fields, occur, a); Assert.AreEqual(expectedRes, q.ToString()); }
public virtual void TestStaticMethod1() { var fields = new []{"b", "t"}; var queries = new [] { "one", "two" }; Query q = MultiFieldQueryParser.Parse(Util.Version.LUCENE_CURRENT, queries, fields, new StandardAnalyzer(Util.Version.LUCENE_CURRENT)); Assert.AreEqual("b:one t:two", q.ToString()); var queries2 = new [] { "+one", "+two" }; q = MultiFieldQueryParser.Parse(Util.Version.LUCENE_CURRENT, queries2, fields, new StandardAnalyzer(Util.Version.LUCENE_CURRENT)); Assert.AreEqual("(+b:one) (+t:two)", q.ToString()); var queries3 = new [] { "one", "+two" }; q = MultiFieldQueryParser.Parse(Util.Version.LUCENE_CURRENT, queries3, fields, new StandardAnalyzer(Util.Version.LUCENE_CURRENT)); Assert.AreEqual("b:one (+t:two)", q.ToString()); var queries4 = new [] { "one +more", "+two" }; q = MultiFieldQueryParser.Parse(Util.Version.LUCENE_CURRENT, queries4, fields, new StandardAnalyzer(Util.Version.LUCENE_CURRENT)); Assert.AreEqual("(b:one +b:more) (+t:two)", q.ToString()); var queries5 = new [] { "blah" }; Assert.Throws<ArgumentException>(() => MultiFieldQueryParser.Parse(Util.Version.LUCENE_CURRENT, queries5, fields, new StandardAnalyzer(Util.Version.LUCENE_CURRENT))); // check also with stop words for this static form (qtxts[], fields[]). var stopA = new TestQueryParser.QPTestAnalyzer(); var queries6 = new [] { "((+stop))", "+((stop))" }; q = MultiFieldQueryParser.Parse(Util.Version.LUCENE_CURRENT, queries6, fields, stopA); Assert.AreEqual("", q.ToString()); var queries7 = new [] { "one ((+stop)) +more", "+((stop)) +two" }; q = MultiFieldQueryParser.Parse(Util.Version.LUCENE_CURRENT, queries7, fields, stopA); Assert.AreEqual("(b:one +b:more) (+t:two)", q.ToString()); }
public virtual void TestStaticMethod1() { System.String[] fields = new System.String[]{"b", "t"}; System.String[] queries = new System.String[]{"one", "two"}; Query q = MultiFieldQueryParser.Parse(queries, fields, new StandardAnalyzer()); Assert.AreEqual("b:one t:two", q.ToString()); System.String[] queries2 = new System.String[]{"+one", "+two"}; q = MultiFieldQueryParser.Parse(queries2, fields, new StandardAnalyzer()); Assert.AreEqual("(+b:one) (+t:two)", q.ToString()); System.String[] queries3 = new System.String[]{"one", "+two"}; q = MultiFieldQueryParser.Parse(queries3, fields, new StandardAnalyzer()); Assert.AreEqual("b:one (+t:two)", q.ToString()); System.String[] queries4 = new System.String[]{"one +more", "+two"}; q = MultiFieldQueryParser.Parse(queries4, fields, new StandardAnalyzer()); Assert.AreEqual("(b:one +b:more) (+t:two)", q.ToString()); System.String[] queries5 = new System.String[]{"blah"}; try { q = MultiFieldQueryParser.Parse(queries5, fields, new StandardAnalyzer()); Assert.Fail(); } catch (System.ArgumentException e) { // expected exception, array length differs } // check also with stop words for this static form (qtxts[], fields[]). TestQueryParser.QPTestAnalyzer stopA = new TestQueryParser.QPTestAnalyzer(); System.String[] queries6 = new System.String[]{"((+stop))", "+((stop))"}; q = MultiFieldQueryParser.Parse(queries6, fields, stopA); Assert.AreEqual("", q.ToString()); System.String[] queries7 = new System.String[]{"one ((+stop)) +more", "+((stop)) +two"}; q = MultiFieldQueryParser.Parse(queries7, fields, stopA); Assert.AreEqual("(b:one +b:more) (+t:two)", q.ToString()); }