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.
Modifier and Type | Field and Description |
---|---|
private boolean |
isOk |
protected Logger |
logger |
protected HashMap<String,Object> |
rewriterDicts |
Modifier | Constructor and 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,
HashMap<String,File> fileList)
Constructor for unit test.
|
Modifier and Type | Method and Description |
---|---|
abstract boolean |
configure(com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer,
RewritesConfig config,
HashMap<String,File> fileList)
Perform instance creation time configuration besides the
default FSA loading
|
abstract HashMap<String,String> |
getDefaultFSAs()
Get default FSA dictionary names
|
protected String |
getQPConfig(Query query,
String paramName)
Get config parameter value set in query profile
|
protected String |
getRewriteFromFSA(Query query,
String dictName,
String key)
Retrieve rewrite from FSA given the original query
|
abstract String |
getRewriterName()
Retrieve rewriter name
It should match the name used in query profile
|
protected abstract boolean |
getSkipRewriterIfRewritten()
Check whether rewriter should be skipped if
the query has been rewritten by other rewriter
|
private boolean |
loadFSADicts(com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer,
RewritesConfig config,
HashMap<String,File> fileList)
Load the dicts specified in vespa-services.xml
|
protected abstract HashMap<String,Object> |
rewrite(Query query,
String dictKey)
Perform the main rewrite logic
|
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 |
ensureFilled, fill, getLogger, process, toString
getAnnotatedDependencies, getDefaultAnnotatedDependencies, getDependencies, initDependencies
private boolean isOk
protected final Logger logger
@Inject protected QueryRewriteSearcher(com.yahoo.component.ComponentId id, com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer, RewritesConfig config)
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)protected QueryRewriteSearcher(RewritesConfig config, HashMap<String,File> fileList)
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 testsprotected QueryRewriteSearcher(com.yahoo.component.ComponentId id)
protected QueryRewriteSearcher()
private boolean loadFSADicts(com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer, RewritesConfig config, HashMap<String,File> fileList) throws RuntimeException
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 testsRuntimeException
public abstract boolean configure(com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer, RewritesConfig config, HashMap<String,File> fileList) throws RuntimeException
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 testsRuntimeException
public Result search(Query query, Execution execution)
protected abstract HashMap<String,Object> rewrite(Query query, String dictKey) throws RuntimeException
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)RuntimeException
protected abstract boolean getSkipRewriterIfRewritten()
public abstract String getRewriterName()
public abstract HashMap<String,String> getDefaultFSAs()
protected String getQPConfig(Query query, String paramName)
query
- Query object from the searcherparamName
- parameter to be retrievedprotected String getRewriteFromFSA(Query query, String dictName, String key) throws RuntimeException
query
- Query object from searcherdictName
- FSA dictionary namekey
- The original query used to retrieve rewrite
from the dictionaryRuntimeException
Copyright © 2017. All rights reserved.