Inheritance: Lucene.Net.Analysis.Analyzer
Exemplo n.º 1
0
        // 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());
        }
Exemplo n.º 2
0
        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());

        }