org.apache.solr.client.solrj
Class SolrQuery

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
All Implemented Interfaces:
Serializable

public class SolrQuery
extends ModifiableSolrParams

This is an augmented SolrParams with get/set/add fields for common fields used in the Standard and Dismax request handlers

Since:
solr 1.3
See Also:
Serialized Form

Nested Class Summary
static class SolrQuery.ORDER
           
static class SolrQuery.SortClause
          A single sort clause, encapsulating what to sort and the sort order.
 
Field Summary
static String DOCID
           
 
Constructor Summary
SolrQuery()
           
SolrQuery(String q)
          Create a new SolrQuery
 
Method Summary
 SolrQuery addDateRangeFacet(String field, Date start, Date end, String gap)
          Add a numeric range facet.
 SolrQuery addFacetField(String... fields)
          Add field(s) for facet computation.
 SolrQuery addFacetPivotField(String... fields)
          Add field(s) for pivot computation.
 SolrQuery addFacetQuery(String f)
          add a faceting query
 SolrQuery addField(String field)
           
 SolrQuery addFilterQuery(String... fq)
           
 SolrQuery addHighlightField(String f)
          add highlight field
 SolrQuery addNumericRangeFacet(String field, Number start, Number end, Number gap)
          Add a numeric range facet.
 SolrQuery addOrUpdateSort(SolrQuery.SortClause sortClause)
          Updates or adds a single sort field specification to the current sort information.
 SolrQuery addOrUpdateSort(String field, SolrQuery.ORDER order)
          Updates or adds a single sort clause to the query.
 SolrQuery addSort(SolrQuery.SortClause sortClause)
          Adds a single sort clause to the end of the query.
 SolrQuery addSort(String field, SolrQuery.ORDER order)
          Adds a single sort clause to the end of the current sort information.
 SolrQuery addSortField(String field, SolrQuery.ORDER order)
          Deprecated. Use addSort(SortClause) instead, which is part of an api handling a wider range of sort specifications.
 void addStatsFieldCalcDistinct(String field, boolean calcDistinct)
           
 void addStatsFieldFacets(String field, String... facets)
           
 SolrQuery addTermsField(String field)
           
 SolrQuery clearSorts()
          Clears current sort information.
 SolrQuery getCopy()
          get a deep copy of this object
 String[] getFacetFields()
          get the facet fields
 int getFacetLimit()
          get current facet limit
 int getFacetMinCount()
          get facet minimum count
 String[] getFacetQuery()
          get facet queries
 boolean getFacetSort()
          Deprecated. Use getFacetSortString() instead.
 String getFacetSortString()
          get facet sort
 String getFields()
           
 String[] getFilterQueries()
           
 boolean getHighlight()
           
 String[] getHighlightFields()
          get list of highlighted fields
 int getHighlightFragsize()
           
 boolean getHighlightRequireFieldMatch()
           
 String getHighlightSimplePost()
           
 String getHighlightSimplePre()
           
 int getHighlightSnippets()
           
 String getQuery()
           
 String getQueryType()
          Deprecated. See getRequestHandler().
 String getRequestHandler()
           
 Integer getRows()
           
 String getSortField()
          Gets the raw sort field, as it will be sent to Solr.
 String[] getSortFields()
          Deprecated. Use getSorts() instead, which is part of an api handling a wider range of sort specifications.
 List<SolrQuery.SortClause> getSorts()
          Gets an a list of current sort clauses.
 Integer getStart()
           
 boolean getTerms()
           
 String[] getTermsFields()
           
 int getTermsLimit()
           
 String getTermsLower()
           
 boolean getTermsLowerInclusive()
           
 int getTermsMaxCount()
           
 int getTermsMinCount()
           
 String getTermsPrefix()
           
 boolean getTermsRaw()
           
 String getTermsRegex()
           
 String[] getTermsRegexFlags()
           
 String getTermsSortString()
           
 String getTermsUpper()
           
 boolean getTermsUpperInclusive()
           
 Integer getTimeAllowed()
          Get the maximum time allowed for this query.
 boolean removeFacetField(String name)
          remove a facet field
 boolean removeFacetQuery(String q)
          remove a facet query
 boolean removeFilterQuery(String fq)
           
 boolean removeHighlightField(String f)
          remove a field for highlighting
 SolrQuery removeSort(SolrQuery.SortClause sortClause)
          Removes a single sort field from the current sort information.
 SolrQuery removeSort(String itemName)
          Removes a single sort field from the current sort information.
 SolrQuery removeSortField(String field, SolrQuery.ORDER order)
          Deprecated. Use removeSort(SortClause) instead, which is part of an api handling a wider range of sort specifications.
 void setDistrib(boolean val)
           
 SolrQuery setFacet(boolean b)
          enable/disable faceting.
 SolrQuery setFacetLimit(int lim)
          set the facet limit
 SolrQuery setFacetMinCount(int cnt)
          set facet minimum count
 SolrQuery setFacetMissing(Boolean v)
          Sets facet missing boolean flag
 SolrQuery setFacetPrefix(String prefix)
           
 SolrQuery setFacetPrefix(String field, String prefix)
           
 SolrQuery setFacetSort(boolean sort)
          Deprecated. Use setFacetSort(String) instead, true corresponds to FacetParams.FACET_SORT_COUNT and false to FacetParams.FACET_SORT_INDEX.
 SolrQuery setFacetSort(String sort)
          set facet sort
 SolrQuery setFields(String... fields)
           
 SolrQuery setFilterQueries(String... fq)
           
 void setGetFieldStatistics(boolean v)
           
 void setGetFieldStatistics(String field)
           
 SolrQuery setHighlight(boolean b)
           
 SolrQuery setHighlightFragsize(int num)
           
 SolrQuery setHighlightRequireFieldMatch(boolean flag)
           
 SolrQuery setHighlightSimplePost(String f)
           
 SolrQuery setHighlightSimplePre(String f)
           
 SolrQuery setHighlightSnippets(int num)
           
 SolrQuery setIncludeScore(boolean includeScore)
           
 SolrQuery setMissing(String fld)
          Deprecated. use setFacetMissing(Boolean)
 SolrQuery setParam(String name, boolean value)
           
 SolrQuery setParam(String name, String... values)
           
 SolrQuery setQuery(String query)
           
 SolrQuery setQueryType(String qt)
          Deprecated. See setRequestHandler(String).
 SolrQuery setRequestHandler(String qt)
          The Request Handler to use (see the solrconfig.xml), which is stored in the "qt" parameter.
 SolrQuery setRows(Integer rows)
           
 void setShowDebugInfo(boolean showDebugInfo)
           
 SolrQuery setSort(SolrQuery.SortClause sortClause)
          Replaces the current sort information with a single sort clause
 SolrQuery setSort(String field, SolrQuery.ORDER order)
          Replaces the current sort information with a single sort clause
 SolrQuery setSortField(String field, SolrQuery.ORDER order)
          Deprecated. Use setSort(SortClause) instead, which is part of an api handling a wider range of sort specifications.
 SolrQuery setSorts(List<SolrQuery.SortClause> value)
          Replaces the current sort information.
 SolrQuery setStart(Integer start)
           
 SolrQuery setTerms(boolean b)
          enable/disable terms.
 SolrQuery setTermsLimit(int limit)
           
 SolrQuery setTermsLower(String lower)
           
 SolrQuery setTermsLowerInclusive(boolean b)
           
 SolrQuery setTermsMaxCount(int cnt)
           
 SolrQuery setTermsMinCount(int cnt)
           
 SolrQuery setTermsPrefix(String prefix)
           
 SolrQuery setTermsRaw(boolean b)
           
 SolrQuery setTermsRegex(String regex)
           
 SolrQuery setTermsRegexFlag(String flag)
           
 SolrQuery setTermsSortString(String type)
           
 SolrQuery setTermsUpper(String upper)
           
 SolrQuery setTermsUpperInclusive(boolean b)
           
 SolrQuery setTimeAllowed(Integer milliseconds)
          Set the maximum time allowed for this query.
 
Methods inherited from class org.apache.solr.common.params.ModifiableSolrParams
add, add, clear, get, getParameterNames, getParameterNamesIterator, getParams, remove, remove, set, set, set, toString
 
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, required, toFilteredSolrParams, toMap, toMultiMap, toNamedList, toSolrParams, wrapAppended, wrapDefaults
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DOCID

public static final String DOCID
See Also:
Constant Field Values
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()

addTermsField

public SolrQuery addTermsField(String field)

getTermsFields

public String[] getTermsFields()

setTermsLower

public SolrQuery setTermsLower(String lower)

getTermsLower

public String getTermsLower()

setTermsUpper

public SolrQuery setTermsUpper(String upper)

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()

setTermsPrefix

public SolrQuery setTermsPrefix(String prefix)

getTermsPrefix

public String getTermsPrefix()

setTermsRaw

public SolrQuery setTermsRaw(boolean b)

getTermsRaw

public boolean getTermsRaw()

setTermsSortString

public SolrQuery setTermsSortString(String type)

getTermsSortString

public String getTermsSortString()

setTermsRegex

public SolrQuery setTermsRegex(String regex)

getTermsRegex

public String getTermsRegex()

setTermsRegexFlag

public SolrQuery setTermsRegexFlag(String flag)

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

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)

setFacetPrefix

public SolrQuery setFacetPrefix(String prefix)

setFacetPrefix

public SolrQuery setFacetPrefix(String field,
                                String prefix)

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

setFacetMissing

public SolrQuery setFacetMissing(Boolean v)
Sets facet missing boolean flag

Parameters:
v - flag to indicate the field of FacetParams.FACET_MISSING .
Returns:
this

setMissing

@Deprecated
public SolrQuery setMissing(String fld)
Deprecated. use setFacetMissing(Boolean)


getFacetSortString

public String getFacetSortString()
get facet sort

Returns:
facet sort or default of FacetParams.FACET_SORT_COUNT

getFacetSort

@Deprecated
public boolean getFacetSort()
Deprecated. Use getFacetSortString() instead.

get facet sort

Returns:
facet sort or default of true.
true corresponds to FacetParams.FACET_SORT_COUNT and
false to FacetParams.FACET_SORT_INDEX

setFacetSort

public SolrQuery setFacetSort(String sort)
set facet sort

Parameters:
sort - sort facets
Returns:
this

setFacetSort

@Deprecated
public SolrQuery setFacetSort(boolean sort)
Deprecated. Use setFacetSort(String) instead, true corresponds to FacetParams.FACET_SORT_COUNT and false to FacetParams.FACET_SORT_INDEX.

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()

setSortField

@Deprecated
public SolrQuery setSortField(String field,
                                         SolrQuery.ORDER order)
Deprecated. Use setSort(SortClause) instead, which is part of an api handling a wider range of sort specifications.

Replaces the sort string with a single sort field.


addSortField

@Deprecated
public SolrQuery addSortField(String field,
                                         SolrQuery.ORDER order)
Deprecated. Use addSort(SortClause) instead, which is part of an api handling a wider range of sort specifications.

Adds a sort field to the end of the sort string.


removeSortField

@Deprecated
public SolrQuery removeSortField(String field,
                                            SolrQuery.ORDER order)
Deprecated. Use removeSort(SortClause) instead, which is part of an api handling a wider range of sort specifications.

Removes a sort field to the end of the sort string.


getSortFields

@Deprecated
public String[] getSortFields()
Deprecated. Use getSorts() instead, which is part of an api handling a wider range of sort specifications.

Gets an array of sort specifications.


getSortField

public String getSortField()
Gets the raw sort field, as it will be sent to Solr.

The returned sort field will always contain a serialized version of the sort string built using setSort(SortClause), addSort(SortClause), addOrUpdateSort(SortClause), removeSort(SortClause), clearSorts() and setSorts(List).


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, it's 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)

addStatsFieldFacets

public void addStatsFieldFacets(String field,
                                String... facets)

addStatsFieldCalcDistinct

public void addStatsFieldCalcDistinct(String field,
                                      boolean calcDistinct)

setFilterQueries

public SolrQuery setFilterQueries(String... fq)

addFilterQuery

public SolrQuery addFilterQuery(String... fq)

removeFilterQuery

public boolean removeFilterQuery(String fq)

getFilterQueries

public String[] getFilterQueries()

getHighlight

public boolean getHighlight()

setHighlight

public SolrQuery setHighlight(boolean b)

setFields

public SolrQuery setFields(String... fields)

addField

public SolrQuery addField(String field)

getFields

public String getFields()

setIncludeScore

public SolrQuery setIncludeScore(boolean includeScore)

setQuery

public SolrQuery setQuery(String query)

getQuery

public String getQuery()

setRows

public SolrQuery setRows(Integer rows)

getRows

public Integer getRows()

setShowDebugInfo

public void setShowDebugInfo(boolean showDebugInfo)

setDistrib

public void setDistrib(boolean val)

setStart

public SolrQuery setStart(Integer start)

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()

setQueryType

@Deprecated
public SolrQuery setQueryType(String qt)
Deprecated. See setRequestHandler(String).


getQueryType

@Deprecated
public String getQueryType()
Deprecated. See getRequestHandler().


setParam

public SolrQuery setParam(String name,
                          String... values)
Returns:
this
See Also:
ModifiableSolrParams.set(String,String[])

setParam

public SolrQuery setParam(String name,
                          boolean value)
Returns:
this
See Also:
ModifiableSolrParams.set(String, boolean)

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.



Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.