org.apache.lucene.queryparser.flexible.core.builders.QueryBuilder Java Examples
The following examples show how to use
org.apache.lucene.queryparser.flexible.core.builders.QueryBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LuceneToJexlQueryParser.java From datawave with Apache License 2.0 | 5 votes |
public JexlNode convertToJexlNode(String query) throws ParseException { query = query.replaceAll("\\u0093", "\""); // replace open smart quote 147 query = query.replaceAll("\\u0094", "\""); // replace close smart quote 148 query = query.replaceAll("\\u201c", "\""); // replace open left double quote query = query.replaceAll("\\u201d", "\""); // replace close right double quote JexlNode parsedQuery = null; try { Locale.setDefault(Locale.US); AccumuloSyntaxParser syntaxParser = new AccumuloSyntaxParser(); syntaxParser.enable_tracing(); QueryConfigHandler queryConfigHandler = new QueryConfigHandler(); queryConfigHandler.set(ConfigurationKeys.ANALYZER, analyzer); queryConfigHandler.set(ConfigurationKeys.ENABLE_POSITION_INCREMENTS, positionIncrementsEnabled); queryConfigHandler.set(TOKENIZED_FIELDS, tokenizedFields); queryConfigHandler.set(TOKENIZE_UNFIELDED_QUERIES, tokenizeUnfieldedQueries); queryConfigHandler.set(SKIP_TOKENIZE_UNFIELDED_FIELDS, skipTokenizeUnfieldedFields); queryConfigHandler.set(ALLOWED_FIELDS, allowedFields); queryConfigHandler.set(ALLOW_ANY_FIELD_QUERIES, allowAnyFieldQueries); queryConfigHandler.set(USE_SLOP_FOR_TOKENIZED_TERMS, useSlopForTokenizedTerms); queryConfigHandler.set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, allowLeadingWildCard); QueryNodeProcessor processor = new CustomQueryNodeProcessorPipeline(queryConfigHandler); QueryBuilder builder = new JexlTreeBuilder(allowedFunctions); org.apache.lucene.queryparser.flexible.core.nodes.QueryNode queryTree = syntaxParser.parse(query, ""); queryTree = processor.process(queryTree); parsedQuery = (JexlNode) builder.build(queryTree); } catch (Exception e) { throw new ParseException(e); } return parsedQuery; }
Example #2
Source File: QueryParserHelper.java From lucene-solr with Apache License 2.0 | 3 votes |
/** * Creates a query parser helper object using the specified configuration, * text parser, processor and builder. * * @param queryConfigHandler * the query configuration handler that will be initially set to this * helper * @param syntaxParser * the text parser that will be initially set to this helper * @param processor * the query processor that will be initially set to this helper * @param builder * the query builder that will be initially set to this helper * * @see QueryNodeProcessor * @see SyntaxParser * @see QueryBuilder * @see QueryConfigHandler */ public QueryParserHelper(QueryConfigHandler queryConfigHandler, SyntaxParser syntaxParser, QueryNodeProcessor processor, QueryBuilder builder) { this.syntaxParser = syntaxParser; this.config = queryConfigHandler; this.processor = processor; this.builder = builder; if (processor != null) { processor.setQueryConfigHandler(queryConfigHandler); } }
Example #3
Source File: QueryParserHelper.java From lucene-solr with Apache License 2.0 | 2 votes |
/** * Returns the query builder used to build a object from the query node tree. * The object produced by this builder is returned by * {@link #parse(String, String)}. * * @return the query builder * * @see #setQueryBuilder(QueryBuilder) * @see QueryBuilder */ public QueryBuilder getQueryBuilder() { return this.builder; }
Example #4
Source File: QueryParserHelper.java From lucene-solr with Apache License 2.0 | 1 votes |
/** * The query builder that will be used to build an object from the query node * tree. It cannot be <code>null</code>. * * @param queryBuilder * the query builder used to build something from the query node tree * * @see #getQueryBuilder() * @see QueryBuilder */ public void setQueryBuilder(QueryBuilder queryBuilder) { if (queryBuilder == null) { throw new IllegalArgumentException("queryBuilder should not be null!"); } this.builder = queryBuilder; }