Class SolrQuery

    • Constructor Detail

      • SolrQuery

        public SolrQuery()
      • SolrQuery

        public SolrQuery​(String q)
        Create a new SolrQuery
        Parameters:
        q - query string
    • Method Detail

      • setTerms

        public SolrQuery setTerms​(boolean b)
        enable/disable terms.
        Parameters:
        b - flag to indicate terms should be enabled.
        if b==false, removes all other terms parameters
        Returns:
        Current reference (this)
      • getTerms

        public boolean getTerms()
      • getTermsFields

        public String[] getTermsFields()
      • getTermsLower

        public String getTermsLower()
      • getTermsUpper

        public String getTermsUpper()
      • setTermsUpperInclusive

        public SolrQuery setTermsUpperInclusive​(boolean b)
      • getTermsUpperInclusive

        public boolean getTermsUpperInclusive()
      • setTermsLowerInclusive

        public SolrQuery setTermsLowerInclusive​(boolean b)
      • getTermsLowerInclusive

        public boolean getTermsLowerInclusive()
      • setTermsLimit

        public SolrQuery setTermsLimit​(int limit)
      • getTermsLimit

        public int getTermsLimit()
      • setTermsMinCount

        public SolrQuery setTermsMinCount​(int cnt)
      • getTermsMinCount

        public int getTermsMinCount()
      • setTermsMaxCount

        public SolrQuery setTermsMaxCount​(int cnt)
      • getTermsMaxCount

        public int getTermsMaxCount()
      • getTermsPrefix

        public String getTermsPrefix()
      • setTermsRaw

        public SolrQuery setTermsRaw​(boolean b)
      • getTermsRaw

        public boolean getTermsRaw()
      • setTermsSortString

        public SolrQuery setTermsSortString​(String type)
      • getTermsSortString

        public String getTermsSortString()
      • getTermsRegex

        public String getTermsRegex()
      • getTermsRegexFlags

        public String[] getTermsRegexFlags()
      • addFacetField

        public SolrQuery addFacetField​(String... fields)
        Add field(s) for facet computation.
        Parameters:
        fields - Array of field names from the IndexSchema
        Returns:
        this
      • addFacetPivotField

        public SolrQuery addFacetPivotField​(String... fields)
        Add field(s) for pivot computation. pivot fields are comma separated
        Parameters:
        fields - Array of field names from the IndexSchema
        Returns:
        this
      • addNumericRangeFacet

        public SolrQuery addNumericRangeFacet​(String field,
                                              Number start,
                                              Number end,
                                              Number gap)
        Add a numeric range facet.
        Parameters:
        field - The field
        start - The start of range
        end - The end of the range
        gap - The gap between each count
        Returns:
        this
      • addDateRangeFacet

        public SolrQuery addDateRangeFacet​(String field,
                                           Date start,
                                           Date end,
                                           String gap)
        Add a numeric range facet.
        Parameters:
        field - The field
        start - The start of range
        end - The end of the range
        gap - The gap between each count
        Returns:
        this
      • addIntervalFacets

        public SolrQuery addIntervalFacets​(String field,
                                           String[] intervals)
        Add Interval Faceting on a field. All intervals for the same field should be included in the same call to this method. For syntax documentation see Solr wiki.
        Key substitution, filter exclusions or other local params on the field are not supported when using this method, if this is needed, use the lower level ModifiableSolrParams.add(java.lang.String, java.lang.String...) method.
        Key substitution IS supported on intervals when using this method.
        Parameters:
        field - the field to add facet intervals. Must be an existing field and can't be null
        intervals - Intervals to be used for faceting. It can be an empty array, but it can't be null
        Returns:
        this
      • removeIntervalFacets

        public String[] removeIntervalFacets​(String field)
        Remove all Interval Facets on a field
        Parameters:
        field - the field to remove from facet intervals
        Returns:
        Array of current intervals for field
      • getFacetFields

        public String[] getFacetFields()
        get the facet fields
        Returns:
        string array of facet fields or null if not set/empty
      • removeFacetField

        public boolean removeFacetField​(String name)
        remove a facet field
        Parameters:
        name - Name of the facet field to be removed.
        Returns:
        true, if the item was removed.
        false, if the facet field was null or did not exist.
      • setFacet

        public SolrQuery setFacet​(boolean b)
        enable/disable faceting.
        Parameters:
        b - flag to indicate faceting should be enabled.
        if b==false, removes all other faceting parameters
        Returns:
        Current reference (this)
      • addFacetQuery

        public SolrQuery addFacetQuery​(String f)
        add a faceting query
        Parameters:
        f - facet query
      • getFacetQuery

        public String[] getFacetQuery()
        get facet queries
        Returns:
        all facet queries or null if not set/empty
      • removeFacetQuery

        public boolean removeFacetQuery​(String q)
        remove a facet query
        Parameters:
        q - the facet query to remove
        Returns:
        true if the facet query was removed false otherwise
      • setFacetLimit

        public SolrQuery setFacetLimit​(int lim)
        set the facet limit
        Parameters:
        lim - number facet items to return
      • getFacetLimit

        public int getFacetLimit()
        get current facet limit
        Returns:
        facet limit or default of 25
      • setFacetMinCount

        public SolrQuery setFacetMinCount​(int cnt)
        set facet minimum count
        Parameters:
        cnt - facets having less that cnt hits will be excluded from teh facet list
      • getFacetMinCount

        public int getFacetMinCount()
        get facet minimum count
        Returns:
        facet minimum count or default of 1
      • setFacetSort

        public SolrQuery setFacetSort​(String sort)
        set facet sort
        Parameters:
        sort - sort facets
        Returns:
        this
      • addHighlightField

        public SolrQuery addHighlightField​(String f)
        add highlight field
        Parameters:
        f - field to enable for highlighting
      • removeHighlightField

        public boolean removeHighlightField​(String f)
        remove a field for highlighting
        Parameters:
        f - field name to not highlight
        Returns:
        true, if removed,
        false, otherwise
      • getHighlightFields

        public String[] getHighlightFields()
        get list of highlighted fields
        Returns:
        Array of highlight fields or null if not set/empty
      • setHighlightSnippets

        public SolrQuery setHighlightSnippets​(int num)
      • getHighlightSnippets

        public int getHighlightSnippets()
      • setHighlightFragsize

        public SolrQuery setHighlightFragsize​(int num)
      • getHighlightFragsize

        public int getHighlightFragsize()
      • setHighlightRequireFieldMatch

        public SolrQuery setHighlightRequireFieldMatch​(boolean flag)
      • getHighlightRequireFieldMatch

        public boolean getHighlightRequireFieldMatch()
      • setHighlightSimplePre

        public SolrQuery setHighlightSimplePre​(String f)
      • getHighlightSimplePre

        public String getHighlightSimplePre()
      • setHighlightSimplePost

        public SolrQuery setHighlightSimplePost​(String f)
      • getHighlightSimplePost

        public String getHighlightSimplePost()
      • clearSorts

        public SolrQuery clearSorts()
        Clears current sort information.
        Returns:
        the modified SolrQuery object, for easy chaining
        Since:
        4.2
      • setSorts

        public SolrQuery setSorts​(List<SolrQuery.SortClause> value)
        Replaces the current sort information.
        Returns:
        the modified SolrQuery object, for easy chaining
        Since:
        4.2
      • getSorts

        public List<SolrQuery.SortClause> getSorts()
        Gets an a list of current sort clauses.
        Returns:
        an immutable list of current sort clauses
        Since:
        4.2
      • setSort

        public SolrQuery setSort​(String field,
                                 SolrQuery.ORDER order)
        Replaces the current sort information with a single sort clause
        Returns:
        the modified SolrQuery object, for easy chaining
        Since:
        4.2
      • setSort

        public SolrQuery setSort​(SolrQuery.SortClause sortClause)
        Replaces the current sort information with a single sort clause
        Returns:
        the modified SolrQuery object, for easy chaining
        Since:
        4.2
      • addSort

        public SolrQuery addSort​(String field,
                                 SolrQuery.ORDER order)
        Adds a single sort clause to the end of the current sort information.
        Returns:
        the modified SolrQuery object, for easy chaining
        Since:
        4.2
      • addSort

        public SolrQuery addSort​(SolrQuery.SortClause sortClause)
        Adds a single sort clause to the end of the query.
        Returns:
        the modified SolrQuery object, for easy chaining
        Since:
        4.2
      • addOrUpdateSort

        public SolrQuery addOrUpdateSort​(String field,
                                         SolrQuery.ORDER order)
        Updates or adds a single sort clause to the query. If the field is already used for sorting, the order of the existing field is modified; otherwise, it is added to the end.

        Returns:
        the modified SolrQuery object, for easy chaining
        Since:
        4.2
      • addOrUpdateSort

        public SolrQuery addOrUpdateSort​(SolrQuery.SortClause sortClause)
        Updates or adds a single sort field specification to the current sort information. If the sort field already exist in the sort information map, its position is unchanged and the sort order is set; if it does not exist, it is appended at the end with the specified order..
        Returns:
        the modified SolrQuery object, for easy chaining
        Since:
        4.2
      • removeSort

        public SolrQuery removeSort​(SolrQuery.SortClause sortClause)
        Removes a single sort field from the current sort information.
        Returns:
        the modified SolrQuery object, for easy chaining
        Since:
        4.2
      • removeSort

        public SolrQuery removeSort​(String itemName)
        Removes a single sort field from the current sort information.
        Returns:
        the modified SolrQuery object, for easy chaining
        Since:
        4.2
      • setGetFieldStatistics

        public void setGetFieldStatistics​(boolean v)
      • setGetFieldStatistics

        public void setGetFieldStatistics​(String field)
      • addGetFieldStatistics

        public void addGetFieldStatistics​(String... field)
      • addStatsFieldFacets

        public void addStatsFieldFacets​(String field,
                                        String... facets)
      • addStatsFieldCalcDistinct

        public void addStatsFieldCalcDistinct​(String field,
                                              boolean calcDistinct)
      • removeFilterQuery

        public boolean removeFilterQuery​(String fq)
      • getFilterQueries

        public String[] getFilterQueries()
      • getHighlight

        public boolean getHighlight()
      • setHighlight

        public SolrQuery setHighlight​(boolean b)
      • addMoreLikeThisField

        public SolrQuery addMoreLikeThisField​(String field)
        Add field for MoreLikeThis. Automatically enables MoreLikeThis.
        Parameters:
        field - the names of the field to be added
        Returns:
        this
      • setMoreLikeThisFields

        public SolrQuery setMoreLikeThisFields​(String... fields)
      • getMoreLikeThisFields

        public String[] getMoreLikeThisFields()
        Returns:
        an array with the fields used to compute similarity.
      • setMoreLikeThisMinTermFreq

        public SolrQuery setMoreLikeThisMinTermFreq​(int mintf)
        Sets the frequency below which terms will be ignored in the source doc
        Parameters:
        mintf - the minimum term frequency
        Returns:
        this
      • getMoreLikeThisMinTermFreq

        public int getMoreLikeThisMinTermFreq()
        Gets the frequency below which terms will be ignored in the source doc
      • setMoreLikeThisMinDocFreq

        public SolrQuery setMoreLikeThisMinDocFreq​(int mindf)
        Sets the frequency at which words will be ignored which do not occur in at least this many docs.
        Parameters:
        mindf - the minimum document frequency
        Returns:
        this
      • getMoreLikeThisMinDocFreq

        public int getMoreLikeThisMinDocFreq()
        Gets the frequency at which words will be ignored which do not occur in at least this many docs.
      • setMoreLikeThisMinWordLen

        public SolrQuery setMoreLikeThisMinWordLen​(int minwl)
        Sets the minimum word length below which words will be ignored.
        Parameters:
        minwl - the minimum word length
        Returns:
        this
      • getMoreLikeThisMinWordLen

        public int getMoreLikeThisMinWordLen()
        Gets the minimum word length below which words will be ignored.
      • setMoreLikeThisMaxWordLen

        public SolrQuery setMoreLikeThisMaxWordLen​(int maxwl)
        Sets the maximum word length above which words will be ignored.
        Parameters:
        maxwl - the maximum word length
        Returns:
        this
      • getMoreLikeThisMaxWordLen

        public int getMoreLikeThisMaxWordLen()
        Gets the maximum word length above which words will be ignored.
      • setMoreLikeThisMaxQueryTerms

        public SolrQuery setMoreLikeThisMaxQueryTerms​(int maxqt)
        Sets the maximum number of query terms that will be included in any generated query.
        Parameters:
        maxqt - the maximum number of query terms
        Returns:
        this
      • getMoreLikeThisMaxQueryTerms

        public int getMoreLikeThisMaxQueryTerms()
        Gets the maximum number of query terms that will be included in any generated query.
      • setMoreLikeThisMaxTokensParsed

        public SolrQuery setMoreLikeThisMaxTokensParsed​(int maxntp)
        Sets the maximum number of tokens to parse in each example doc field that is not stored with TermVector support.
        Parameters:
        maxntp - the maximum number of tokens to parse
        Returns:
        this
      • getMoreLikeThisMaxTokensParsed

        public int getMoreLikeThisMaxTokensParsed()
        Gets the maximum number of tokens to parse in each example doc field that is not stored with TermVector support.
      • setMoreLikeThisBoost

        public SolrQuery setMoreLikeThisBoost​(boolean b)
        Sets if the query will be boosted by the interesting term relevance.
        Parameters:
        b - set to true to boost the query with the interesting term relevance
        Returns:
        this
      • getMoreLikeThisBoost

        public boolean getMoreLikeThisBoost()
        Gets if the query will be boosted by the interesting term relevance.
      • setMoreLikeThisQF

        public SolrQuery setMoreLikeThisQF​(String qf)
        Sets the query fields and their boosts using the same format as that used in DisMaxQParserPlugin. These fields must also be added using addMoreLikeThisField(String).
        Parameters:
        qf - the query fields
        Returns:
        this
      • getMoreLikeThisQF

        public String getMoreLikeThisQF()
        Gets the query fields and their boosts.
      • setMoreLikeThisCount

        public SolrQuery setMoreLikeThisCount​(int count)
        Sets the number of similar documents to return for each result.
        Parameters:
        count - the number of similar documents to return for each result
        Returns:
        this
      • getMoreLikeThisCount

        public int getMoreLikeThisCount()
        Gets the number of similar documents to return for each result.
      • setMoreLikeThis

        public SolrQuery setMoreLikeThis​(boolean b)
        Enable/Disable MoreLikeThis. After enabling MoreLikeThis, the fields used for computing similarity must be specified calling addMoreLikeThisField(String).
        Parameters:
        b - flag to indicate if MoreLikeThis should be enabled. if b==false removes all mlt.* parameters
        Returns:
        this
      • getMoreLikeThis

        public boolean getMoreLikeThis()
        Returns:
        true if MoreLikeThis is enabled, false otherwise
      • getFields

        public String getFields()
      • setIncludeScore

        public SolrQuery setIncludeScore​(boolean includeScore)
      • getQuery

        public String getQuery()
      • getRows

        public Integer getRows()
      • setShowDebugInfo

        public SolrQuery setShowDebugInfo​(boolean showDebugInfo)
      • setDistrib

        public void setDistrib​(boolean val)
      • getStart

        public Integer getStart()
      • setRequestHandler

        public SolrQuery setRequestHandler​(String qt)
        The Request Handler to use (see the solrconfig.xml), which is stored in the "qt" parameter. Normally it starts with a '/' and if so it will be used by QueryRequest.getPath() in the URL instead of the "qt" parameter. If this is left blank, then the default of "/select" is assumed.
        Parameters:
        qt - The Request Handler name corresponding to one in solrconfig.xml on the server.
        Returns:
        this
      • getRequestHandler

        public String getRequestHandler()
      • getCopy

        public SolrQuery getCopy()
        get a deep copy of this object
      • setTimeAllowed

        public SolrQuery setTimeAllowed​(Integer milliseconds)
        Set the maximum time allowed for this query. If the query takes more time than the specified milliseconds, a timeout occurs and partial (or no) results may be returned. If given Integer is null, then this parameter is removed from the request
        Parameters:
        milliseconds - the time in milliseconds allowed for this query
      • getTimeAllowed

        public Integer getTimeAllowed()
        Get the maximum time allowed for this query.