Examples of StandardQueryParser

The syntax for query strings is as follows (copied from the old QueryParser javadoc):

The text parser used by this helper is a {@link StandardSyntaxParser}.

The query node processor used by this helper is a {@link StandardQueryNodeProcessorPipeline}.

The builder used by this helper is a {@link StandardQueryTreeBuilder}.

@see StandardQueryParser @see StandardQueryConfigHandler @see StandardSyntaxParser @see StandardQueryNodeProcessorPipeline @see StandardQueryTreeBuilder

  • org.apache.lucene.queryparser.flexible.standard.StandardQueryParser
    query config handler returned by {@link StandardQueryParser} is a{@link StandardQueryConfigHandler}
    queryParserHelper.getQueryConfigHandler().setAnalyzer(new WhitespaceAnalyzer());

    The syntax for query strings is as follows (copied from the old QueryParser javadoc):

    The text parser used by this helper is a {@link StandardSyntaxParser}.

    The query node processor used by this helper is a {@link StandardQueryNodeProcessorPipeline}.

    The builder used by this helper is a {@link StandardQueryTreeBuilder}.

    @see StandardQueryParser @see StandardQueryConfigHandler @see StandardSyntaxParser @see StandardQueryNodeProcessorPipeline @see StandardQueryTreeBuilder


  • Examples of org.apache.lucene.queryParser.standard.StandardQueryParser

        assertQueryEquals("b !(a AND b)", null, "b -(+a +b)");
        assertQueryEquals("(a AND b)^4 OR c", null, "((+a +b)^4.0) c");
      }
     
      public void testParens() throws Exception {
        StandardQueryParser qp = new StandardQueryParser(new MockAnalyzer(random));
        String query = "(field:[1 TO *] AND field:[* TO 2]) AND field2:(z)";
        BooleanQuery q = new BooleanQuery();
        BooleanQuery bq = new BooleanQuery();
        bq.add(new TermRangeQuery("field", "1", "*", true, true), BooleanClause.Occur.MUST);
        bq.add(new TermRangeQuery("field", "*", "2", true, true), BooleanClause.Occur.MUST);
        q.add(bq, BooleanClause.Occur.MUST);
        q.add(new TermQuery(new Term("field2", "z")), BooleanClause.Occur.MUST);
        assertEquals(q, qp.parse(query, "foo"));
      }
    View Full Code Here

    Examples of org.apache.lucene.queryParser.standard.StandardQueryParser

        assertWildcardQueryEquals("*Term", true, "*term", true);
        assertWildcardQueryEquals("?Term", true, "?term", true);
      }

      public void testLeadingWildcardType() throws Exception {
        StandardQueryParser qp = getParser(null);
        qp.setAllowLeadingWildcard(true);
        assertEquals(WildcardQuery.class, qp.parse("t*erm*", "field").getClass());
        assertEquals(WildcardQuery.class, qp.parse("?term*", "field").getClass());
        assertEquals(WildcardQuery.class, qp.parse("*term*", "field").getClass());
      }
    View Full Code Here

    Examples of org.apache.lucene.queryParser.standard.StandardQueryParser

      public void testRange() throws Exception {
        assertQueryEquals("[ a TO z]", null, "[a TO z]");
        assertEquals(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT, ((TermRangeQuery)getQuery("[ a TO z]", null)).getRewriteMethod());

        StandardQueryParser qp = new StandardQueryParser();
       
        qp.setMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
        assertEquals(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE,((TermRangeQuery)qp.parse("[ a TO z]", "field")).getRewriteMethod());

        assertQueryEquals("[ a TO z ]", null, "[a TO z]");
        assertQueryEquals("{ a TO z}", null, "{a TO z}");
        assertQueryEquals("{ a TO z }", null, "{a TO z}");
        assertQueryEquals("{ a TO z }^2.0", null, "{a TO z}^2.0");
    View Full Code Here

    Examples of org.apache.lucene.queryParser.standard.StandardQueryParser

            Field.Index.NOT_ANALYZED));
        iw.addDocument(doc);
        iw.close();
        IndexSearcher is = new IndexSearcher(ramDir, true);

        StandardQueryParser qp = new StandardQueryParser();
        qp.setAnalyzer(new WhitespaceAnalyzer(TEST_VERSION_CURRENT));

        // Neither Java 1.4.2 nor 1.5.0 has Farsi Locale collation available in
        // RuleBasedCollator. However, the Arabic Locale seems to order the
        // Farsi
        // characters properly.
        Collator c = Collator.getInstance(new Locale("ar"));
        qp.setRangeCollator(c);

        // Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi
        // orders the U+0698 character before the U+0633 character, so the
        // single
        // index Term below should NOT be returned by a ConstantScoreRangeQuery
        // with a Farsi Collator (or an Arabic one for the case when Farsi is
        // not
        // supported).

        // Test ConstantScoreRangeQuery
        qp.setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
        ScoreDoc[] result = is.search(qp.parse("[ \u062F TO \u0698 ]", "content"),
            null, 1000).scoreDocs;
        assertEquals("The index Term should not be included.", 0, result.length);

        result = is.search(qp.parse("[ \u0633 TO \u0638 ]", "content"), null, 1000).scoreDocs;
        assertEquals("The index Term should be included.", 1, result.length);

        // Test RangeQuery
        qp.setMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
        result = is.search(qp.parse("[ \u062F TO \u0698 ]", "content"), null, 1000).scoreDocs;
        assertEquals("The index Term should not be included.", 0, result.length);

        result = is.search(qp.parse("[ \u0633 TO \u0638 ]", "content"), null, 1000).scoreDocs;
        assertEquals("The index Term should be included.", 1, result.length);

        is.close();
        ramDir.close();
      }
    View Full Code Here

    Examples of org.apache.lucene.queryParser.standard.StandardQueryParser

        endDateExpected.set(2002, 1, 4, 23, 59, 59);
        endDateExpected.set(Calendar.MILLISECOND, 999);
        final String defaultField = "default";
        final String monthField = "month";
        final String hourField = "hour";
        StandardQueryParser qp = new StandardQueryParser();

        // Don't set any date resolution and verify if DateField is used
        assertDateRangeQueryEquals(qp, defaultField, startDate, endDate,
            endDateExpected.getTime(), null);

        Map<CharSequence, DateTools.Resolution> dateRes =  new HashMap<CharSequence, DateTools.Resolution>();
       
        // set a field specific date resolution   
        dateRes.put(monthField, DateTools.Resolution.MONTH);
        qp.setDateResolution(dateRes);

        // DateField should still be used for defaultField
        assertDateRangeQueryEquals(qp, defaultField, startDate, endDate,
            endDateExpected.getTime(), null);

        // set default date resolution to MILLISECOND
        qp.setDateResolution(DateTools.Resolution.MILLISECOND);

        // set second field specific date resolution
        dateRes.put(hourField, DateTools.Resolution.HOUR);
        qp.setDateResolution(dateRes);

        // for this field no field specific date resolution has been set,
        // so verify if the default resolution is used
        assertDateRangeQueryEquals(qp, defaultField, startDate, endDate,
            endDateExpected.getTime(), DateTools.Resolution.MILLISECOND);
    View Full Code Here

    Examples of org.apache.lucene.queryParser.standard.StandardQueryParser

        assertQueryEqualsDOA("-term term term", null, "-term +term +term");
      }

      public void testBoost() throws Exception {
        StandardAnalyzer oneStopAnalyzer = new StandardAnalyzer(TEST_VERSION_CURRENT, Collections.singleton("on"));
        StandardQueryParser qp = new StandardQueryParser();
        qp.setAnalyzer(oneStopAnalyzer);

        Query q = qp.parse("on^1.0", "field");
        assertNotNull(q);
        q = qp.parse("\"hello\"^2.0", "field");
        assertNotNull(q);
        assertEquals(q.getBoost(), (float) 2.0, (float) 0.5);
        q = qp.parse("hello^2.0", "field");
        assertNotNull(q);
        assertEquals(q.getBoost(), (float) 2.0, (float) 0.5);
        q = qp.parse("\"on\"^1.0", "field");
        assertNotNull(q);

        StandardQueryParser qp2 = new StandardQueryParser();
        qp2.setAnalyzer(new StandardAnalyzer(TEST_VERSION_CURRENT));

        q = qp2.parse("the^3", "field");
        // "the" is a stop word so the result is an empty query:
        assertNotNull(q);
        assertEquals("", q.toString());
        assertEquals(1.0f, q.getBoost(), 0.01f);
      }
    View Full Code Here

    Examples of org.apache.lucene.queryParser.standard.StandardQueryParser

      }

      public void testBooleanQuery() throws Exception {
        BooleanQuery.setMaxClauseCount(2);
        try {
          StandardQueryParser qp = new StandardQueryParser();
          qp.setAnalyzer(new MockAnalyzer(random, MockTokenizer.WHITESPACE, false));
          qp.parse("one two three", "field");
          fail("ParseException expected due to too many boolean clauses");
        } catch (QueryNodeException expected) {
          // too many boolean clauses, so ParseException is expected
        }
      }
    View Full Code Here

    Examples of org.apache.lucene.queryParser.standard.StandardQueryParser

      /**
       * This test differs from TestPrecedenceQueryParser
       */
      public void testPrecedence() throws Exception {
        StandardQueryParser qp = new StandardQueryParser();
        qp.setAnalyzer(new MockAnalyzer(random, MockTokenizer.WHITESPACE, false));

        Query query1 = qp.parse("A AND B OR C AND D", "field");
        Query query2 = qp.parse("+A +B +C +D", "field");

        assertEquals(query1, query2);
      }
    View Full Code Here

    Examples of org.apache.lucene.queryParser.standard.StandardQueryParser

        // assertEquals(1,type[0]);

      }

      public void testStopwords() throws Exception {
        StandardQueryParser qp = new StandardQueryParser();
        qp.setAnalyzer(
            new StopAnalyzer(TEST_VERSION_CURRENT, StopFilter.makeStopSet(TEST_VERSION_CURRENT, "the", "foo" )));

        Query result = qp.parse("a:the OR a:foo", "a");
        assertNotNull("result is null and it shouldn't be", result);
        assertTrue("result is not a BooleanQuery", result instanceof BooleanQuery);
        assertTrue(((BooleanQuery) result).clauses().size() + " does not equal: "
            + 0, ((BooleanQuery) result).clauses().size() == 0);
        result = qp.parse("a:woo OR a:the", "a");
        assertNotNull("result is null and it shouldn't be", result);
        assertTrue("result is not a TermQuery", result instanceof TermQuery);
        result = qp.parse(
            "(fieldX:xxxxx OR fieldy:xxxxxxxx)^2 AND (fieldx:the OR fieldy:foo)",
            "a");
        assertNotNull("result is null and it shouldn't be", result);
        assertTrue("result is not a BooleanQuery", result instanceof BooleanQuery);
        if (VERBOSE)
    View Full Code Here

    Examples of org.apache.lucene.queryParser.standard.StandardQueryParser

        assertTrue(((BooleanQuery) result).clauses().size() + " does not equal: "
            + 2, ((BooleanQuery) result).clauses().size() == 2);
      }

      public void testPositionIncrement() throws Exception {
        StandardQueryParser qp = new StandardQueryParser();
        qp.setAnalyzer(
            new StopAnalyzer(TEST_VERSION_CURRENT, StopFilter.makeStopSet(TEST_VERSION_CURRENT, "the", "in", "are", "this" )));

        qp.setEnablePositionIncrements(true);

        String qtxt = "\"the words in poisitions pos02578 are stopped in this phrasequery\"";
        // 0 2 5 7 8
        int expectedPositions[] = { 1, 3, 4, 6, 9 };
        PhraseQuery pq = (PhraseQuery) qp.parse(qtxt, "a");
        // System.out.println("Query text: "+qtxt);
        // System.out.println("Result: "+pq);
        Term t[] = pq.getTerms();
        int pos[] = pq.getPositions();
        for (int i = 0; i < t.length; i++) {
    View Full Code Here
    TOP
    Copyright © 2018 www.massapi.com. All rights reserved.
    All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.