Package org.apache.lucene.queryparser.flexible.standard

Examples of org.apache.lucene.queryparser.flexible.standard.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


        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


        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

    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

     * @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

        }
        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

        }
        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

                            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

Related Classes of org.apache.lucene.queryparser.flexible.standard.StandardQueryParser

Copyright © 2018 www.massapicom. 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.