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 class
QueryElevationComponent.DefaultElevationProvider
Provides elevations with either: subset match - all the elevating terms are matched in the search query, in any order.protected static class
QueryElevationComponent.ElevatingQuery
Query triggering elevation.protected static class
QueryElevationComponent.Elevation
Elevation of some documents in search results, with potential exclusion of others.class
QueryElevationComponent.ElevationBuilder
Builds anQueryElevationComponent.Elevation
.protected static interface
QueryElevationComponent.ElevationProvider
Provides the elevations defined for queries.protected static class
QueryElevationComponent.InitializationExceptionCause
protected static class
QueryElevationComponent.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 String
BOOSTED
Key toSolrQueryRequest.getContext()
for aSet<BytesRef>
of included IDs in configured order (so-called priority).protected QueryElevationComponent.ElevationProvider
cacheElevationProvider
Cached elevation provider.protected long
cacheVersion
Cached version / timestamp of the data underlyingcacheElevationProvider
.protected String
configFileName
static String
EXCLUDED
Key toSolrQueryRequest.getContext()
for aSet<BytesRef>
of excluded IDs.protected boolean
forceElevation
protected org.apache.solr.common.params.SolrParams
initArgs
protected boolean
initialized
Ifinform(SolrCore)
completed without error.protected static QueryElevationComponent.ElevationProvider
NO_OP_ELEVATION_PROVIDER
QueryElevationComponent.ElevationProvider
that returns no elevation.protected org.apache.lucene.analysis.Analyzer
queryAnalyzer
protected SchemaField
uniqueKeyField
protected boolean
useConfiguredElevatedOrder
-
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 String
analyzeQuery(String query)
Analyzes the provided query string and returns a concatenation of the analyzed tokens.protected void
analyzeQuery(String query, Consumer<CharSequence> termsConsumer)
Analyzes the provided query string, tokenizes the terms, and adds them to the providedConsumer
.protected QueryElevationComponent.ElevationProvider
createElevationProvider(Map<QueryElevationComponent.ElevatingQuery,QueryElevationComponent.ElevationBuilder> elevationBuilderMap)
Creates theQueryElevationComponent.ElevationProvider
to set during configuration loading.static com.carrotsearch.hppc.IntIntHashMap
getBoostDocs(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 long
getConfigVersion(SolrCore core)
Returns a version number for the config file, or -1 if not supported.String
getDescription()
Simple one or two line descriptionprotected QueryElevationComponent.Elevation
getElevation(ResponseBuilder rb)
protected QueryElevationComponent.ElevationProvider
getElevationProvider(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 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.void
inform(SolrCore core)
void
init(org.apache.solr.common.util.NamedList<?> args)
init
will be called just once, immediately after creation.protected boolean
isSubsetMatchPolicy(String matchString)
protected int
loadElevationConfiguration(SolrCore core)
(Re)Loads elevation configuration.protected QueryElevationComponent.ElevationProvider
loadElevationProvider(SolrCore core)
Loads theQueryElevationComponent.ElevationProvider
.protected QueryElevationComponent.ElevationProvider
loadElevationProvider(Document doc)
Loads theQueryElevationComponent.ElevationProvider
.void
prepare(ResponseBuilder rb)
Prepare the response.void
process(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.ElevationProvider
that returns no elevation.
-
-
Method Detail
-
init
public void init(org.apache.solr.common.util.NamedList<?> args)
Description copied from interface:NamedListInitializedPlugin
init
will 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:
init
in interfaceNamedListInitializedPlugin
- Parameters:
args
- non-null list of initialization parameters (may be empty)
-
inform
public void inform(SolrCore core)
- Specified by:
inform
in 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 fieldinitialized
which 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 returncacheElevationProvider
if 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 extendIOException
if there was a resource access issue.- Returns:
- The
QueryElevationComponent.ElevationProvider
to 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:
IOException
SAXException
-
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 (eitherRuntimeException
orSolrException
).
-
isSubsetMatchPolicy
protected boolean isSubsetMatchPolicy(String matchString)
-
prepare
public void prepare(ResponseBuilder rb) throws IOException
Description copied from class:SearchComponent
Prepare 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:
prepare
in 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:SearchComponent
Process the request for this component- Specified by:
process
in 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:SolrInfoBean
Simple one or two line description- Specified by:
getDescription
in interfaceSolrInfoBean
- Specified by:
getDescription
in classSearchComponent
-
createElevationProvider
protected QueryElevationComponent.ElevationProvider createElevationProvider(Map<QueryElevationComponent.ElevatingQuery,QueryElevationComponent.ElevationBuilder> elevationBuilderMap)
Creates theQueryElevationComponent.ElevationProvider
to set during configuration loading. The same instance will be used later when elevating results for queries.- Parameters:
elevationBuilderMap
- map of allQueryElevationComponent.ElevatingQuery
and 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
.
-
-