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

The following examples show how to use org.apache.lucene.queryparser.flexible.core.QueryNodeException. 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: SpanOrQueryNodeBuilder.java    From lucene-solr with 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 #2
Source File: SlopQueryNodeBuilder.java    From datawave with 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 #3
Source File: PhraseQueryNodeBuilder.java    From datawave with 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 #4
Source File: RegexpQueryNodeBuilder.java    From datawave with 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 #5
Source File: SolrSuggester.java    From lucene-solr with 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 #6
Source File: BooleanQueryNodeBuilder.java    From datawave with 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 #7
Source File: TestMultiFieldQPHelper.java    From lucene-solr with 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 File: PointRangeQueryNode.java    From lucene-solr with 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 #9
Source File: TestQPHelper.java    From lucene-solr with 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 #10
Source File: TestSpanQueryParser.java    From lucene-solr with 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 #11
Source File: SynonymQueryNodeBuilder.java    From lucene-solr with 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 #12
Source File: GroupQueryNodeBuilder.java    From lucene-solr with 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 #13
Source File: CustomFieldLimiterNodeProcessor.java    From datawave with 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 #14
Source File: AllowLeadingWildcardProcessor.java    From lucene-solr with 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 #15
Source File: OpenRangeQueryNodeProcessor.java    From lucene-solr with 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 #16
Source File: ModifierQueryNodeBuilder.java    From lucene-solr with 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 #17
Source File: TestQPHelper.java    From lucene-solr with 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 #18
Source File: BooleanQuery2ModifierNodeProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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 #19
Source File: SpanTermQueryNodeBuilder.java    From lucene-solr with 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 #20
Source File: MatchNoDocsQueryNodeBuilder.java    From lucene-solr with 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 File: FuzzyQueryNodeProcessor.java    From lucene-solr with 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 #22
Source File: PrefixWildcardQueryNodeBuilder.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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 #23
Source File: BooleanModifiersQueryNodeProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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 #24
Source File: FieldQueryNodeBuilder.java    From lucene-solr with 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 #25
Source File: MultiFieldQueryNodeProcessor.java    From lucene-solr with 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 #26
Source File: FuzzyQueryNodeBuilder.java    From lucene-solr with 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 #27
Source File: QueryTreeBuilder.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void process(QueryNode node) throws QueryNodeException {

    if (node != null) {
      QueryBuilder builder = getBuilder(node);

      if (!(builder instanceof QueryTreeBuilder)) {
        List<QueryNode> children = node.getChildren();

        if (children != null) {

          for (QueryNode child : children) {
            process(child);
          }

        }

      }

      processNode(node, builder);

    }

  }
 
Example #28
Source File: TestSpanQueryParser.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public SpanQuery getSpanQuery(CharSequence query) throws QueryNodeException {
  return getSpanQuery("", query);
}
 
Example #29
Source File: PointQueryNodeProcessor.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
  
  if (node instanceof FieldQueryNode
      && !(node.getParent() instanceof RangeQueryNode)) {
    
    QueryConfigHandler config = getQueryConfigHandler();
    
    if (config != null) {
      FieldQueryNode fieldNode = (FieldQueryNode) node;
      FieldConfig fieldConfig = config.getFieldConfig(fieldNode
          .getFieldAsString());
      
      if (fieldConfig != null) {
        PointsConfig numericConfig = fieldConfig.get(ConfigurationKeys.POINTS_CONFIG);
        
        if (numericConfig != null) {
          
          NumberFormat numberFormat = numericConfig.getNumberFormat();
          String text = fieldNode.getTextAsString();
          Number number = null;
          
          if (text.length() > 0) {
            
            try {
              number = numberFormat.parse(text);
              
            } catch (ParseException e) {
              throw new QueryNodeParseException(new MessageImpl(
                  QueryParserMessages.COULD_NOT_PARSE_NUMBER, fieldNode
                      .getTextAsString(), numberFormat.getClass()
                      .getCanonicalName()), e);
            }
            
            if (Integer.class.equals(numericConfig.getType())) {
              number = number.intValue();
            } else if (Long.class.equals(numericConfig.getType())) {
              number = number.longValue();
            } else if (Double.class.equals(numericConfig.getType())) {
              number = number.doubleValue();
            } else if (Float.class.equals(numericConfig.getType())) {
              number = number.floatValue();
            }
            
          } else {
            throw new QueryNodeParseException(new MessageImpl(
                QueryParserMessages.NUMERIC_CANNOT_BE_EMPTY, fieldNode.getFieldAsString()));
          }
          
          PointQueryNode lowerNode = new PointQueryNode(fieldNode.getField(), number, numberFormat);
          PointQueryNode upperNode = new PointQueryNode(fieldNode.getField(), number, numberFormat);
          
          return new PointRangeQueryNode(lowerNode, upperNode, true, true, numericConfig);
        }
      }
    }
  }
  return node;
}
 
Example #30
Source File: TestMultiAnalyzerQPHelper.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void testMultiAnalyzer() throws QueryNodeException {

    StandardQueryParser qp = new StandardQueryParser();
    qp.setAnalyzer(new MultiAnalyzer());

    // trivial, no multiple tokens:
    assertEquals("foo", qp.parse("foo", "").toString());
    assertEquals("foo", qp.parse("\"foo\"", "").toString());
    assertEquals("foo foobar", qp.parse("foo foobar", "").toString());
    assertEquals("\"foo foobar\"", qp.parse("\"foo foobar\"", "").toString());
    assertEquals("\"foo foobar blah\"", qp.parse("\"foo foobar blah\"", "")
        .toString());

    // two tokens at the same position:
    assertEquals("(multi multi2) foo", qp.parse("multi foo", "").toString());
    assertEquals("foo (multi multi2)", qp.parse("foo multi", "").toString());
    assertEquals("(multi multi2) (multi multi2)", qp.parse("multi multi", "")
        .toString());
    assertEquals("+(foo (multi multi2)) +(bar (multi multi2))", qp.parse(
        "+(foo multi) +(bar multi)", "").toString());
    assertEquals("+(foo (multi multi2)) field:\"bar (multi multi2)\"", qp
        .parse("+(foo multi) field:\"bar multi\"", "").toString());

    // phrases:
    assertEquals("\"(multi multi2) foo\"", qp.parse("\"multi foo\"", "")
        .toString());
    assertEquals("\"foo (multi multi2)\"", qp.parse("\"foo multi\"", "")
        .toString());
    assertEquals("\"foo (multi multi2) foobar (multi multi2)\"", qp.parse(
        "\"foo multi foobar multi\"", "").toString());

    // fields:
    assertEquals("(field:multi field:multi2) field:foo", qp.parse(
        "field:multi field:foo", "").toString());
    assertEquals("field:\"(multi multi2) foo\"", qp.parse(
        "field:\"multi foo\"", "").toString());

    // three tokens at one position:
    assertEquals("triplemulti multi3 multi2", qp.parse("triplemulti", "")
        .toString());
    assertEquals("foo (triplemulti multi3 multi2) foobar", qp.parse(
        "foo triplemulti foobar", "").toString());

    // phrase with non-default slop:
    assertEquals("\"(multi multi2) foo\"~10", qp.parse("\"multi foo\"~10", "")
        .toString());

    // phrase with non-default boost:
    assertEquals("(\"(multi multi2) foo\")^2.0", qp.parse("\"multi foo\"^2", "")
        .toString());

    // phrase after changing default slop
    qp.setPhraseSlop(99);
    assertEquals("\"(multi multi2) foo\"~99 bar", qp.parse("\"multi foo\" bar",
        "").toString());
    assertEquals("\"(multi multi2) foo\"~99 \"foo bar\"~2", qp.parse(
        "\"multi foo\" \"foo bar\"~2", "").toString());
    qp.setPhraseSlop(0);

    // non-default operator:
    qp.setDefaultOperator(StandardQueryConfigHandler.Operator.AND);
    assertEquals("+(multi multi2) +foo", qp.parse("multi foo", "").toString());

  }