QueryParsing (Solr 3.6.2 API)
Keywords: org.apache.solr.search.QueryParsing class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.solr.search
Class QueryParsing

    java.lang.Object
      org.apache.solr.search.QueryParsing

    public class QueryParsing

extends Object

Collection of static utilities useful for query parsing.

Version:
  $Id: QueryParsing.java 1152657 2011-07-31 22:43:13Z hossman $

Nested Class Summary
`static class` | `QueryParsing.StrParser` Simple class to help with parsing a string Note: This API is experimental and may change in non backward-compatible ways in the future

Field Summary
`static String` | `DEFTYPE`
`static String` | `DOCID`
`static String` | `F`
`static char` | `LOCALPARAM_END`
`static String` | `LOCALPARAM_START`
`static String` | `OP`
`static String` | `SCORE`
`static String` | `TYPE`
`static String` | `V`
`static String` | `VAL_EXPLICIT`

Constructor Summary
`QueryParsing()`

Method Summary
`static String` | `encodeLocalParamVal(String val)`
`static SolrParams` | `getLocalParams(String txt, SolrParams params)` "foo" returns null "{!prefix f=myfield}yes" returns type="prefix",f="myfield",v="yes" "{!prefix f=myfield v=$p}" returns type="prefix",f="myfield",v=params.get("p")
`static FunctionQuery` | `parseFunction(String func, IndexSchema schema)` Parse a function, returning a FunctionQuery
`static Query` | `parseQuery(String qs, IndexSchema schema)` Helper utility for parsing a query using the Lucene QueryParser syntax.
`static Query` | `parseQuery(String qs, String defaultField, IndexSchema schema)` Helper utility for parsing a query using the Lucene QueryParser syntax.
`static Query` | `parseQuery(String qs, String defaultField, SolrParams params, IndexSchema schema)` Helper utility for parsing a query using the Lucene QueryParser syntax.
`static Sort` | `parseSort(String sortSpec, SolrQueryRequest req)` Returns null if the sortSpec is the standard sort desc.
`static List<String>` | `toString(List<Query> queries, IndexSchema schema)` Builds a list of String which are stringified versions of a list of Queries
`static String` | `toString(Query query, IndexSchema schema)` Formats a Query for debugging, using the IndexSchema to make complex field types readable.
`static void` | `toString(Query query, IndexSchema schema, Appendable out, int flags)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### OP

    public static final String OP

See Also:
  Constant Field Values

### V

    public static final String V

See Also:
  Constant Field Values

### F

    public static final String F

See Also:
  Constant Field Values

### TYPE

    public static final String TYPE

See Also:
  Constant Field Values

### DEFTYPE

    public static final String DEFTYPE

See Also:
  Constant Field Values

### LOCALPARAM_START

    public static final String LOCALPARAM_START

See Also:
  Constant Field Values

### LOCALPARAM_END

    public static final char LOCALPARAM_END

See Also:
  Constant Field Values

### DOCID

    public static final String DOCID

See Also:
  Constant Field Values

### SCORE

    public static final String SCORE

See Also:
  Constant Field Values

### VAL_EXPLICIT

    public static final String VAL_EXPLICIT

See Also:
  Constant Field Values

Constructor Detail

### QueryParsing

    public QueryParsing()

Method Detail

### parseQuery

    public static Query parseQuery(String qs,
                                   IndexSchema schema)

  Helper utility for parsing a query using the Lucene QueryParser syntax.

  Parameters:
    `qs` - query expression in standard Lucene syntax
    `schema` - used for default operator (overridden by params) and passed to the query parser for field format analysis information

### parseQuery

    public static Query parseQuery(String qs,
                                   String defaultField,
                                   IndexSchema schema)

  Helper utility for parsing a query using the Lucene QueryParser syntax.

  Parameters:
    `qs` - query expression in standard Lucene syntax
    `defaultField` - default field used for unqualified search terms in the query expression
    `schema` - used for default operator (overridden by params) and passed to the query parser for field format analysis information

### parseQuery

    public static Query parseQuery(String qs,
                                   String defaultField,
                                   SolrParams params,
                                   IndexSchema schema)

  Helper utility for parsing a query using the Lucene QueryParser syntax.

  Parameters:
    `qs` - query expression in standard Lucene syntax
    `defaultField` - default field used for unqualified search terms in the query expression
    `params` - used to determine the default operator, overriding the schema specified operator
    `schema` - used for default operator (overridden by params) and passed to the query parser for field format analysis information

### encodeLocalParamVal

    public static String encodeLocalParamVal(String val)

### getLocalParams

    public static SolrParams getLocalParams(String txt,
                                            SolrParams params)
                                     throws ParseException

  "foo" returns null "{!prefix f=myfield}yes" returns type="prefix",f="myfield",v="yes" "{!prefix f=myfield v=$p}" returns type="prefix",f="myfield",v=params.get("p")

  Throws:
    `ParseException`

### parseSort

    public static Sort parseSort(String sortSpec,
                                 SolrQueryRequest req)

  Returns null if the sortSpec is the standard sort desc.

  The form of the sort specification string currently parsed is:

      >
       SortSpec ::= SingleSort [, SingleSort]*
       SingleSort ::=  SortDirection
       SortDirection ::= top | desc | bottom | asc

  Examples:

         score desc               #normal sort by score (will return null)
         weight bottom            #sort by weight ascending
         weight desc              #sort by weight descending
         height desc,weight desc  #sort by height descending, and use weight descending to break any ties
         height desc,weight asc   #sort by height descending, using weight ascending as a tiebreaker

### toString

    public static void toString(Query query,
                                IndexSchema schema,
                                Appendable out,
                                int flags)
                         throws IOException

  Throws:
    `IOException`
  See Also:
    `toString(Query,IndexSchema)`

### toString

    public static String toString(Query query,
                                  IndexSchema schema)

  Formats a Query for debugging, using the IndexSchema to make complex field types readable.

  The benefit of using this method instead of calling `Query.toString` directly is that it knows about the data types of each field, so any field which is encoded in a particularly complex way is still readable. The downside is that it only knows about built in Query types, and will not be able to format custom Query classes.

### toString

    public static List<String> toString(List<Query> queries,
                                        IndexSchema schema)

  Builds a list of String which are stringified versions of a list of Queries

### parseFunction

    public static FunctionQuery parseFunction(String func,
                                              IndexSchema schema)
                                       throws ParseException

  Parse a function, returning a FunctionQuery

  Syntax Examples....

       // Numeric fields default to correct type
       // (ie: IntFieldSource or FloatFieldSource)
       // Others use explicit ord(...) to generate numeric field value
       myfield

       // OrdFieldSource
       ord(myfield)

       // ReverseOrdFieldSource
       rord(myfield)

       // LinearFloatFunction on numeric field value
       linear(myfield,1,2)

       // MaxFloatFunction of LinearFloatFunction on numeric field value or constant
       max(linear(myfield,1,2),100)

       // ReciprocalFloatFunction on numeric field value
       recip(myfield,1,2,3)

       // ReciprocalFloatFunction on ReverseOrdFieldSource
       recip(rord(myfield),1,2,3)

       // ReciprocalFloatFunction on LinearFloatFunction on ReverseOrdFieldSource
       recip(linear(rord(myfield),1,2),3,4,5)

  Throws:
    `ParseException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD