Java Code Examples for org.apache.lucene.queryparser.flexible.core.builders.QueryBuilder

The following examples show how to use org.apache.lucene.queryparser.flexible.core.builders.QueryBuilder. These examples are extracted from open source projects. 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 Project: datawave   Source File: LuceneToJexlQueryParser.java    License: Apache License 2.0 5 votes vote down vote up
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 Project: lucene-solr   Source File: QueryParserHelper.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * 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 Project: lucene-solr   Source File: QueryParserHelper.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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 Project: lucene-solr   Source File: QueryParserHelper.java    License: Apache License 2.0 1 votes vote down vote up
/**
 * 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;

}