Package com.yahoo.search.query.rewrite
Class QueryRewriteSearcher
- java.lang.Object
-
- com.yahoo.component.AbstractComponent
-
- com.yahoo.component.chain.ChainedComponent
-
- com.yahoo.processing.Processor
-
- com.yahoo.search.Searcher
-
- com.yahoo.search.query.rewrite.QueryRewriteSearcher
-
- All Implemented Interfaces:
com.yahoo.component.Component
,com.yahoo.component.Deconstructable
,java.lang.Comparable<com.yahoo.component.Component>
- Direct Known Subclasses:
GenericExpansionRewriter
,MisspellRewriter
,NameRewriter
public abstract class QueryRewriteSearcher extends Searcher
A template class for all rewriters
All rewriters extending this class would need to implement the rewrite method which contains the rewriter's main logic, getSkipRewriterIfRewritten method which indicates whether this rewriter should be skipped if the query has been rewritten, getRewriterName method which returns the name of the rewriter used in query profile, configure method which contains any instance creation time configuration besides the default FSA loading, and getDefaultDicts method which return the pair of dictionary name and filename.
Common rewrite features are in RewriterFeatures.java. Common rewriter utils are in RewriterUtils.java.
- Author:
- Karen Sze Wing Lee
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.logging.Logger
logger
protected java.util.HashMap<java.lang.String,java.lang.Object>
rewriterDicts
-
Constructor Summary
Constructors Modifier Constructor Description protected
QueryRewriteSearcher()
Empty constructor for unit test.protected
QueryRewriteSearcher(com.yahoo.component.ComponentId id)
Empty constructor.protected
QueryRewriteSearcher(com.yahoo.component.ComponentId id, com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer, RewritesConfig config)
Constructor for this rewriter.protected
QueryRewriteSearcher(RewritesConfig config, java.util.HashMap<java.lang.String,java.io.File> fileList)
Constructor for unit test.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
configure(com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer, RewritesConfig config, java.util.HashMap<java.lang.String,java.io.File> fileList)
Perform instance creation time configuration besides the default FSA loadingabstract java.util.HashMap<java.lang.String,java.lang.String>
getDefaultFSAs()
Get default FSA dictionary namesprotected java.lang.String
getQPConfig(Query query, java.lang.String paramName)
Get config parameter value set in query profileprotected java.lang.String
getRewriteFromFSA(Query query, java.lang.String dictName, java.lang.String key)
Retrieve rewrite from FSA given the original queryabstract java.lang.String
getRewriterName()
Retrieve rewriter name It should match the name used in query profileprotected abstract boolean
getSkipRewriterIfRewritten()
Check whether rewriter should be skipped if the query has been rewritten by other rewriterprotected abstract java.util.HashMap<java.lang.String,java.lang.Object>
rewrite(Query query, java.lang.String dictKey)
Perform the main rewrite logicResult
search(Query query, Execution execution)
Perform main rewrite logics for this searcher
- Skip to next rewriter if query is previously rewritten and getSkipRewriterIfRewritten() is true for this rewriter
- Execute rewriter's main rewrite logic
- Pass to the next rewriter the query to be used for dictionary retrieval-
Methods inherited from class com.yahoo.search.Searcher
ensureFilled, fill, getLogger, process, toString
-
Methods inherited from class com.yahoo.component.chain.ChainedComponent
getAnnotatedDependencies, getDefaultAnnotatedDependencies, getDependencies, initDependencies
-
-
-
-
Constructor Detail
-
QueryRewriteSearcher
@Inject protected QueryRewriteSearcher(com.yahoo.component.ComponentId id, com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer, RewritesConfig config)
Constructor for this rewriter. Prepare the data needed by the rewriter- Parameters:
id
- Component ID (see vespa's search container doc for more detail)fileAcquirer
- Required param for retrieving file type config (see vespa's search container doc for more detail)config
- Config from vespa-services.xml (see vespa's search container doc for more detail)
-
QueryRewriteSearcher
protected QueryRewriteSearcher(RewritesConfig config, java.util.HashMap<java.lang.String,java.io.File> fileList)
Constructor for unit test. Prepare the data needed by the rewriter- Parameters:
config
- Config from vespa-services.xml (see vespa's search container doc for more detail)fileList
- pairs of file name and file handler for unit tests
-
QueryRewriteSearcher
protected QueryRewriteSearcher(com.yahoo.component.ComponentId id)
Empty constructor. Do nothing at instance creation time
-
QueryRewriteSearcher
protected QueryRewriteSearcher()
Empty constructor for unit test. Do nothing at instance creation time
-
-
Method Detail
-
configure
public abstract boolean configure(com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer, RewritesConfig config, java.util.HashMap<java.lang.String,java.io.File> fileList) throws java.lang.RuntimeException
Perform instance creation time configuration besides the default FSA loading- Parameters:
fileAcquirer
- Required param for retrieving file type config (see vespa's search container doc for more detail)config
- Config from vespa-services.xml (see vespa's search container doc for more detail)fileList
- pairs of file name and file handler for unit tests- Returns:
- boolean true if loaded successfully, false otherwise
- Throws:
java.lang.RuntimeException
-
search
public Result search(Query query, Execution execution)
Perform main rewrite logics for this searcher
- Skip to next rewriter if query is previously rewritten and getSkipRewriterIfRewritten() is true for this rewriter
- Execute rewriter's main rewrite logic
- Pass to the next rewriter the query to be used for dictionary retrieval
-
rewrite
protected abstract java.util.HashMap<java.lang.String,java.lang.Object> rewrite(Query query, java.lang.String dictKey) throws java.lang.RuntimeException
Perform the main rewrite logic- Parameters:
query
- Query object from searcherdictKey
- the key passed from previous rewriter to be treated as "original query from user" For example, if previous is misspell rewriter, it would pass the corrected query as the "original query from user". For other rewriters which add variants, abbr, etc to the query, the original query should be passed as a key. This rewriter could still choose to ignore this key. This key is not the rewritten query itself. For example, if original query is (willl smith) and the rewritten query is (willl smith) OR (will smith) the key to be passed could be (will smith)- Returns:
- HashMap which contains the key value pairs:
- whether this query has been rewritten by this rewriter
key: rewritten
value: true or false
- the key to be treated as "original query from user" in next rewriter downstream, for example, misspell rewriter would pass the corrected query as the "original query from user" to the next rewriter. For other rewriters which add variants, abbr, etc to the query, the original query should be passed as a key. This key is not necessarily consumed by the next rewriter. The next rewriter can still choose to ignore this key.
key: newDictKey
value: new dict key - Throws:
java.lang.RuntimeException
-
getSkipRewriterIfRewritten
protected abstract boolean getSkipRewriterIfRewritten()
Check whether rewriter should be skipped if the query has been rewritten by other rewriter- Returns:
- boolean Whether rewriter should be skipped
-
getRewriterName
public abstract java.lang.String getRewriterName()
Retrieve rewriter name It should match the name used in query profile- Returns:
- Name of the rewriter
-
getDefaultFSAs
public abstract java.util.HashMap<java.lang.String,java.lang.String> getDefaultFSAs()
Get default FSA dictionary names- Returns:
- Pair of FSA dictionary name and filename
-
getQPConfig
protected java.lang.String getQPConfig(Query query, java.lang.String paramName)
Get config parameter value set in query profile- Parameters:
query
- Query object from the searcherparamName
- parameter to be retrieved- Returns:
- parameter value or null if not found
-
getRewriteFromFSA
protected java.lang.String getRewriteFromFSA(Query query, java.lang.String dictName, java.lang.String key) throws java.lang.RuntimeException
Retrieve rewrite from FSA given the original query- Parameters:
query
- Query object from searcherdictName
- FSA dictionary namekey
- The original query used to retrieve rewrite from the dictionary- Returns:
- String The retrieved rewrites, null if query doesn't exist
- Throws:
java.lang.RuntimeException
-
-