SMILA 1.0 API documentation

org.eclipse.smila.solr.util
Class SolrQueryUtils

java.lang.Object
  extended by org.eclipse.smila.solr.util.SolrQueryUtils

public final class SolrQueryUtils
extends java.lang.Object

Provide extensions/simplifications for handling SolrQuery.


Field Summary
static java.lang.String ESCAPE_CHARS
          chars, that if part of a term need to be escaped when searching.
static java.lang.String ESCAPE_CHARS_WS
          chars, that if part of a term need to be escaped when searching. including space
static java.lang.String OR_SEPARATOR
          Lucene/Solr operator for OR query parts.
static java.lang.String QUERY_WRAPPER_FILTER
          The query wrapper filter string.
 
Method Summary
static void appendFieldQueryPart(java.lang.StringBuilder q, java.lang.String field, java.util.List<Value> values)
           
static java.lang.String decodeQuery(java.lang.String query)
           
static java.lang.String encodeQuery(java.lang.String query)
          Encode a query into application/x-www-form-urlencoded format.
static java.lang.String escapeQuery(java.lang.String query)
          Escapes all chars with a special meaning to the lucene query parser.
static java.lang.String escapeQuery(java.lang.String query, java.lang.String escapeChars)
          Escapes the given chars in the given query by prepending '\'.
static boolean responseStatusIsError(SolrResponseBase response)
          returns true if response indicates an error.
static java.lang.String toConstQueryOnField(java.lang.String fieldName, java.lang.String constant)
          creates a query string on the given field for a constant which must be searched "as is", i.e. escaping fo chars and wrapping in quotes
static java.lang.String toSolrQueryFilter(java.lang.String filter)
          Convert a lucene QueryWrapperFilter to a query filter for solr.
static java.lang.String toTokenQueryOnField(java.lang.String fieldName, java.lang.String token)
          returns an escaped query string of the form (<field>:<token>).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OR_SEPARATOR

public static final java.lang.String OR_SEPARATOR
Lucene/Solr operator for OR query parts.

See Also:
Constant Field Values

QUERY_WRAPPER_FILTER

public static final java.lang.String QUERY_WRAPPER_FILTER
The query wrapper filter string.

See Also:
Constant Field Values

ESCAPE_CHARS

public static final java.lang.String ESCAPE_CHARS
chars, that if part of a term need to be escaped when searching.

See Also:
Constant Field Values

ESCAPE_CHARS_WS

public static final java.lang.String ESCAPE_CHARS_WS
chars, that if part of a term need to be escaped when searching. including space

See Also:
Constant Field Values
Method Detail

appendFieldQueryPart

public static void appendFieldQueryPart(java.lang.StringBuilder q,
                                        java.lang.String field,
                                        java.util.List<Value> values)
Parameters:
q - the query to add the field query part to.
field - the field name to add the query part for
values - the field value alternatives to match in the search

encodeQuery

public static java.lang.String encodeQuery(java.lang.String query)
                                    throws java.io.UnsupportedEncodingException
Encode a query into application/x-www-form-urlencoded format.

Parameters:
query - the query.
Returns:
the urlencoded query.
Throws:
java.io.UnsupportedEncodingException - UnsupportedEncodingException.

decodeQuery

public static java.lang.String decodeQuery(java.lang.String query)
                                    throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

escapeQuery

public static java.lang.String escapeQuery(java.lang.String query)
Escapes all chars with a special meaning to the lucene query parser. Spaces are not escaped.

Parameters:
query - the query.
Returns:
the query after escaping.
See Also:
ESCAPE_CHARS, toConstQueryOnField(String, String)

escapeQuery

public static java.lang.String escapeQuery(java.lang.String query,
                                           java.lang.String escapeChars)
Escapes the given chars in the given query by prepending '\'.

Parameters:
query - the query, if empty nothing happens and it is returned as is.
escapeChars - the chars to escape
Returns:
the string

responseStatusIsError

public static boolean responseStatusIsError(SolrResponseBase response)
                                     throws SolrServerException
returns true if response indicates an error.

Throws:
SolrServerException
See Also:
http://lucene.472066.n3.nabble.com/Response-status-td490876.html

toSolrQueryFilter

public static java.lang.String toSolrQueryFilter(java.lang.String filter)
Convert a lucene QueryWrapperFilter to a query filter for solr.

Parameters:
filter - the filter.
Returns:
the solr query filter.

toConstQueryOnField

public static java.lang.String toConstQueryOnField(java.lang.String fieldName,
                                                   java.lang.String constant)
creates a query string on the given field for a constant which must be searched "as is", i.e. escaping fo chars and wrapping in quotes

Parameters:
fieldName - must not contain whitespace, but this is not checked!
constant - the constant
Returns:
the lucen query string

toTokenQueryOnField

public static java.lang.String toTokenQueryOnField(java.lang.String fieldName,
                                                   java.lang.String token)
returns an escaped query string of the form (<field>:<token>). The given token is fully escaped, i.e. including spaces.


SMILA 1.0 API documentation