org.opencms.search.solr
Class CmsSolrQuery

java.lang.Object
  extended by org.apache.solr.common.params.SolrParams
      extended by org.apache.solr.common.params.ModifiableSolrParams
          extended by org.apache.solr.client.solrj.SolrQuery
              extended by org.opencms.search.solr.CmsSolrQuery
All Implemented Interfaces:
java.io.Serializable

public class CmsSolrQuery
extends org.apache.solr.client.solrj.SolrQuery

A Solr search query.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.solr.client.solrj.SolrQuery
org.apache.solr.client.solrj.SolrQuery.ORDER
 
Field Summary
static java.lang.String ALL_RETURN_FIELDS
          A constant to add the score field to the result documents.
static java.lang.String DEFAULT_FACET_DATE_GAP
          The default facet date gap.
static java.lang.String DEFAULT_QUERY
          The default query.
static java.lang.String DEFAULT_QUERY_TYPE
          The query type.
static java.lang.Integer DEFAULT_ROWS
          The default search result count.
static java.lang.String MINIMUM_FIELDS
          A constant to add the score field to the result documents.
static java.lang.String STRUCTURE_FIELDS
          A constant to add the score field to the result documents.
 
Constructor Summary
CmsSolrQuery()
          Default constructor.
CmsSolrQuery(CmsObject cms, java.util.Map<java.lang.String,java.lang.String[]> queryParams)
          Public constructor.
 
Method Summary
 void addFilterQuery(java.lang.String fieldName, boolean all, java.util.List<java.lang.String> vals)
          Adds a filter query.
 void addSortFieldOrders(java.util.Map<java.lang.String,org.apache.solr.client.solrj.SolrQuery.ORDER> sortFields)
          Adds the given fields/orders to the existing sort fields.
protected  CmsSolrQuery clone()
           
static java.lang.String getResourceType(java.lang.String[] fqs)
          Returns the resource type if only one is set as filter query.
 void setCategories(java.util.List<java.lang.String> categories)
          Sets the categories only if not set in the query parameters.
 void setCategories(java.lang.String... categories)
          Sets the categories only if not set in the query parameters.
 void setDateRanges(java.util.Map<java.lang.String,CmsPair<java.util.Date,java.util.Date>> dateRanges)
          Sets date ranges.
 void setFacetDateGap(java.lang.String facetDateGap)
          Sets the facetDateGap.
 void setLocales(java.util.List<java.util.Locale> locales)
          Sets the locales only if not set in the query parameters.
 void setLocales(java.util.Locale... locales)
          Sets the locales only if not set in the query parameters.
 void setResourceTypes(java.util.List<java.lang.String> resourceTypes)
          Sets the resource types only if not set in the query parameters.
 void setResourceTypes(java.lang.String... resourceTypes)
          Sets the resource types only if not set in the query parameters.
 void setSearchRoots(java.util.List<java.lang.String> searchRoots)
          Sets the search roots only if not set as query parameter.
 void setSearchRoots(java.lang.String... searchRoots)
          Sets the search roots only if not set as query parameter.
 void setStructureQuery(boolean structureQuery)
          Sets the return fields 'fl' to a predefined set that does not contain content specific fields.
 void setText(java.lang.String text)
          Sets the text.
 void setTextSearchFields(java.util.List<java.lang.String> textSearchFields)
          Sets the textSearchFields.
 void setTextSearchFields(java.lang.String... textSearchFields)
          Sets the textSearchFields.
 java.lang.String toString()
           
 
Methods inherited from class org.apache.solr.client.solrj.SolrQuery
addDateRangeFacet, addFacetField, addFacetQuery, addField, addFilterQuery, addHighlightField, addNumericRangeFacet, addSortField, addStatsFieldFacets, addTermsField, getCopy, getFacetFields, getFacetLimit, getFacetMinCount, getFacetQuery, getFacetSort, getFacetSortString, getFields, getFilterQueries, getHighlight, getHighlightFields, getHighlightFragsize, getHighlightRequireFieldMatch, getHighlightSimplePost, getHighlightSimplePre, getHighlightSnippets, getQuery, getQueryType, getRows, getSortField, getSortFields, getStart, getTerms, getTermsFields, getTermsLimit, getTermsLower, getTermsLowerInclusive, getTermsMaxCount, getTermsMinCount, getTermsPrefix, getTermsRaw, getTermsRegex, getTermsRegexFlags, getTermsSortString, getTermsUpper, getTermsUpperInclusive, getTimeAllowed, removeFacetField, removeFacetQuery, removeFilterQuery, removeHighlightField, removeSortField, setFacet, setFacetLimit, setFacetMinCount, setFacetMissing, setFacetPrefix, setFacetPrefix, setFacetSort, setFacetSort, setFields, setFilterQueries, setGetFieldStatistics, setGetFieldStatistics, setHighlight, setHighlightFragsize, setHighlightRequireFieldMatch, setHighlightSimplePost, setHighlightSimplePre, setHighlightSnippets, setIncludeScore, setMissing, setParam, setParam, setQuery, setQueryType, setRows, setShowDebugInfo, setSortField, setStart, setTerms, setTermsLimit, setTermsLower, setTermsLowerInclusive, setTermsMaxCount, setTermsMinCount, setTermsPrefix, setTermsRaw, setTermsRegex, setTermsRegexFlag, setTermsSortString, setTermsUpper, setTermsUpperInclusive, setTimeAllowed
 
Methods inherited from class org.apache.solr.common.params.ModifiableSolrParams
add, add, clear, get, getParameterNames, getParameterNamesIterator, getParams, remove, remove, set, set, set
 
Methods inherited from class org.apache.solr.common.params.SolrParams
fpname, get, getBool, getBool, getDouble, getDouble, getFieldBool, getFieldBool, getFieldDouble, getFieldDouble, getFieldFloat, getFieldFloat, getFieldInt, getFieldInt, getFieldParam, getFieldParam, getFieldParams, getFloat, getFloat, getInt, getInt, parseBool, required, toMap, toMultiMap, toNamedList, toSolrParams, wrapAppended, wrapDefaults
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ALL_RETURN_FIELDS

public static final java.lang.String ALL_RETURN_FIELDS
A constant to add the score field to the result documents.

See Also:
Constant Field Values

DEFAULT_FACET_DATE_GAP

public static final java.lang.String DEFAULT_FACET_DATE_GAP
The default facet date gap.

See Also:
Constant Field Values

DEFAULT_QUERY

public static final java.lang.String DEFAULT_QUERY
The default query.

See Also:
Constant Field Values

DEFAULT_QUERY_TYPE

public static final java.lang.String DEFAULT_QUERY_TYPE
The query type.

See Also:
Constant Field Values

DEFAULT_ROWS

public static final java.lang.Integer DEFAULT_ROWS
The default search result count.


MINIMUM_FIELDS

public static final java.lang.String MINIMUM_FIELDS
A constant to add the score field to the result documents.

See Also:
Constant Field Values

STRUCTURE_FIELDS

public static final java.lang.String STRUCTURE_FIELDS
A constant to add the score field to the result documents.

See Also:
Constant Field Values
Constructor Detail

CmsSolrQuery

public CmsSolrQuery()
Default constructor.


CmsSolrQuery

public CmsSolrQuery(CmsObject cms,
                    java.util.Map<java.lang.String,java.lang.String[]> queryParams)
Public constructor.

Parameters:
cms - the current OpenCms context
queryParams - the Solr query parameters
Method Detail

getResourceType

public static java.lang.String getResourceType(java.lang.String[] fqs)
Returns the resource type if only one is set as filter query.

Parameters:
fqs - the field queries to check
Returns:
the type or null

addFilterQuery

public void addFilterQuery(java.lang.String fieldName,
                           boolean all,
                           java.util.List<java.lang.String> vals)
Adds a filter query.

Parameters:
fieldName - the field name
all - true to combine the given values with 'AND', false for 'OR'
vals - the values

addSortFieldOrders

public void addSortFieldOrders(java.util.Map<java.lang.String,org.apache.solr.client.solrj.SolrQuery.ORDER> sortFields)
Adds the given fields/orders to the existing sort fields.

Parameters:
sortFields - the sortFields to set

setCategories

public void setCategories(java.util.List<java.lang.String> categories)
Sets the categories only if not set in the query parameters.

Parameters:
categories - the categories to set

setCategories

public void setCategories(java.lang.String... categories)
Sets the categories only if not set in the query parameters.

Parameters:
categories - the categories to set

setDateRanges

public void setDateRanges(java.util.Map<java.lang.String,CmsPair<java.util.Date,java.util.Date>> dateRanges)
Sets date ranges.

This call will overwrite all existing date ranges for the given keys (name of the date facet field).

The parameter Map uses as:

Alternatively you can use Solr standard query syntax like:

whereby date is Solr formated: DateField.formatExternal(Date)

Parameters:
dateRanges - the ranges map with field name as key and a CmsPair with min date as first and max date as second

setFacetDateGap

public void setFacetDateGap(java.lang.String facetDateGap)
Sets the facetDateGap.

Parameters:
facetDateGap - the facetDateGap to set

setLocales

public void setLocales(java.util.List<java.util.Locale> locales)
Sets the locales only if not set in the query parameters.

Parameters:
locales - the locales to set

setLocales

public void setLocales(java.util.Locale... locales)
Sets the locales only if not set in the query parameters.

Parameters:
locales - the locales to set

setResourceTypes

public void setResourceTypes(java.util.List<java.lang.String> resourceTypes)
Sets the resource types only if not set in the query parameters.

Parameters:
resourceTypes - the resourceTypes to set

setResourceTypes

public void setResourceTypes(java.lang.String... resourceTypes)
Sets the resource types only if not set in the query parameters.

Parameters:
resourceTypes - the resourceTypes to set

setSearchRoots

public void setSearchRoots(java.util.List<java.lang.String> searchRoots)
Sets the search roots only if not set as query parameter.

Parameters:
searchRoots - the searchRoots to set

setSearchRoots

public void setSearchRoots(java.lang.String... searchRoots)
Sets the search roots only if not set as query parameter.

Parameters:
searchRoots - the searchRoots to set

setStructureQuery

public void setStructureQuery(boolean structureQuery)
Sets the return fields 'fl' to a predefined set that does not contain content specific fields.

Parameters:
structureQuery - the true to return only structural fields

setText

public void setText(java.lang.String text)
Sets the text.

Parameters:
text - the text to set

setTextSearchFields

public void setTextSearchFields(java.util.List<java.lang.String> textSearchFields)
Sets the textSearchFields.

Parameters:
textSearchFields - the textSearchFields to set

setTextSearchFields

public void setTextSearchFields(java.lang.String... textSearchFields)
Sets the textSearchFields.

Parameters:
textSearchFields - the textSearchFields to set

toString

public java.lang.String toString()
Overrides:
toString in class org.apache.solr.common.params.ModifiableSolrParams
See Also:
ModifiableSolrParams.toString()

clone

protected CmsSolrQuery clone()
Overrides:
clone in class java.lang.Object
See Also:
Object.clone()