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

              expectedPositions[i], pos[i]);
        }
      }

      public void testMatchAllDocs() throws Exception {
        StandardQueryParser qp = new StandardQueryParser();
        qp.setAnalyzer(new MockAnalyzer(random, MockTokenizer.WHITESPACE, false));

        assertEquals(new MatchAllDocsQuery(), qp.parse("*:*", "field"));
        assertEquals(new MatchAllDocsQuery(), qp.parse("(*:*)", "field"));
        BooleanQuery bq = (BooleanQuery) qp.parse("+*:* -*:*", "field");
        assertTrue(bq.getClauses()[0].getQuery() instanceof MatchAllDocsQuery);
        assertTrue(bq.getClauses()[1].getQuery() instanceof MatchAllDocsQuery);
      }
    View Full Code Here

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

        assertTrue(bq.getClauses()[1].getQuery() instanceof MatchAllDocsQuery);
      }

      private void assertHits(int expected, String query, IndexSearcher is)
          throws IOException, QueryNodeException {
        StandardQueryParser qp = new StandardQueryParser();
        qp.setAnalyzer(new MockAnalyzer(random, MockTokenizer.WHITESPACE, false));
        qp.setLocale(Locale.ENGLISH);

        Query q = qp.parse(query, "date");
        ScoreDoc[] hits = is.search(q, null, 1000).scoreDocs;
        assertEquals(expected, hits.length);
      }
    View Full Code Here

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

        doc.add(newField("field", "", Field.Store.NO, Field.Index.ANALYZED));
        w.addDocument(doc);
        IndexReader r = IndexReader.open(w, true);
        IndexSearcher s = newSearcher(r);
       
        Query q = new StandardQueryParser(new CannedAnalyzer()).parse("\"a\"", "field");
        assertTrue(q instanceof MultiPhraseQuery);
        assertEquals(1, s.search(q, 10).totalHits);
        s.close();
        r.close();
        w.close();
    View Full Code Here

    Examples of org.apache.lucene.queryparser.flexible.standard.StandardQueryParser

            writer.addDocument(doc);

            searcher = new IndexSearcher(DirectoryReader.open(writer, false));

            Query query = new StandardQueryParser(skosAnalyzer).parse("\"fox jumps\"", "content");

            Assert.assertEquals(1, TestUtil.hitCount(searcher, query));

            Assert.assertEquals("content:\"fox (jumps hops leaps)\"", query.toString());
            Assert.assertEquals("org.apache.lucene.search.MultiPhraseQuery", query
                    .getClass().getName());

            query = new StandardQueryParser(new StandardAnalyzer(SKOSAnalysisPlugin.getLuceneVersion())).parse("\"fox jumps\"", "content");
            Assert.assertEquals(1, TestUtil.hitCount(searcher, query));

            Assert.assertEquals("content:\"fox jumps\"", query.toString());
            Assert.assertEquals("org.apache.lucene.search.PhraseQuery", query
                    .getClass().getName());
    View Full Code Here

    Examples of org.apache.lucene.queryparser.flexible.standard.StandardQueryParser

            writer.addDocument(doc);

            searcher = new IndexSearcher(DirectoryReader.open(writer, false));

            StandardQueryParser parser = new StandardQueryParser(new SimpleAnalyzer(SKOSAnalysisPlugin.getLuceneVersion()));

            Query query = parser.parse("united nations", "content");

            Assert.assertEquals(1, TestUtil.hitCount(searcher, query));

        }
    View Full Code Here

    Examples of org.apache.lucene.queryparser.flexible.standard.StandardQueryParser

        private StandardQueryParser parser = null;

        public StandardQueryParserWrapper(String field, Analyzer analyzer) {
            super(field, analyzer);
            this.field = field;
            this.parser = new StandardQueryParser(analyzer);
        }
    View Full Code Here

    Examples of org.apache.lucene.queryparser.flexible.standard.StandardQueryParser

         * @throws ParseException
         * @throws QueryNodeException
         */
        public static Query getCswServiceSpecificConstraintQuery(String cswServiceSpecificConstraint, LuceneConfig _luceneConfig) throws ParseException, QueryNodeException {
    //        MultiFieldQueryParser parser = new MultiFieldQueryParser(Geonet.LUCENE_VERSION, fields , SearchManager.getAnalyzer());
            StandardQueryParser parser = new StandardQueryParser(SearchManager.getAnalyzer());
            Map<String, NumericConfig> numericMap = new HashMap<String, NumericConfig>();
            for (LuceneConfigNumericField field : _luceneConfig.getNumericFields().values()) {
                String name = field.getName();
                int precisionStep = field.getPrecisionStep();
                NumberFormat format = NumberFormat.getNumberInstance();
                NumericType type = NumericType.valueOf(field.getType().toUpperCase());
                NumericConfig config = new NumericConfig(precisionStep, format, type);
                numericMap.put(name, config);
            }
            parser.setNumericConfigMap(numericMap);
            Query q = parser.parse(cswServiceSpecificConstraint, "title");

            // List of lucene fields which MUST not be control by user, to be removed from the CSW service specific constraint
            List<String> SECURITY_FIELDS = Arrays.asList(
                 LuceneIndexField.OWNER,
                 LuceneIndexField.GROUP_OWNER);
    View Full Code Here

    Examples of org.apache.lucene.queryparser.flexible.standard.StandardQueryParser

            }
            if (search.trim().length() == 0) {
                log.trace("No search parameters: " + search);
                search = "*"; // return everything
            }
            StandardQueryParser parser = new StandardQueryParser();
            parser.setDefaultOperator(StandardQueryConfigHandler.Operator.AND);
            try {
                return parser.parse(search, "text");
            } catch (ParseException se) {
                log.error("Could not parse query: " + search);
                throw se;
            }
        }
    View Full Code Here

    Examples of org.apache.lucene.queryparser.flexible.standard.StandardQueryParser

            }
            return analyzer;
        }

        public StandardQueryParser getParser() {
            StandardQueryParser parser;
            synchronized (shared) {
                parser = shared.getParser();
                if (parser == null) {
                    parser = new StandardQueryParser(getAnalyzer());
                }
                shared.setParser(parser);
            }
            return parser;
        }
    View Full Code Here

    Examples of org.apache.lucene.queryparser.flexible.standard.StandardQueryParser

                                String defaultField, String query) {
            FullTextIndexInfo index = getIndex(context.getSession(), name, null);
            if (defaultField == null) {
                defaultField = index.getDefaultFieldName();
            }
            StandardQueryParser parser = index.getParser();
            try {
                synchronized (parser) {
                    return parser.parse(query, defaultField);
                }
            }
            catch (QueryNodeException ex) {
                throw new FullTextQueryParseException(ex);
            }
    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.