Class QueryElevationComponent
- java.lang.Object
-
- org.apache.solr.handler.component.SearchComponent
-
- org.apache.solr.handler.component.QueryElevationComponent
-
- All Implemented Interfaces:
SolrInfoBean
,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. exact match - the elevating query matches fully (all terms in same order) the search query. The terms are tokenized with the query analyzer.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).static String
EXCLUDED
Key toSolrQueryRequest.getContext()
for aSet<BytesRef>
of excluded IDs.protected boolean
forceElevation
protected SolrParams
initArgs
protected boolean
initialized
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
metricNames, registry, 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 context)
Resolves a set of boosted docs by uniqueKey to a map of docIds mapped to a priority value > 0.String
getDescription()
Simple one or two line descriptionprotected QueryElevationComponent.Elevation
getElevation(ResponseBuilder rb)
protected <E extends Exception>
QueryElevationComponent.ElevationProviderhandleConfigLoadingException(E e, boolean resourceAccessIssue)
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.void
inform(SolrCore core)
void
init(NamedList args)
protected boolean
isSubsetMatchPolicy(String matchString)
protected int
loadElevationConfiguration(SolrCore core)
(Re)Loads elevation configuration.protected QueryElevationComponent.ElevationProvider
loadElevationProvider(XmlConfigFile config)
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, getMetricNames, getMetricRegistry, getName, handleResponses, 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.core.SolrInfoBean
getMetricsSnapshot, registerMetricName
-
-
-
-
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 SolrParams initArgs
-
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
-
initialized
protected boolean initialized
-
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(NamedList args)
- Specified by:
init
in interfaceNamedListInitializedPlugin
- Overrides:
init
in classSearchComponent
-
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. 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, boolean resourceAccessIssue) throws E extends Exception
Handles an exception that occurred while loading the configuration resource.- Parameters:
e
- The exception caught.resourceAccessIssue
-true
if the exception has been thrown because the resource could not be accessed (missing or cannot be read) or the config file is empty;false
if the resource has been found and accessed but the error occurred while loading the resource (invalid format, incomplete or corrupted).- Returns:
- The
QueryElevationComponent.ElevationProvider
to use if the exception is absorbed. Ifnull
is returned, theNO_OP_ELEVATION_PROVIDER
is used but not cached in theQueryElevationComponent.ElevationProvider
cache. - Throws:
E
- If the exception is not absorbed.E extends Exception
-
loadElevationProvider
protected QueryElevationComponent.ElevationProvider loadElevationProvider(XmlConfigFile config)
Loads theQueryElevationComponent.ElevationProvider
.- 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 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
.
-
-