org.apache.lucene.queryParser.standard

## Class QueryParserUtil

- java.lang.Object
- - org.apache.lucene.queryParser.standard.QueryParserUtil

-     public final class QueryParserUtil
      extends java.lang.Object

  This class defines utility methods to (help) parse query strings into `Query` objects.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `QueryParserUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `escape(java.lang.String s)` Returns a String where those characters that TextParser expects to be escaped are escaped by a preceding `\`.
    `static org.apache.lucene.search.Query` | `parse(java.lang.String[] queries, java.lang.String[] fields, org.apache.lucene.analysis.Analyzer analyzer)` Parses a query which searches on the fields specified.
    `static org.apache.lucene.search.Query` | `parse(java.lang.String[] queries, java.lang.String[] fields, org.apache.lucene.search.BooleanClause.Occur[] flags, org.apache.lucene.analysis.Analyzer analyzer)` Parses a query, searching on the fields specified.
    `static org.apache.lucene.search.Query` | `parse(java.lang.String query, java.lang.String[] fields, org.apache.lucene.search.BooleanClause.Occur[] flags, org.apache.lucene.analysis.Analyzer analyzer)` Parses a query, searching on the fields specified.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### QueryParserUtil

          public QueryParserUtil()

  - ### Method Detail

    - #### parse

          public static org.apache.lucene.search.Query parse(java.lang.String[] queries,
                                                             java.lang.String[] fields,
                                                             org.apache.lucene.analysis.Analyzer analyzer)
                                                      throws QueryNodeException

      Parses a query which searches on the fields specified.

      If x fields are specified, this effectively constructs:

           <code>
           (field1:query1) (field2:query2) (field3:query3)...(fieldx:queryx)
           </code>

      Parameters:
        `queries` - Queries strings to parse
        `fields` - Fields to search on
        `analyzer` - Analyzer to use
      Throws:
        `java.lang.IllegalArgumentException` - if the length of the queries array differs from the length of the fields array
        `QueryNodeException`

    - #### parse

          public static org.apache.lucene.search.Query parse(java.lang.String query,
                                                             java.lang.String[] fields,
                                                             org.apache.lucene.search.BooleanClause.Occur[] flags,
                                                             org.apache.lucene.analysis.Analyzer analyzer)
                                                      throws QueryNodeException

      Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited.

           Usage:
           <code>
           String[] fields = {"filename", "contents", "description"};
           BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
                          BooleanClause.Occur.MUST,
                          BooleanClause.Occur.MUST_NOT};
           MultiFieldQueryParser.parse("query", fields, flags, analyzer);
           </code>

      The code above would construct a query:

           <code>
           (filename:query) +(contents:query) -(description:query)
           </code>

      Parameters:
        `query` - Query string to parse
        `fields` - Fields to search on
        `flags` - Flags describing the fields
        `analyzer` - Analyzer to use
      Throws:
        `java.lang.IllegalArgumentException` - if the length of the fields array differs from the length of the flags array
        `QueryNodeException`

    - #### parse

          public static org.apache.lucene.search.Query parse(java.lang.String[] queries,
                                                             java.lang.String[] fields,
                                                             org.apache.lucene.search.BooleanClause.Occur[] flags,
                                                             org.apache.lucene.analysis.Analyzer analyzer)
                                                      throws QueryNodeException

      Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited.

           Usage:
           <code>
           String[] query = {"query1", "query2", "query3"};
           String[] fields = {"filename", "contents", "description"};
           BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
                          BooleanClause.Occur.MUST,
                          BooleanClause.Occur.MUST_NOT};
           MultiFieldQueryParser.parse(query, fields, flags, analyzer);
           </code>

      The code above would construct a query:

           <code>
           (filename:query1) +(contents:query2) -(description:query3)
           </code>

      Parameters:
        `queries` - Queries string to parse
        `fields` - Fields to search on
        `flags` - Flags describing the fields
        `analyzer` - Analyzer to use
      Throws:
        `java.lang.IllegalArgumentException` - if the length of the queries, fields, and flags array differ
        `QueryNodeException`

    - #### escape

          public static java.lang.String escape(java.lang.String s)

      Returns a String where those characters that TextParser expects to be escaped are escaped by a preceding `\`.

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.