Class QueryElevationComponent
java.lang.Object
org.apache.solr.handler.component.SearchComponent
org.apache.solr.handler.component.QueryElevationComponent
- All Implemented Interfaces:
AutoCloseable,SolrInfoBean,SolrMetricProducer,NamedListInitializedPlugin,SolrCoreAware
A component to elevate some documents to the top of the result set.
- Since:
- solr 1.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classProvides elevations with either: subset match - all the elevating terms are matched in the search query, in any order.protected static classQuery triggering elevation.protected static classElevation of some documents in search results, with potential exclusion of others.classBuilds anQueryElevationComponent.Elevation.protected static interfaceProvides the elevations defined for queries.protected static enumprotected static classQueryElevationComponent.TrieSubsetMatcher<E extends Comparable<? super E>,M> Matches a potentially large collection of subsets with a trie implementation.Nested classes/interfaces inherited from interface org.apache.solr.core.SolrInfoBean
SolrInfoBean.Category, SolrInfoBean.Group -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringKey toSolrQueryRequest.getContext()for aSet<BytesRef>of included IDs in configured order (so-called priority).Cached elevation provider.protected longCached version / timestamp of the data underlyingcacheElevationProvider.protected Stringstatic final StringKey toSolrQueryRequest.getContext()for aSet<BytesRef>of excluded IDs.protected booleanprotected org.apache.solr.common.params.SolrParamsprotected booleanIfinform(SolrCore)completed without error.protected static final QueryElevationComponent.ElevationProviderQueryElevationComponent.ElevationProviderthat returns no elevation.protected org.apache.lucene.analysis.Analyzerprotected SchemaFieldprotected booleanFields inherited from class org.apache.solr.handler.component.SearchComponent
solrMetricsContext, standard_componentsFields inherited from interface org.apache.solr.metrics.SolrMetricProducer
CATEGORY_ATTR, HANDLER_ATTR, NAME_ATTR, OPERATION_ATTR, PLUGIN_NAME_ATTR, RESULT_ATTR, TYPE_ATTR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionanalyzeQuery(String query) Analyzes the provided query string and returns a concatenation of the analyzed tokens.protected voidanalyzeQuery(String query, Consumer<CharSequence> termsConsumer) Analyzes the provided query string, tokenizes the terms, and adds them to the providedConsumer.createElevationProvider(Map<QueryElevationComponent.ElevatingQuery, QueryElevationComponent.ElevationBuilder> elevationBuilderMap) Creates theQueryElevationComponent.ElevationProviderto set during configuration loading.static com.carrotsearch.hppc.IntIntHashMapgetBoostDocs(SolrIndexSearcher indexSearcher, Set<org.apache.lucene.util.BytesRef> boosted, Map<Object, Object> context) Resolves a set of boosted docs by uniqueKey to a map of docIds mapped to a priority value > 0.protected longgetConfigVersion(SolrCore core) Returns a version number for the config file, or -1 if not supported.Simple one or two line descriptionprotected QueryElevationComponent.ElevationgetElevationProvider(org.apache.lucene.index.IndexReader reader, SolrCore core) Gets theQueryElevationComponent.ElevationProvider; typically cached.protected <E extends Exception>
QueryElevationComponent.ElevationProviderHandles an exception that occurred while loading the configuration resource.protected voidhandleInitializationException(Exception exception, QueryElevationComponent.InitializationExceptionCause cause) Handles the exception that occurred while initializing this component or when parsing a new config file at runtime.voidvoidinit(org.apache.solr.common.util.NamedList<?> args) initwill be called just once, immediately after creation.protected booleanisSubsetMatchPolicy(String matchString) protected int(Re)Loads elevation configuration.Loads theQueryElevationComponent.ElevationProvider.Loads theQueryElevationComponent.ElevationProvider.voidPrepare the response.voidProcess the request for this componentMethods inherited from class org.apache.solr.handler.component.SearchComponent
distributedProcess, finishStage, getCategory, getName, getSolrMetricsContext, handleResponses, initializeMetrics, modifyRequest, setNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.solr.metrics.SolrMetricProducer
close
-
Field Details
-
BOOSTED
Key toSolrQueryRequest.getContext()for aSet<BytesRef>of included IDs in configured order (so-called priority).- See Also:
-
EXCLUDED
Key toSolrQueryRequest.getContext()for aSet<BytesRef>of excluded IDs.- See Also:
-
initArgs
protected org.apache.solr.common.params.SolrParams initArgs -
configFileName
-
queryAnalyzer
protected org.apache.lucene.analysis.Analyzer queryAnalyzer -
uniqueKeyField
-
forceElevation
protected boolean forceElevation- See Also:
-
useConfiguredElevatedOrder
protected boolean useConfiguredElevatedOrder- See Also:
-
initialized
protected boolean initializedIfinform(SolrCore)completed without error. -
cacheElevationProvider
Cached elevation provider. Must be accessed under lock.handleConfigLoadingException(Exception)has the lock when called and may access this if it wishes to return a previous good result. -
cacheVersion
protected long cacheVersionCached version / timestamp of the data underlyingcacheElevationProvider. -1 means unsupported. Must be accessed under lock.- See Also:
-
NO_OP_ELEVATION_PROVIDER
QueryElevationComponent.ElevationProviderthat returns no elevation.
-
-
Constructor Details
-
QueryElevationComponent
public QueryElevationComponent()
-
-
Method Details
-
init
public void init(org.apache.solr.common.util.NamedList<?> args) Description copied from interface:NamedListInitializedPlugininitwill be called just once, immediately after creation.Source of the initialization arguments will typically be solrconfig.xml, but will ultimately depends on the plugin itself
- Specified by:
initin interfaceNamedListInitializedPlugin- Parameters:
args- non-null list of initialization parameters (may be empty)
-
inform
- Specified by:
informin interfaceSolrCoreAware
-
loadElevationConfiguration
(Re)Loads elevation configuration.- Parameters:
core- The core holding this component.- Returns:
- The number of elevation rules parsed.
- Throws:
Exception
-
handleInitializationException
protected void handleInitializationException(Exception exception, QueryElevationComponent.InitializationExceptionCause cause) Handles the exception that occurred while initializing this component or when parsing a new config file at runtime. If this method does not throw an exception, this component silently fails to initialize and is muted with fieldinitializedwhich becomesfalse. -
handleConfigLoadingException
protected <E extends Exception> QueryElevationComponent.ElevationProvider handleConfigLoadingException(E e) Handles an exception that occurred while loading the configuration resource. The default implementation will returncacheElevationProviderif present, while also logging the error. If that is null (e.g. on startup) then the exception is thrown. When re-throwing, wrap in aSolrException.- Parameters:
e- The exception caught. It will extendIOExceptionif there was a resource access issue.- Returns:
- The
QueryElevationComponent.ElevationProviderto use if the exception is absorbed (vs re-thrown).
-
getElevationProvider
protected QueryElevationComponent.ElevationProvider getElevationProvider(org.apache.lucene.index.IndexReader reader, SolrCore core) Gets theQueryElevationComponent.ElevationProvider; typically cached. If there was a problem, it might return a previously cached or dummy entry, or possibly rethrow the exception.- Returns:
- The cached or loaded
QueryElevationComponent.ElevationProvider.
-
getConfigVersion
Returns a version number for the config file, or -1 if not supported. It can be a timestamp; it need not strictly increase. -
loadElevationProvider
protected QueryElevationComponent.ElevationProvider loadElevationProvider(SolrCore core) throws IOException, SAXException Loads theQueryElevationComponent.ElevationProvider.- Returns:
- The loaded
QueryElevationComponent.ElevationProvider; not null. - Throws:
IOExceptionSAXException
-
loadElevationProvider
Loads theQueryElevationComponent.ElevationProvider. Not null.- Throws:
RuntimeException- If the config does not provide an XML content of the expected format (eitherRuntimeExceptionorSolrException).
-
isSubsetMatchPolicy
-
prepare
Description copied from class:SearchComponentPrepare the response. Guaranteed to be called before any SearchComponentSearchComponent.process(org.apache.solr.handler.component.ResponseBuilder)method. Called for every incoming request.The place to do initialization that is request dependent.
- Specified by:
preparein classSearchComponent- Parameters:
rb- TheResponseBuilder- Throws:
IOException- If there is a low-level I/O error.
-
process
Description copied from class:SearchComponentProcess the request for this component- Specified by:
processin classSearchComponent- Parameters:
rb- TheResponseBuilder- Throws:
IOException- If there is a low-level I/O error.
-
getElevation
-
getBoostDocs
public static com.carrotsearch.hppc.IntIntHashMap getBoostDocs(SolrIndexSearcher indexSearcher, Set<org.apache.lucene.util.BytesRef> boosted, Map<Object, Object> context) throws IOExceptionResolves a set of boosted docs by uniqueKey to a map of docIds mapped to a priority value > 0.- Parameters:
indexSearcher- the SolrIndexSearcher; requiredboosted- are the set of uniqueKey values to be boosted in priority order. If null; returns null.context- theSolrQueryRequest.getContext()or null if none. We'll cache our results here.- Throws:
IOException
-
getDescription
Description copied from interface:SolrInfoBeanSimple one or two line description- Specified by:
getDescriptionin interfaceSolrInfoBean- Specified by:
getDescriptionin classSearchComponent
-
createElevationProvider
protected QueryElevationComponent.ElevationProvider createElevationProvider(Map<QueryElevationComponent.ElevatingQuery, QueryElevationComponent.ElevationBuilder> elevationBuilderMap) Creates theQueryElevationComponent.ElevationProviderto set during configuration loading. The same instance will be used later when elevating results for queries.- Parameters:
elevationBuilderMap- map of allQueryElevationComponent.ElevatingQueryand their correspondingQueryElevationComponent.ElevationBuilder.- Returns:
- The created
QueryElevationComponent.ElevationProvider.
-
analyzeQuery
Analyzes the provided query string and returns a concatenation of the analyzed tokens. -
analyzeQuery
Analyzes the provided query string, tokenizes the terms, and adds them to the providedConsumer.
-