Package org.apache.lucene.queryparser.flexible.messages

Examples of org.apache.lucene.queryparser.flexible.messages.MessageImpl


  throws QueryNodeException {
    if (node instanceof TwigQueryNode) {
      final TwigQueryNode twig = (TwigQueryNode) node;
      if (twig.getChild() instanceof WildcardNodeQueryNode &&
          twig.getRoot() instanceof WildcardNodeQueryNode) {
        throw new QueryNodeException(new MessageImpl("Twig with both root and child empty is not allowed."));
      }
    }
    return node;
  }
View Full Code Here


  @Override
  protected QueryNode postProcessNode(final QueryNode node) throws QueryNodeException {

    if (node instanceof WildcardQueryNode) {
      throw new QueryNodeException(new MessageImpl("Wildcard not allowed", node
              .toQueryString(new EscapeQuerySyntaxImpl())));
    }


    if (node instanceof FuzzyQueryNode) {
      throw new QueryNodeException(new MessageImpl("Fuzzy not allowed", node
              .toQueryString(new EscapeQuerySyntaxImpl())));
    }

    return node;
View Full Code Here

  @Override
  protected QueryNode preProcessNode(final QueryNode node)
  throws QueryNodeException {
    if (node instanceof SlopQueryNode && ((SlopQueryNode) node).getValue() != 0) {
      throw new QueryNodeException(new MessageImpl("Slop queries are not supported",
        node.toQueryString(new EscapeQuerySyntaxImpl())));
    } else if (node instanceof MultiPhraseQueryNode) {
      throw new QueryNodeException(new MessageImpl("Multi phrase queries are not supported",
        node.toQueryString(new EscapeQuerySyntaxImpl())));
    } else if (node instanceof MatchAllDocsQueryNodeBuilder) {
      throw new QueryNodeException(new MessageImpl("MatchAllDocsQueries are not supported",
        node.toQueryString(new EscapeQuerySyntaxImpl())));
    }
    return node;
  }
View Full Code Here

          } else {
            final ReusableCharArrayReader lowerReader = new ReusableCharArrayReader(lowerText);
            lowerNumber = parser.parse(lowerReader);
          }
        } catch (final Exception e) {
          throw new QueryNodeParseException(new MessageImpl(QueryParserMessages.COULD_NOT_PARSE_NUMBER,
            lowerText, parser.getNumericType() + " parser"), e);
        }
        final Number upperNumber;
        try {
          if (upperText.length == 0) { // open bound
            upperNumber = null;
          } else {
            final ReusableCharArrayReader upperReader = new ReusableCharArrayReader(upperText);
            upperNumber = parser.parse(upperReader);
          }
        } catch (final Exception e) {
          throw new QueryNodeParseException(new MessageImpl(QueryParserMessages.COULD_NOT_PARSE_NUMBER,
            upperText, parser.getNumericType() + " parser"), e);
        }

        final CharSequence field = termRangeNode.getField();
        final NodeNumericQueryNode lowerNode = new NodeNumericQueryNode(field, lowerNumber);
View Full Code Here

      final Analyzer analyzer = this.getQueryConfigHandler()
                                .get(KeywordConfigurationKeys.DATATYPES_ANALYZERS)
                                .get(datatype);
      if (analyzer == null) {
        throw new QueryNodeException(new MessageImpl(
          QueryParserMessages.INVALID_SYNTAX, "No analyzer associated with " + datatype));
      }

      PositionIncrementAttribute posIncrAtt = null;
      int numTokens = 0;
      int positionCount = 0;
      boolean severalTokensAtSamePosition = false;

      final TokenStream source;
      try {
        source = analyzer.tokenStream(field, new StringReader(text));
        source.reset();
      } catch (final IOException e1) {
        throw new RuntimeException(e1);
      }
      final CachingTokenFilter buffer = new CachingTokenFilter(source);

      if (buffer.hasAttribute(PositionIncrementAttribute.class)) {
        posIncrAtt = buffer.getAttribute(PositionIncrementAttribute.class);
      }

      try {
        while (buffer.incrementToken()) {
          numTokens++;
          final int positionIncrement = (posIncrAtt != null) ? posIncrAtt
              .getPositionIncrement() : 1;
          if (positionIncrement != 0) {
            positionCount += positionIncrement;
          } else {
            severalTokensAtSamePosition = true;
          }
        }
      } catch (final IOException e) {
        // ignore
      }

      try {
        // rewind the buffer stream
        buffer.reset();
        // close original stream - all tokens buffered
        source.close();
      } catch (final IOException e) {
        // ignore
      }

      if (!buffer.hasAttribute(CharTermAttribute.class)) {
        return new NoTokenFoundQueryNode();
      }
      final CharTermAttribute termAtt = buffer.getAttribute(CharTermAttribute.class);

      if (numTokens == 0) {
        if (nbTwigs != 0) { // Twig special case
          return new WildcardNodeQueryNode();
        }
        return new NoTokenFoundQueryNode();
      }
      else if (numTokens == 1) {
        String term = null;
        try {
          boolean hasNext;
          hasNext = buffer.incrementToken();
          assert hasNext == true;
          term = termAtt.toString();
        } catch (final IOException e) {
          // safe to ignore, because we know the number of tokens
        }
        fieldNode.setText(term);
        return fieldNode;
      }
      else {
        // no phrase query:
        final LinkedList<QueryNode> children = new LinkedList<QueryNode>();

        int position = -1;

        for (int i = 0; i < numTokens; i++) {
          String term = null;
          final int positionIncrement = 1;

          try {
            final boolean hasNext = buffer.incrementToken();
            assert hasNext == true;
            term = termAtt.toString();

          } catch (final IOException e) {
            // safe to ignore, because we know the number of tokens
          }

          final FieldQueryNode newFieldNode = new FieldQueryNode(field, term, -1, -1);

          if (this.positionIncrementsEnabled) {
            position += positionIncrement;
            newFieldNode.setPositionIncrement(position);
          } else {
            newFieldNode.setPositionIncrement(i);
          }

          children.add(new FieldQueryNode(field, term, -1, -1));
        }

        if (node.getParent() instanceof TokenizedPhraseQueryNode) {
          throw new QueryNodeException(new MessageImpl("Cannot build a MultiPhraseQuery"));
        }
        // If multiple terms at one single position, this must be a query
        // expansion. Perform a OR between the terms.
        if (severalTokensAtSamePosition && positionCount == 1) {
          return new GroupQueryNode(new OrQueryNode(children));
View Full Code Here

        final ReusableCharArrayReader textReader = new ReusableCharArrayReader(text);
        final Number number;
        try {
          number = na.getNumericParser().parse(textReader);
        } catch (final Exception e) {
          throw new QueryNodeParseException(new MessageImpl(QueryParserMessages.COULD_NOT_PARSE_NUMBER, text), e);
        }

        final CharSequence field = fieldNode.getField();
        final NodeNumericQueryNode lowerNode = new NodeNumericQueryNode(field, number);
        final NodeNumericQueryNode upperNode = new NodeNumericQueryNode(field, number);
View Full Code Here

  protected QueryNode preProcessNode(final QueryNode node)
  throws QueryNodeException {
    if (node instanceof TwigQueryNode) {
      if (this.getQueryConfigHandler().has(KeywordConfigurationKeys.ALLOW_TWIG)) {
        if (!this.getQueryConfigHandler().get(KeywordConfigurationKeys.ALLOW_TWIG)) {
          throw new QueryNodeException(new MessageImpl("TwigQuery not allowed", node
            .toQueryString(new EscapeQuerySyntaxImpl())));
        }
      } else {
        throw new IllegalArgumentException("KeywordConfigurationKeys.ALLOW_TWIG should be set on the KeywordQueryConfigHandler");
      }
View Full Code Here

public class ParseException extends QueryNodeParseException {

  private static final long serialVersionUID = 1L;

  public ParseException(final String message, final Throwable throwable) {
    super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, message), throwable);
  }
View Full Code Here

  public ParseException(final String message, final Throwable throwable) {
    super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, message), throwable);
  }

  public ParseException(final String message) {
    super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, message));
  }
View Full Code Here

    // process child and descendant queries
    try {
      processChildren(children, query);
    }
    catch (final TooManyClauses ex) {
      throw new QueryNodeException(new MessageImpl(
          QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES,
          BooleanQuery.getMaxClauseCount(),
          twigNode.toQueryString(new EscapeQuerySyntaxImpl())), ex);
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.queryparser.flexible.messages.MessageImpl

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.