Class SolrQuery
java.lang.Object
org.apache.solr.common.params.SolrParams
org.apache.solr.common.params.ModifiableSolrParams
org.apache.solr.client.solrj.request.SolrQuery
- All Implemented Interfaces:
Serializable,Iterable<Map.Entry<String,,String[]>> MapSerializable,MapWriter,NavigableObject,org.noggit.JSONWriter.Writable
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic classA single sort clause, encapsulating what to sort and the sort order.Nested classes/interfaces inherited from interface org.apache.solr.common.MapWriter
MapWriter.EntryWriter -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddDateRangeFacet(String field, Date start, Date end, String gap) Add a numeric range facet.addFacetField(String... fields) Add field(s) for facet computation.addFacetPivotField(String... fields) Add field(s) for pivot computation.add a faceting queryaddFilterQuery(String... fq) voidaddGetFieldStatistics(String... field) add highlight fieldaddIntervalFacets(String field, String[] intervals) Add Interval Faceting on a field.addMoreLikeThisField(String field) Add field for MoreLikeThis.addNumericRangeFacet(String field, Number start, Number end, Number gap) Add a numeric range facet.addOrUpdateSort(String field, SolrQuery.ORDER order) Updates or adds a single sort clause to the query.addOrUpdateSort(SolrQuery.SortClause sortClause) Updates or adds a single sort field specification to the current sort information.addSort(String field, SolrQuery.ORDER order) Adds a single sort clause to the end of the current sort information.addSort(SolrQuery.SortClause sortClause) Adds a single sort clause to the end of the query.voidaddStatsFieldCalcDistinct(String field, boolean calcDistinct) voidaddStatsFieldFacets(String field, String... facets) addTermsField(String field) Clears current sort information.getCopy()get a deep copy of this object *Get the maximum time allowed for this query.String[]get the facet fieldsintget current facet limitintget facet minimum countString[]get facet queriesget facet sortString[]booleanString[]get list of highlighted fieldsintbooleanintbooleanbooleanGets if the query will be boosted by the interesting term relevance.intGets the number of similar documents to return for each result.String[]intGets the maximum number of query terms that will be included in any generated query.intGets the maximum number of tokens to parse in each example doc field that is not stored with TermVector support.intGets the maximum word length above which words will be ignored.intGets the frequency at which words will be ignored which do not occur in at least this many docs.intGets the frequency below which terms will be ignored in the source docintGets the minimum word length below which words will be ignored.Gets the query fields and their boosts.getQuery()Deprecated.getRows()Gets the raw sort field, as it will be sent to Solr.getSorts()Gets a list of current sort clauses.getStart()booleangetTerms()String[]intbooleanintintbooleanString[]booleanGet the maximum time allowed for this query.booleanremoveFacetField(String name) remove a facet fieldbooleanremove a facet querybooleanbooleanremove a field for highlightingString[]removeIntervalFacets(String field) Remove all Interval Facets on a fieldremoveSort(String itemName) Removes a single sort field from the current sort information.removeSort(SolrQuery.SortClause sortClause) Removes a single sort field from the current sort information.setCpuAllowed(Integer milliseconds) Set the maximum CPU time allowed for this query.voidsetDistrib(boolean val) setFacet(boolean b) enable/disable faceting.setFacetLimit(int lim) set the facet limitsetFacetMinCount(int cnt) set facet minimum countSets facet missing boolean flagsetFacetPrefix(String prefix) setFacetPrefix(String field, String prefix) setFacetSort(String sort) set facet sortsetFilterQueries(String... fq) voidsetGetFieldStatistics(boolean v) voidsetGetFieldStatistics(String field) setHighlight(boolean b) setHighlightFragsize(int num) setHighlightRequireFieldMatch(boolean flag) setHighlightSnippets(int num) setIncludeScore(boolean includeScore) setMoreLikeThis(boolean b) Enable/Disable MoreLikeThis.setMoreLikeThisBoost(boolean b) Sets if the query will be boosted by the interesting term relevance.setMoreLikeThisCount(int count) Sets the number of similar documents to return for each result.setMoreLikeThisFields(String... fields) setMoreLikeThisMaxQueryTerms(int maxqt) Sets the maximum number of query terms that will be included in any generated query.setMoreLikeThisMaxTokensParsed(int maxntp) Sets the maximum number of tokens to parse in each example doc field that is not stored with TermVector support.setMoreLikeThisMaxWordLen(int maxwl) Sets the maximum word length above which words will be ignored.setMoreLikeThisMinDocFreq(int mindf) Sets the frequency at which words will be ignored which do not occur in at least this many docs.setMoreLikeThisMinTermFreq(int mintf) Sets the frequency below which terms will be ignored in the source docsetMoreLikeThisMinWordLen(int minwl) Sets the minimum word length below which words will be ignored.Sets the query fields and their boosts using the same format as that used in DisMaxQParserPlugin.Deprecated.setShowDebugInfo(boolean showDebugInfo) setSort(String field, SolrQuery.ORDER order) Replaces the current sort information with a single sort clausesetSort(SolrQuery.SortClause sortClause) Replaces the current sort information with a single sort clausesetSorts(List<SolrQuery.SortClause> value) Replaces the current sort information.setTerms(boolean b) enable/disable terms.setTermsLimit(int limit) setTermsLower(String lower) setTermsLowerInclusive(boolean b) setTermsMaxCount(int cnt) setTermsMinCount(int cnt) setTermsPrefix(String prefix) setTermsRaw(boolean b) setTermsRegex(String regex) setTermsRegexFlag(String flag) setTermsSortString(String type) setTermsUpper(String upper) setTermsUpperInclusive(boolean b) 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, getMap, getParameterNames, getParameterNamesIterator, getParams, iterator, of, remove, remove, set, set, set, setNonNull, sizeMethods inherited from class org.apache.solr.common.params.SolrParams
equals, fpname, get, 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, hashCode, of, of, required, stream, toLocalParamsString, toNamedList, toQueryString, toString, wrapAppended, wrapDefaults, writeMapMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface org.apache.solr.common.NavigableObject
_forEachEntry, _forEachEntry, _forEachEntry, _get, _get, _getStr, _getStr, _size
-
Field Details
-
DOCID
- See Also:
-
-
Constructor Details
-
SolrQuery
public SolrQuery() -
SolrQuery
Create a new SolrQuery- Parameters:
q- query string
-
SolrQuery
-
-
Method Details
-
setTerms
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
-
getTermsFields
-
setTermsLower
-
getTermsLower
-
setTermsUpper
-
getTermsUpper
-
setTermsUpperInclusive
-
getTermsUpperInclusive
public boolean getTermsUpperInclusive() -
setTermsLowerInclusive
-
getTermsLowerInclusive
public boolean getTermsLowerInclusive() -
setTermsLimit
-
getTermsLimit
public int getTermsLimit() -
setTermsMinCount
-
getTermsMinCount
public int getTermsMinCount() -
setTermsMaxCount
-
getTermsMaxCount
public int getTermsMaxCount() -
setTermsPrefix
-
getTermsPrefix
-
setTermsRaw
-
getTermsRaw
public boolean getTermsRaw() -
setTermsSortString
-
getTermsSortString
-
setTermsRegex
-
getTermsRegex
-
setTermsRegexFlag
-
getTermsRegexFlags
-
addFacetField
Add field(s) for facet computation.- Parameters:
fields- Array of field names from the IndexSchema- Returns:
- this
-
addFacetPivotField
Add field(s) for pivot computation.pivot fields are comma separated
- Parameters:
fields- Array of field names from the IndexSchema- Returns:
- this
-
addNumericRangeFacet
Add a numeric range facet.- Parameters:
field- The fieldstart- The start of rangeend- The end of the rangegap- The gap between each count- Returns:
- this
-
addDateRangeFacet
Add a numeric range facet.- Parameters:
field- The fieldstart- The start of rangeend- The end of the rangegap- The gap between each count- Returns:
- this
-
addIntervalFacets
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 levelModifiableSolrParams.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 nullintervals- Intervals to be used for faceting. It can be an empty array, but it can't benull- Returns:
- this
-
removeIntervalFacets
Remove all Interval Facets on a field- Parameters:
field- the field to remove from facet intervals- Returns:
- Array of current intervals for
field
-
getFacetFields
get the facet fields- Returns:
- string array of facet fields or null if not set/empty
-
removeFacetField
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
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
-
setFacetPrefix
-
addFacetQuery
add a faceting query- Parameters:
f- facet query
-
getFacetQuery
get facet queries- Returns:
- all facet queries or null if not set/empty
-
removeFacetQuery
remove a facet query- Parameters:
q- the facet query to remove- Returns:
- true if the facet query was removed false otherwise
-
setFacetLimit
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
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
Sets facet missing boolean flag- Parameters:
v- flag to indicate the field ofFacetParams.FACET_MISSING.- Returns:
- this
-
getFacetSortString
get facet sort- Returns:
- facet sort or default of
FacetParams.FACET_SORT_COUNT
-
setFacetSort
set facet sort- Parameters:
sort- sort facets- Returns:
- this
-
addHighlightField
add highlight field- Parameters:
f- field to enable for highlighting
-
removeHighlightField
remove a field for highlighting- Parameters:
f- field name to not highlight- Returns:
- true, if removed,
false, otherwise
-
getHighlightFields
get list of highlighted fields- Returns:
- Array of highlight fields or null if not set/empty
-
setHighlightSnippets
-
getHighlightSnippets
public int getHighlightSnippets() -
setHighlightFragsize
-
getHighlightFragsize
public int getHighlightFragsize() -
setHighlightRequireFieldMatch
-
getHighlightRequireFieldMatch
public boolean getHighlightRequireFieldMatch() -
setHighlightSimplePre
-
getHighlightSimplePre
-
setHighlightSimplePost
-
getHighlightSimplePost
-
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()andsetSorts(List). -
clearSorts
Clears current sort information.- Returns:
- the modified SolrQuery object, for easy chaining
- Since:
- 4.2
-
setSorts
Replaces the current sort information.- Returns:
- the modified SolrQuery object, for easy chaining
- Since:
- 4.2
-
getSorts
Gets a list of current sort clauses.- Returns:
- an immutable list of current sort clauses
- Since:
- 4.2
-
setSort
Replaces the current sort information with a single sort clause- Returns:
- the modified SolrQuery object, for easy chaining
- Since:
- 4.2
-
setSort
Replaces the current sort information with a single sort clause- Returns:
- the modified SolrQuery object, for easy chaining
- Since:
- 4.2
-
addSort
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
Adds a single sort clause to the end of the query.- Returns:
- the modified SolrQuery object, for easy chaining
- Since:
- 4.2
-
addOrUpdateSort
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
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
Removes a single sort field from the current sort information.- Returns:
- the modified SolrQuery object, for easy chaining
- Since:
- 4.2
-
removeSort
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
-
addGetFieldStatistics
-
addStatsFieldFacets
-
addStatsFieldCalcDistinct
-
setFilterQueries
-
addFilterQuery
-
removeFilterQuery
-
getFilterQueries
-
getHighlight
public boolean getHighlight() -
setHighlight
-
addMoreLikeThisField
Add field for MoreLikeThis. Automatically enables MoreLikeThis.- Parameters:
field- the names of the field to be added- Returns:
- this
-
setMoreLikeThisFields
-
getMoreLikeThisFields
- Returns:
- an array with the fields used to compute similarity.
-
setMoreLikeThisMinTermFreq
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
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
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
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
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
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
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
Sets the query fields and their boosts using the same format as that used in DisMaxQParserPlugin. These fields must also be added usingaddMoreLikeThisField(String).- Parameters:
qf- the query fields- Returns:
- this
-
getMoreLikeThisQF
Gets the query fields and their boosts. -
setMoreLikeThisCount
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
Enable/Disable MoreLikeThis. After enabling MoreLikeThis, the fields used for computing similarity must be specified callingaddMoreLikeThisField(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
-
setFields
-
addField
-
getFields
-
setIncludeScore
-
setQuery
-
getQuery
-
setRows
-
getRows
-
setShowDebugInfo
-
setDistrib
public void setDistrib(boolean val) -
setStart
-
getStart
-
setRequestHandler
Deprecated.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 byQueryRequest.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
Deprecated. -
setParam
- Returns:
- this
- See Also:
-
setParam
- Returns:
- this
- See Also:
-
getCopy
get a deep copy of this object * -
setTimeAllowed
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
Get the maximum time allowed for this query. -
setCpuAllowed
Set the maximum CPU time allowed for this query. If the thread that executes the query takes more CPU 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 CPU time in milliseconds allowed for this query
-
getCpuAllowed
Get the maximum time allowed for this query.
-
SolrRequest.setPath(String)