Java Code Examples for org.apache.lucene.queryparser.flexible.core.QueryNodeException

The following examples show how to use org.apache.lucene.queryparser.flexible.core.QueryNodeException. 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: SlopQueryNodeBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public JexlNode build(QueryNode queryNode) throws QueryNodeException {
    JexlNode returnNode = null;
    
    SlopQueryNode phraseSlopNode = (SlopQueryNode) queryNode;
    
    JexlNode node = (JexlNode) phraseSlopNode.getChild().getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
    
    if (node instanceof JexlPhraseNode) {
        JexlPhraseNode phraseNode = (JexlPhraseNode) node;
        returnNode = new JexlWithinNode(phraseNode.getField(), phraseNode.getWordList(), phraseSlopNode.getValue());
    } else if (node instanceof JexlSelectorNode) {
        // if phrase only contained one word, a JexlSelectorNode would be created
        // and then a SlopQueryNode / within makes no sense
        returnNode = node;
    } else {
        throw new UnsupportedOperationException(node.getClass().getName() + " found as a child of a SlopQueryNode -- not implemented");
    }
    
    return returnNode;
}
 
Example 2
Source Project: datawave   Source File: BooleanQueryNodeBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public JexlNode build(QueryNode queryNode) throws QueryNodeException {
    BooleanQueryNode booleanNode = (BooleanQueryNode) queryNode;
    
    JexlNode bNode = null;
    List<QueryNode> children = booleanNode.getChildren();
    
    if (children != null) {
        List<JexlNode> childrenList = new ArrayList<>();
        
        LinkedList<QueryNode> extraNodeList = new LinkedList<>();
        boolean isNegation = false;
        
        for (QueryNode child : children) {
            Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
            if (obj != null) {
                JexlNode query = (JexlNode) obj;
                childrenList.add(query);
            }
        }
        
        bNode = createNode(queryNode, childrenList, isNegation, extraNodeList);
    }
    
    return bNode;
    
}
 
Example 3
Source Project: datawave   Source File: RegexpQueryNodeBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public JexlNode build(QueryNode queryNode) throws QueryNodeException {
    JexlNode returnNode = null;
    
    if (queryNode instanceof RegexpQueryNode) {
        RegexpQueryNode regexpQueryNode = (RegexpQueryNode) queryNode;
        String field = regexpQueryNode.getFieldAsString();
        UnescapedCharSequence ecs = (UnescapedCharSequence) regexpQueryNode.getText();
        
        if (field == null || field.isEmpty()) {
            returnNode = new JexlSelectorNode(JexlSelectorNode.Type.REGEX, "", ecs.toString());
        } else {
            returnNode = new JexlSelectorNode(JexlSelectorNode.Type.REGEX, field, ecs.toString());
        }
    }
    
    return returnNode;
}
 
Example 4
Source Project: datawave   Source File: PhraseQueryNodeBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public datawave.query.language.tree.QueryNode build(QueryNode queryNode) throws QueryNodeException {
    TokenizedPhraseQueryNode phraseNode = (TokenizedPhraseQueryNode) queryNode;
    datawave.query.language.tree.QueryNode bNode = null;
    
    List<QueryNode> children = phraseNode.getChildren();
    List<datawave.query.language.tree.QueryNode> childrenList = new ArrayList<>();
    
    if (children != null) {
        
        for (QueryNode child : children) {
            SelectorNode selectorNode = (SelectorNode) child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
            childrenList.add(selectorNode);
        }
    }
    
    if (children != null) {
        datawave.query.language.tree.QueryNode[] childrenArray = new datawave.query.language.tree.QueryNode[childrenList.size()];
        childrenList.toArray(childrenArray);
        bNode = new AdjNode((childrenArray.length - 1), childrenArray);
    } else {
        throw new QueryNodeException(new MessageImpl("Unknown class: " + queryNode.getClass().getName()));
    }
    
    return bNode;
}
 
Example 5
Source Project: lucene-solr   Source File: SpanOrQueryNodeBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public SpanOrQuery build(QueryNode node) throws QueryNodeException {

  // validates node
  BooleanQueryNode booleanNode = (BooleanQueryNode) node;

  List<QueryNode> children = booleanNode.getChildren();
  SpanQuery[] spanQueries = new SpanQuery[children.size()];

  int i = 0;
  for (QueryNode child : children) {
    spanQueries[i++] = (SpanQuery) child
        .getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
  }

  return new SpanOrQuery(spanQueries);

}
 
Example 6
Source Project: lucene-solr   Source File: SolrSuggester.java    License: Apache License 2.0 6 votes vote down vote up
private BooleanQuery parseContextFilterQuery(String contextFilter) {
  if(contextFilter == null){
    return null;
  }

  Query query = null;
  try {
    query = new StandardQueryParser(contextFilterQueryAnalyzer).parse(contextFilter, CONTEXTS_FIELD_NAME);
    if (query instanceof BooleanQuery) {
      return (BooleanQuery) query;
    }
    return new BooleanQuery.Builder().add(query, BooleanClause.Occur.MUST).build();
  } catch (QueryNodeException e) {
    throw new IllegalArgumentException("Failed to parse query: " + query);
  }
}
 
Example 7
Source Project: lucene-solr   Source File: TestMultiFieldQPHelper.java    License: Apache License 2.0 6 votes vote down vote up
public void testStaticMethod2Old() throws QueryNodeException {
  String[] fields = { "b", "t" };
  BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST,
      BooleanClause.Occur.MUST_NOT };
  StandardQueryParser parser = new StandardQueryParser();
  parser.setMultiFields(fields);
  parser.setAnalyzer(new MockAnalyzer(random()));

  Query q = QueryParserUtil.parse("one", fields, flags,
      new MockAnalyzer(random()));// , fields, flags, new
  // MockAnalyzer());
  assertEquals("+b:one -t:one", q.toString());

  q = QueryParserUtil.parse("one two", fields, flags, new MockAnalyzer(random()));
  assertEquals("+(b:one b:two) -(t:one t:two)", q.toString());

  // expected exception, array length differs
  expectThrows(IllegalArgumentException.class, () -> {
    BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
    QueryParserUtil.parse("blah", fields, flags2, new MockAnalyzer(random()));
  });
}
 
Example 8
Source Project: lucene-solr   Source File: OpenRangeQueryNodeProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
  
  if (node instanceof TermRangeQueryNode) {
    TermRangeQueryNode rangeNode = (TermRangeQueryNode) node;
    FieldQueryNode lowerNode = rangeNode.getLowerBound();
    FieldQueryNode upperNode = rangeNode.getUpperBound();
    CharSequence lowerText = lowerNode.getText();
    CharSequence upperText = upperNode.getText();
    
    if (OPEN_RANGE_TOKEN.equals(upperNode.getTextAsString())
        && (!(upperText instanceof UnescapedCharSequence) || !((UnescapedCharSequence) upperText)
            .wasEscaped(0))) {
      upperText = "";
    }
    
    if (OPEN_RANGE_TOKEN.equals(lowerNode.getTextAsString())
        && (!(lowerText instanceof UnescapedCharSequence) || !((UnescapedCharSequence) lowerText)
            .wasEscaped(0))) {
      lowerText = "";
    }
    
    lowerNode.setText(lowerText);
    upperNode.setText(upperText);
  }
  
  return node;
  
}
 
Example 9
Source Project: datawave   Source File: CustomFieldLimiterNodeProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
    
    if (getQueryConfigHandler().has(ConfigurationKeys.ENABLE_POSITION_INCREMENTS)) {
        
        if (getQueryConfigHandler().has(LuceneToJexlQueryParser.ALLOWED_FIELDS)) {
            allowedFields = new HashSet<>();
            allowedFields.addAll(getQueryConfigHandler().get(LuceneToJexlQueryParser.ALLOWED_FIELDS));
        }
        if (getQueryConfigHandler().has(LuceneToJexlQueryParser.ALLOW_ANY_FIELD_QUERIES)) {
            allowAnyFieldQueries = getQueryConfigHandler().get(LuceneToJexlQueryParser.ALLOW_ANY_FIELD_QUERIES);
        }
    }
    return node;
}
 
Example 10
Source Project: lucene-solr   Source File: ModifierQueryNodeBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query build(QueryNode queryNode) throws QueryNodeException {
  ModifierQueryNode modifierNode = (ModifierQueryNode) queryNode;

  return (Query) (modifierNode).getChild().getTag(
      QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);

}
 
Example 11
Source Project: lucene-solr   Source File: GroupQueryNodeBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query build(QueryNode queryNode) throws QueryNodeException {
  GroupQueryNode groupNode = (GroupQueryNode) queryNode;

  return (Query) (groupNode).getChild().getTag(
      QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);

}
 
Example 12
Source Project: lucene-solr   Source File: TestSpanQueryParser.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryValidator() throws QueryNodeException {

    expectThrows(QueryNodeException.class, () -> {
      getSpanQuery("term*"); // wildcard queries should not be supported
    });

    expectThrows(QueryNodeException.class, () -> {
      getSpanQuery("[a TO z]"); // range queries should not be supported
    });

    expectThrows(QueryNodeException.class, () -> {
      getSpanQuery("a~0.5"); // boost queries should not be supported
    });

    expectThrows(QueryNodeException.class, () -> {
      getSpanQuery("a^0.5"); // fuzzy queries should not be supported
    });

    expectThrows(QueryNodeException.class, () -> {
      getSpanQuery("\"a b\""); // quoted queries should not be supported
    });

    expectThrows(QueryNodeException.class, () -> {
      getSpanQuery("(a b)"); // parenthesized queries should not be supported
    });

    expectThrows(QueryNodeException.class, () -> {
      getSpanQuery("a AND b"); // AND queries should not be supported
    });
  }
 
Example 13
Source Project: lucene-solr   Source File: TestQPHelper.java    License: Apache License 2.0 5 votes vote down vote up
public void testBooleanQuery() throws Exception {
  IndexSearcher.setMaxClauseCount(2);
  expectThrows(QueryNodeException.class, () -> {
    StandardQueryParser qp = new StandardQueryParser();
    qp.setAnalyzer(new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false));

    qp.parse("one two three", "field");
  });
}
 
Example 14
@Override
public PrefixQuery build(QueryNode queryNode) throws QueryNodeException {    

  PrefixWildcardQueryNode wildcardNode = (PrefixWildcardQueryNode) queryNode;

  String text = wildcardNode.getText().subSequence(0, wildcardNode.getText().length() - 1).toString();
  PrefixQuery q = new PrefixQuery(new Term(wildcardNode.getFieldAsString(), text));
  
  MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode.getTag(MultiTermRewriteMethodProcessor.TAG_ID);
  if (method != null) {
    q.setRewriteMethod(method);
  }
  
  return q;
}
 
Example 15
@Override
public QueryNode process(QueryNode queryTree) throws QueryNodeException {
  Operator op = getQueryConfigHandler().get(ConfigurationKeys.DEFAULT_OPERATOR);
  
  if (op == null) {
    throw new IllegalArgumentException(
        "StandardQueryConfigHandler.ConfigurationKeys.DEFAULT_OPERATOR should be set on the QueryConfigHandler");
  }

  this.usingAnd = StandardQueryConfigHandler.Operator.AND == op;

  return super.process(queryTree);

}
 
Example 16
Source Project: lucene-solr   Source File: MultiFieldQueryNodeProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void processChildren(QueryNode queryTree) throws QueryNodeException {

  if (this.processChildren) {
    super.processChildren(queryTree);

  } else {
    this.processChildren = true;
  }

}
 
Example 17
Source Project: lucene-solr   Source File: PointRangeQueryNode.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the upper and lower bounds of this range query node and the
 * {@link PointsConfig} associated with these bounds.
 * 
 * @param lower the lower bound
 * @param upper the upper bound
 * @param lowerInclusive <code>true</code> if the lower bound is inclusive, otherwise, <code>false</code>
 * @param upperInclusive <code>true</code> if the upper bound is inclusive, otherwise, <code>false</code>
 * @param pointsConfig the {@link PointsConfig} that represents associated with the upper and lower bounds
 * 
 */
public void setBounds(PointQueryNode lower, PointQueryNode upper,
    boolean lowerInclusive, boolean upperInclusive, PointsConfig pointsConfig) throws QueryNodeException {
  
  if (pointsConfig == null) {
    throw new IllegalArgumentException("pointsConfig must not be null!");
  }
  
  Class<? extends Number> lowerNumberType, upperNumberType;
  
  if (lower != null && lower.getValue() != null) {
    lowerNumberType = lower.getValue().getClass();
  } else {
    lowerNumberType = null;
  }
  
  if (upper != null && upper.getValue() != null) {
    upperNumberType = upper.getValue().getClass();
  } else {
    upperNumberType = null;
  }
  
  if (lowerNumberType != null
      && !lowerNumberType.equals(pointsConfig.getType())) {
    throw new IllegalArgumentException(
        "lower value's type should be the same as numericConfig type: "
            + lowerNumberType + " != " + pointsConfig.getType());
  }
  
  if (upperNumberType != null
      && !upperNumberType.equals(pointsConfig.getType())) {
    throw new IllegalArgumentException(
        "upper value's type should be the same as numericConfig type: "
            + upperNumberType + " != " + pointsConfig.getType());
  }
  
  super.setBounds(lower, upper, lowerInclusive, upperInclusive);
  this.numericConfig = pointsConfig;
}
 
Example 18
Source Project: lucene-solr   Source File: FieldQueryNodeBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TermQuery build(QueryNode queryNode) throws QueryNodeException {
  FieldQueryNode fieldNode = (FieldQueryNode) queryNode;

  return new TermQuery(new Term(fieldNode.getFieldAsString(), fieldNode
      .getTextAsString()));

}
 
Example 19
Source Project: lucene-solr   Source File: FuzzyQueryNodeProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {

  if (node instanceof FuzzyQueryNode) {
    FuzzyQueryNode fuzzyNode = (FuzzyQueryNode) node;
    QueryConfigHandler config = getQueryConfigHandler();

    Analyzer analyzer = getQueryConfigHandler().get(ConfigurationKeys.ANALYZER);
    if (analyzer != null) {
      // because we call utf8ToString, this will only work with the default TermToBytesRefAttribute
      String text = fuzzyNode.getTextAsString();
      text = analyzer.normalize(fuzzyNode.getFieldAsString(), text).utf8ToString();
      fuzzyNode.setText(text);
    }

    FuzzyConfig fuzzyConfig = null;
    
    if ((fuzzyConfig = config.get(ConfigurationKeys.FUZZY_CONFIG)) != null) {
      fuzzyNode.setPrefixLength(fuzzyConfig.getPrefixLength());

      if (fuzzyNode.getSimilarity() < 0) {
        fuzzyNode.setSimilarity(fuzzyConfig.getMinSimilarity());
      }
      
    } else if (fuzzyNode.getSimilarity() < 0) {
      throw new IllegalArgumentException("No FUZZY_CONFIG set in the config");
    }

  }

  return node;

}
 
Example 20
Source Project: lucene-solr   Source File: MatchNoDocsQueryNodeBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public MatchNoDocsQuery build(QueryNode queryNode) throws QueryNodeException {

  // validates node
  if (!(queryNode instanceof MatchNoDocsQueryNode)) {
    throw new QueryNodeException(new MessageImpl(
        QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, queryNode
            .toQueryString(new EscapeQuerySyntaxImpl()), queryNode.getClass()
            .getName()));
  }

  return new MatchNoDocsQuery();

}
 
Example 21
Source Project: lucene-solr   Source File: SpanTermQueryNodeBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SpanTermQuery build(QueryNode node) throws QueryNodeException {
  FieldQueryNode fieldQueryNode = (FieldQueryNode) node;

  return new SpanTermQuery(new Term(fieldQueryNode.getFieldAsString(),
      fieldQueryNode.getTextAsString()));

}
 
Example 22
@Override
public QueryNode process(QueryNode queryTree) throws QueryNodeException {
  Operator op = getQueryConfigHandler().get(
      ConfigurationKeys.DEFAULT_OPERATOR);
  
  if (op == null) {
    throw new IllegalArgumentException(
        "StandardQueryConfigHandler.ConfigurationKeys.DEFAULT_OPERATOR should be set on the QueryConfigHandler");
  }
  
  this.usingAnd = StandardQueryConfigHandler.Operator.AND == op;
  
  return processIteration(queryTree);
  
}
 
Example 23
Source Project: lucene-solr   Source File: TestQPHelper.java    License: Apache License 2.0 5 votes vote down vote up
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, 1000).scoreDocs;
  assertEquals(expected, hits.length);
}
 
Example 24
Source Project: lucene-solr   Source File: FuzzyQueryNodeBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FuzzyQuery build(QueryNode queryNode) throws QueryNodeException {
  FuzzyQueryNode fuzzyNode = (FuzzyQueryNode) queryNode;
  String text = fuzzyNode.getTextAsString();
  
  int numEdits = FuzzyQuery.floatToEdits(fuzzyNode.getSimilarity(), 
      text.codePointCount(0, text.length()));
  
  return new FuzzyQuery(new Term(fuzzyNode.getFieldAsString(), fuzzyNode
      .getTextAsString()), numEdits, fuzzyNode
      .getPrefixLength());

}
 
Example 25
Source Project: lucene-solr   Source File: SynonymQueryNodeBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query build(QueryNode queryNode) throws QueryNodeException {
  // TODO: use SynonymQuery instead
  SynonymQueryNode node = (SynonymQueryNode) queryNode;
  BooleanQuery.Builder builder = new BooleanQuery.Builder();
  for (QueryNode child : node.getChildren()) {
    Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);

    if (obj != null) {
      Query query = (Query) obj;
      builder.add(query, Occur.SHOULD);
    }
  }
  return builder.build();
}
 
Example 26
Source Project: lucene-solr   Source File: AllowLeadingWildcardProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public QueryNode process(QueryNode queryTree) throws QueryNodeException {
  Boolean allowsLeadingWildcard = getQueryConfigHandler().get(ConfigurationKeys.ALLOW_LEADING_WILDCARD);

  if (allowsLeadingWildcard != null) {

    if (!allowsLeadingWildcard) {
      return super.process(queryTree);
    }

  }

  return queryTree;
}
 
Example 27
Source Project: datawave   Source File: CustomAnalyzerQueryNodeProcessor.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * establish configuration from <code>QueryConfigHandler</code> and process the speicfied tree
 *
 * @param queryTree
 *            the query tree to process
 * @return the processed tree.
 * @throws QueryNodeException
 *             if there's a problem processing the tree
 */
@Override
public QueryNode process(QueryNode queryTree) throws QueryNodeException {
    
    if (getQueryConfigHandler().has(ConfigurationKeys.ANALYZER)) {
        this.analyzer = getQueryConfigHandler().get(ConfigurationKeys.ANALYZER);
    }
    
    this.positionIncrementsEnabled = false;
    
    if (getQueryConfigHandler().has(ConfigurationKeys.ENABLE_POSITION_INCREMENTS)) {
        
        if (getQueryConfigHandler().get(ConfigurationKeys.ENABLE_POSITION_INCREMENTS)) {
            this.positionIncrementsEnabled = true;
        }
    }
    
    if (getQueryConfigHandler().has(LuceneToJexlQueryParser.TOKENIZED_FIELDS)) {
        getQueryConfigHandler().get(LuceneToJexlQueryParser.TOKENIZED_FIELDS).forEach(s -> tokenizedFields.add(s.toUpperCase()));
    }
    
    if (getQueryConfigHandler().has(LuceneToJexlQueryParser.SKIP_TOKENIZE_UNFIELDED_FIELDS)) {
        skipTokenizeUnfieldedFields.clear();
        getQueryConfigHandler().get(LuceneToJexlQueryParser.SKIP_TOKENIZE_UNFIELDED_FIELDS).forEach(s -> skipTokenizeUnfieldedFields.add(s.toUpperCase()));
    }
    
    if (getQueryConfigHandler().has(LuceneToJexlQueryParser.TOKENIZE_UNFIELDED_QUERIES)) {
        this.unfieldedTokenized = getQueryConfigHandler().get(LuceneToJexlQueryParser.TOKENIZE_UNFIELDED_QUERIES);
    }
    
    if (getQueryConfigHandler().has(LuceneToJexlQueryParser.USE_SLOP_FOR_TOKENIZED_TERMS)) {
        this.useSlopForTokenizedTerms = getQueryConfigHandler().get(LuceneToJexlQueryParser.USE_SLOP_FOR_TOKENIZED_TERMS);
    }
    
    QueryNode processedQueryTree = super.process(queryTree);
    
    if (logger.isDebugEnabled()) {
        logger.debug("Analyzer: " + analyzer);
        logger.debug("Position Increments Enabled: " + positionIncrementsEnabled);
        logger.debug("TokenizedFields: " + Arrays.toString(tokenizedFields.toArray()));
        logger.debug("SkipTokenizeUnfieldedFields: " + Arrays.toString(skipTokenizeUnfieldedFields.toArray()));
        logger.debug("Tokenize Unfielded Queries: " + this.unfieldedTokenized);
        logger.debug("Use Slop for Tokenized Terms: " + this.useSlopForTokenizedTerms);
        logger.debug("Original QueryTree: " + queryTree);
        logger.debug("Processed QueryTree: " + queryTree);
    }
    
    return processedQueryTree;
}
 
Example 28
Source Project: datawave   Source File: CustomAnalyzerQueryNodeProcessor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
    
    if (logger.isDebugEnabled()) {
        logger.debug("Incoming query node: " + node);
    }
    
    final Class<?> nodeClazz = node.getClass();
    
    if (SlopQueryNode.class.isAssignableFrom(nodeClazz)) {
        /*
         * SlopQueryNodes typically contain a QuotedFieldQueryNode, so simply call the preProcessNode method on that child immediately, so that preserve the
         * slop as an attribute and return the result. This also allows us to replace the slop node with the OR node produced in tokenize node.
         */
        SlopQueryNode slopNode = (SlopQueryNode) node;
        QueryNode childNode = slopNode.getChild();
        childNode.setTag(ORIGINAL_SLOP, slopNode.getValue());
        QueryNode newChildNode = preProcessNode(childNode);
        if (childNode != newChildNode) {
            return newChildNode;
        }
        return slopNode;
    } else if (TextableQueryNode.class.isAssignableFrom(nodeClazz)) {
        
        if (WildcardQueryNode.class.isAssignableFrom(nodeClazz)) {
            return node;
        } else if (FuzzyQueryNode.class.isAssignableFrom(nodeClazz)) {
            return node;
        } else if (node.getParent() != null && TermRangeQueryNode.class.isAssignableFrom(node.getParent().getClass())) {
            // Ignore children of TermReangeQueryNodes (for now)
            return node;
        }
        
        final TextableQueryNode textableNode = (TextableQueryNode) node;
        final String text = textableNode.getText().toString();
        
        FieldQueryNode fieldNode;
        String field = "";
        
        if (FieldQueryNode.class.isAssignableFrom(nodeClazz)) {
            fieldNode = (FieldQueryNode) node;
            field = fieldNode.getFieldAsString();
            
            // treat these fields as un-fielded and skip tokenization if enabled.
            if (skipTokenizeUnfieldedFields.contains(field.toUpperCase())) {
                fieldNode.setField("");
                
                if (logger.isDebugEnabled()) {
                    logger.debug("Skipping tokenization of un-fielded query node: " + fieldNode);
                }
                
                return node;
            }
        }
        
        if ((tokenizedFields.contains(field.toUpperCase()) || (unfieldedTokenized && field.isEmpty()))) {
            node = tokenizeNode(node, text, field);
        }
        
        if (logger.isDebugEnabled()) {
            logger.debug("Post-processed query node: " + node);
        }
    }
    
    return node;
}
 
Example 29
Source Project: datawave   Source File: CustomAnalyzerQueryNodeProcessor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
    return node; /* no-op */
}
 
Example 30
Source Project: lucene-solr   Source File: TestQPHelper.java    License: Apache License 2.0 4 votes vote down vote up
public void testCustomQueryParserWildcard() {
  expectThrows(QueryNodeException.class, () -> {
    new QPTestParser(new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)).parse("a?t", "contents");
  });
}