Class CmsSolrQuery

java.lang.Object
org.apache.solr.common.params.SolrParams
org.apache.solr.common.params.ModifiableSolrParams
org.apache.solr.client.solrj.SolrQuery
org.opencms.search.solr.CmsSolrQuery
All Implemented Interfaces:
Serializable, Iterable<Map.Entry<String,String[]>>, org.apache.solr.common.MapSerializable, org.apache.solr.common.MapWriter, org.apache.solr.common.NavigableObject, org.noggit.JSONWriter.Writable

public class CmsSolrQuery extends org.apache.solr.client.solrj.SolrQuery
A Solr search query.

See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.apache.solr.client.solrj.SolrQuery

    org.apache.solr.client.solrj.SolrQuery.ORDER, org.apache.solr.client.solrj.SolrQuery.SortClause

    Nested classes/interfaces inherited from interface org.apache.solr.common.MapWriter

    org.apache.solr.common.MapWriter.EntryWriter
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    A constant to add the score field to the result documents.
    static final String
    The default facet date gap.
    static final String
    The default query.
    static final String
    The query type.
    static final Integer
    The default search result count.
    static final String
    A constant to add the score field to the result documents.
    static final String
    A constant to add the score field to the result documents.

    Fields inherited from class org.apache.solr.client.solrj.SolrQuery

    DOCID

    Fields inherited from interface org.apache.solr.common.MapWriter

    EMPTY
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
    CmsSolrQuery(CmsObject cms, Map<String,String[]> queryParams)
    Public constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addFilterQuery(String fieldName, List<String> vals, boolean all, boolean useQuotes)
    Creates and adds a filter query.
    void
    addSortFieldOrders(Map<String,org.apache.solr.client.solrj.SolrQuery.ORDER> sortFields)
    Adds the given fields/orders to the existing sort fields.
     
    void
    Ensures that the initial request parameters will overwrite the member values.
    static String
    Returns the resource type if only one is set as filter query.
    void
    Removes the expiration flag.
    void
    setCategories(String... categories)
    Sets the categories only if not set in the query parameters.
    void
    setCategories(List<String> categories)
    Sets the categories only if not set in the query parameters.
    void
    Sets date ranges.
    void
    setFacetDateGap(String facetDateGap)
    Sets the facetDateGap.
    void
    setGeoFilterQuery(String fieldName, String coordinates, String radius, String units)
    Sets the Geo filter query if not exists.
    void
    setHighlightFields(String... highlightFields)
    Sets the highlightFields.
    void
    setHighlightFields(List<String> highlightFields)
    Sets the highlightFields.
    void
    Sets the locales only if not set in the query parameters.
    void
    setLocales(Locale... locales)
    Sets the locales only if not set in the query parameters.
    org.apache.solr.client.solrj.SolrQuery
     
    void
    setResourceTypes(String... resourceTypes)
    Sets the resource types only if not set in the query parameters.
    void
    setResourceTypes(List<String> resourceTypes)
    Sets the resource types only if not set in the query parameters.
    void
    setReturnFields(String returnFields)
    Sets the requested return fields, but ensures that at least the 'path' and the 'type', 'id' and 'solr_id' are part of the fields returned field list.
    void
    setSearchRoots(String... searchRoots)
    Sets the search roots only if not set as query parameter.
    void
    setSearchRoots(List<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
    Sets the text.
    void
    setTextSearchFields(String... textSearchFields)
    Sets the textSearchFields.
    void
    setTextSearchFields(List<String> textSearchFields)
    Sets the textSearchFields.

    Methods inherited from class org.apache.solr.client.solrj.SolrQuery

    addDateRangeFacet, addFacetField, addFacetPivotField, addFacetQuery, addField, addFilterQuery, addGetFieldStatistics, addHighlightField, addIntervalFacets, addMoreLikeThisField, addNumericRangeFacet, addOrUpdateSort, addOrUpdateSort, addSort, addSort, addStatsFieldCalcDistinct, addStatsFieldFacets, addTermsField, clearSorts, getCopy, getFacetFields, getFacetLimit, getFacetMinCount, getFacetQuery, getFacetSortString, getFields, getFilterQueries, getHighlight, getHighlightFields, getHighlightFragsize, getHighlightRequireFieldMatch, getHighlightSimplePost, getHighlightSimplePre, getHighlightSnippets, getMoreLikeThis, getMoreLikeThisBoost, getMoreLikeThisCount, getMoreLikeThisFields, getMoreLikeThisMaxQueryTerms, getMoreLikeThisMaxTokensParsed, getMoreLikeThisMaxWordLen, getMoreLikeThisMinDocFreq, getMoreLikeThisMinTermFreq, getMoreLikeThisMinWordLen, getMoreLikeThisQF, getQuery, getRequestHandler, getRows, getSortField, getSorts, getStart, getTerms, getTermsFields, getTermsLimit, getTermsLower, getTermsLowerInclusive, getTermsMaxCount, getTermsMinCount, getTermsPrefix, getTermsRaw, getTermsRegex, getTermsRegexFlags, getTermsSortString, getTermsUpper, getTermsUpperInclusive, getTimeAllowed, removeFacetField, removeFacetQuery, removeFilterQuery, removeHighlightField, removeIntervalFacets, removeSort, removeSort, setDistrib, setFacet, setFacetLimit, setFacetMinCount, setFacetMissing, setFacetPrefix, setFacetPrefix, setFacetSort, setFields, setFilterQueries, setGetFieldStatistics, setGetFieldStatistics, setHighlight, setHighlightFragsize, setHighlightRequireFieldMatch, setHighlightSimplePost, setHighlightSimplePre, setHighlightSnippets, setIncludeScore, setMoreLikeThis, setMoreLikeThisBoost, setMoreLikeThisCount, setMoreLikeThisFields, setMoreLikeThisMaxQueryTerms, setMoreLikeThisMaxTokensParsed, setMoreLikeThisMaxWordLen, setMoreLikeThisMinDocFreq, setMoreLikeThisMinTermFreq, setMoreLikeThisMinWordLen, setMoreLikeThisQF, setParam, setParam, setQuery, setRows, setShowDebugInfo, setSort, setSort, setSorts, 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, getMap, getParameterNames, getParameterNamesIterator, getParams, iterator, of, remove, remove, set, set, set, setNonNull, setShardAttributesToParams, size

    Methods inherited from class org.apache.solr.common.params.SolrParams

    fpname, get, getAll, getAll, getBool, getBool, getDouble, getDouble, getFieldBool, getFieldBool, getFieldDouble, getFieldDouble, getFieldFloat, getFieldFloat, getFieldInt, getFieldInt, getFieldParam, getFieldParam, getFieldParams, getFloat, getFloat, getInt, getInt, getLong, getLong, getPrimitiveBool, getPrimitiveFieldBool, getPrimitiveFieldFloat, getPrimitiveInt, required, stream, toFilteredSolrParams, toLocalParamsString, toMap, toMultiMap, toNamedList, toQueryString, toSolrParams, toString, wrapAppended, wrapDefaults, writeMap

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface org.apache.solr.common.MapWriter

    append, jsonStr, toMap, write

    Methods inherited from interface org.apache.solr.common.NavigableObject

    _forEachEntry, _forEachEntry, _forEachEntry, _get, _get, _getStr, _getStr, _size
  • Field Details

  • Constructor Details

    • CmsSolrQuery

      public CmsSolrQuery()
      Default constructor.

    • CmsSolrQuery

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

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

    • getResourceType

      public static String getResourceType(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(String fieldName, List<String> vals, boolean all, boolean useQuotes)
      Creates and adds a filter query.

      Parameters:
      fieldName - the field name to create a filter query on
      vals - the values that should match for the given field
      all - true to combine the given values with 'AND', false for 'OR'
      useQuotes - true to surround the given values with double quotes, false otherwise
    • addSortFieldOrders

      public void addSortFieldOrders(Map<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
    • clone

      public CmsSolrQuery clone()
      Overrides:
      clone in class Object
      See Also:
    • ensureParameters

      public void ensureParameters()
      Ensures that the initial request parameters will overwrite the member values.

      You can initialize the query with an HTTP request parameter then make some method calls and finally re-ensure that the initial request parameters will overwrite the changes made in the meanwhile.

    • removeExpiration

      public void removeExpiration()
      Removes the expiration flag.
    • setCategories

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

      Parameters:
      categories - the categories to set
    • setCategories

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

      Parameters:
      categories - the categories to set
    • setDateRanges

      public void setDateRanges(Map<String,CmsPair<Date,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:

      • keys: Solr field name CmsSearchField and
      • values: pairs with min date as first and max date as second CmsPair
      Alternatively you can use Solr standard query syntax like:

      • +created:[* TO NOW]
      • +lastmodified:[' + date + ' TO NOW]
      whereby date is Solr formatted: CmsSearchUtil.getDateAsIso8601(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(String facetDateGap)
      Sets the facetDateGap.

      Parameters:
      facetDateGap - the facetDateGap to set
    • setGeoFilterQuery

      public void setGeoFilterQuery(String fieldName, String coordinates, String radius, String units)
      Sets the Geo filter query if not exists.
      Parameters:
      fieldName - the field name storing the coordinates
      coordinates - the coordinates string as a lat,lng pair
      radius - the radius
      units - the units of the search radius
    • setHighlightFields

      public void setHighlightFields(List<String> highlightFields)
      Sets the highlightFields.

      Parameters:
      highlightFields - the highlightFields to set
    • setHighlightFields

      public void setHighlightFields(String... highlightFields)
      Sets the highlightFields.

      Parameters:
      highlightFields - the highlightFields to set
    • setLocales

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

      Parameters:
      locales - the locales to set
    • setLocales

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

      Parameters:
      locales - the locales to set
    • setRequestHandler

      public org.apache.solr.client.solrj.SolrQuery setRequestHandler(String qt)
      Overrides:
      setRequestHandler in class org.apache.solr.client.solrj.SolrQuery
      See Also:
      • SolrQuery.setRequestHandler(java.lang.String)
    • setResourceTypes

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

      Parameters:
      resourceTypes - the resourceTypes to set
    • setResourceTypes

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

      Parameters:
      resourceTypes - the resourceTypes to set
    • setReturnFields

      public void setReturnFields(String returnFields)
      Sets the requested return fields, but ensures that at least the 'path' and the 'type', 'id' and 'solr_id' are part of the fields returned field list.

      Parameters:
      returnFields - the really requested return fields.
      See Also:
      • CommonParams.FL
    • setSearchRoots

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

      Parameters:
      searchRoots - the searchRoots to set
    • setSearchRoots

      public void setSearchRoots(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(String text)
      Sets the text.

      Parameters:
      text - the text to set
    • setTextSearchFields

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

      Parameters:
      textSearchFields - the textSearchFields to set
    • setTextSearchFields

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

      Parameters:
      textSearchFields - the textSearchFields to set