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
public class QueryElevationComponent extends SearchComponent implements SolrCoreAware
A component to elevate some documents to the top of the result set.- Since:
- solr 1.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classQueryElevationComponent.DefaultElevationProviderProvides elevations with either: subset match - all the elevating terms are matched in the search query, in any order.protected static classQueryElevationComponent.ElevatingQueryQuery triggering elevation.protected static classQueryElevationComponent.ElevationElevation of some documents in search results, with potential exclusion of others.classQueryElevationComponent.ElevationBuilderBuilds anQueryElevationComponent.Elevation.protected static interfaceQueryElevationComponent.ElevationProviderProvides the elevations defined for queries.protected static classQueryElevationComponent.InitializationExceptionCauseprotected 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
Fields Modifier and Type Field Description static StringBOOSTEDKey toSolrQueryRequest.getContext()for aSet<BytesRef>of included IDs in configured order (so-called priority).protected QueryElevationComponent.ElevationProvidercacheElevationProviderCached elevation provider.protected longcacheVersionCached version / timestamp of the data underlyingcacheElevationProvider.protected StringconfigFileNamestatic StringEXCLUDEDKey toSolrQueryRequest.getContext()for aSet<BytesRef>of excluded IDs.protected booleanforceElevationprotected org.apache.solr.common.params.SolrParamsinitArgsprotected booleaninitializedIfinform(SolrCore)completed without error.protected static QueryElevationComponent.ElevationProviderNO_OP_ELEVATION_PROVIDERQueryElevationComponent.ElevationProviderthat returns no elevation.protected org.apache.lucene.analysis.AnalyzerqueryAnalyzerprotected SchemaFielduniqueKeyFieldprotected booleanuseConfiguredElevatedOrder-
Fields inherited from class org.apache.solr.handler.component.SearchComponent
solrMetricsContext, standard_components
-
-
Constructor Summary
Constructors Constructor Description QueryElevationComponent()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringanalyzeQuery(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.protected QueryElevationComponent.ElevationProvidercreateElevationProvider(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.StringgetDescription()Simple one or two line descriptionprotected QueryElevationComponent.ElevationgetElevation(ResponseBuilder rb)protected QueryElevationComponent.ElevationProvidergetElevationProvider(org.apache.lucene.index.IndexReader reader, SolrCore core)Gets theQueryElevationComponent.ElevationProvider; typically cached.protected <E extends Exception>
QueryElevationComponent.ElevationProviderhandleConfigLoadingException(E e)Handles 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.voidinform(SolrCore core)voidinit(org.apache.solr.common.util.NamedList<?> args)initwill be called just once, immediately after creation.protected booleanisSubsetMatchPolicy(String matchString)protected intloadElevationConfiguration(SolrCore core)(Re)Loads elevation configuration.protected QueryElevationComponent.ElevationProviderloadElevationProvider(SolrCore core)Loads theQueryElevationComponent.ElevationProvider.protected QueryElevationComponent.ElevationProviderloadElevationProvider(Document doc)Loads theQueryElevationComponent.ElevationProvider.voidprepare(ResponseBuilder rb)Prepare the response.voidprocess(ResponseBuilder rb)Process the request for this component-
Methods inherited from class org.apache.solr.handler.component.SearchComponent
distributedProcess, finishStage, getCategory, getName, getSolrMetricsContext, handleResponses, initializeMetrics, modifyRequest, setName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.solr.metrics.SolrMetricProducer
close
-
-
-
-
Field Detail
-
BOOSTED
public static final String BOOSTED
Key toSolrQueryRequest.getContext()for aSet<BytesRef>of included IDs in configured order (so-called priority).- See Also:
- Constant Field Values
-
EXCLUDED
public static final String EXCLUDED
Key toSolrQueryRequest.getContext()for aSet<BytesRef>of excluded IDs.- See Also:
- Constant Field Values
-
initArgs
protected org.apache.solr.common.params.SolrParams initArgs
-
configFileName
protected String configFileName
-
queryAnalyzer
protected org.apache.lucene.analysis.Analyzer queryAnalyzer
-
uniqueKeyField
protected SchemaField uniqueKeyField
-
forceElevation
protected boolean forceElevation
- See Also:
QueryElevationParams.FORCE_ELEVATION
-
useConfiguredElevatedOrder
protected boolean useConfiguredElevatedOrder
- See Also:
QueryElevationParams.USE_CONFIGURED_ELEVATED_ORDER
-
initialized
protected boolean initialized
Ifinform(SolrCore)completed without error.
-
cacheElevationProvider
protected QueryElevationComponent.ElevationProvider 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 cacheVersion
Cached version / timestamp of the data underlyingcacheElevationProvider. -1 means unsupported. Must be accessed under lock.- See Also:
getConfigVersion(SolrCore)
-
NO_OP_ELEVATION_PROVIDER
protected static final QueryElevationComponent.ElevationProvider NO_OP_ELEVATION_PROVIDER
QueryElevationComponent.ElevationProviderthat returns no elevation.
-
-
Method Detail
-
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
public void inform(SolrCore core)
- Specified by:
informin interfaceSolrCoreAware
-
loadElevationConfiguration
protected int loadElevationConfiguration(SolrCore core) throws Exception
(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
protected long getConfigVersion(SolrCore core)
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
protected QueryElevationComponent.ElevationProvider loadElevationProvider(Document doc)
Loads theQueryElevationComponent.ElevationProvider. Not null.- Throws:
RuntimeException- If the config does not provide an XML content of the expected format (eitherRuntimeExceptionorSolrException).
-
isSubsetMatchPolicy
protected boolean isSubsetMatchPolicy(String matchString)
-
prepare
public void prepare(ResponseBuilder rb) throws IOException
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
public void process(ResponseBuilder rb) throws IOException
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
protected QueryElevationComponent.Elevation getElevation(ResponseBuilder rb)
-
getBoostDocs
public static com.carrotsearch.hppc.IntIntHashMap getBoostDocs(SolrIndexSearcher indexSearcher, Set<org.apache.lucene.util.BytesRef> boosted, Map<Object,Object> context) throws IOException
Resolves 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
public String 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
public String analyzeQuery(String query)
Analyzes the provided query string and returns a concatenation of the analyzed tokens.
-
analyzeQuery
protected void analyzeQuery(String query, Consumer<CharSequence> termsConsumer)
Analyzes the provided query string, tokenizes the terms, and adds them to the providedConsumer.
-
-