Package com.yahoo.search.query.rewrite
Class RewriterUtils
- java.lang.Object
-
- com.yahoo.search.query.rewrite.RewriterUtils
-
public class RewriterUtils extends java.lang.Object
Contains common utilities used by rewriters- Author:
- Karen Sze Wing Lee
-
-
Constructor Summary
Constructors Constructor Description RewriterUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
error(java.util.logging.Logger logger, Query query, java.lang.String msg)
Print error messagestatic void
error(java.util.logging.Logger logger, java.lang.String msg)
Print error messagestatic java.lang.String
getNormalizedOriginalQuery(Query query)
Retrieve normalized original query from query objectstatic java.lang.String
getQPConfig(Query query, java.lang.String rewriterName, java.lang.String paramName)
Get config parameter value set in query profilestatic java.lang.String
getRewriteFromFSA(Query query, java.util.HashMap<java.lang.String,java.lang.Object> rewriterDicts, java.lang.String dictName, java.lang.String key)
Retrieve rewrite from FSA given the original querystatic java.util.HashMap<java.lang.String,java.lang.Object>
getRewriteMeta(Query query)
Retrieve metadata passed by previous rewriter from query properties Initialize values if this is the first rewriterstatic java.lang.String
getRewriterChain(Query query)
Get rewriter chain valuestatic java.lang.String
getSpellCorrected(Query query, boolean qss_rw, boolean qss_sugg)
Retrieve spell corrected query with highest score from QLASstatic java.lang.String
getUserParam(Query query, java.lang.String paramName)
Get user param valuestatic com.yahoo.fsa.FSA
loadFSA(java.io.File file, Query query)
Load FSA from filestatic com.yahoo.fsa.FSA
loadFSA(java.lang.String filename, Query query)
Load FSA from filestatic void
log(java.util.logging.Logger logger, Query query, java.lang.String msg)
Log messagestatic void
log(java.util.logging.Logger logger, java.lang.String msg)
Log messagestatic void
setRewriteMeta(Query query, java.util.HashMap<java.lang.String,java.lang.Object> metadata)
Pass metadata to the next rewriter through query properties
-
-
-
Method Detail
-
loadFSA
public static com.yahoo.fsa.FSA loadFSA(java.io.File file, Query query) throws java.io.IOException
Load FSA from file- Parameters:
file
- FSA dictionary file objectquery
- Query object from the searcher, could be null if not available- Returns:
- FSA The FSA object for the input file path
- Throws:
java.io.IOException
-
loadFSA
public static com.yahoo.fsa.FSA loadFSA(java.lang.String filename, Query query) throws java.io.IOException
Load FSA from file- Parameters:
filename
- FSA dictionary file pathquery
- Query object from the searcher, could be null if not available- Returns:
- FSA The FSA object for the input file path
- Throws:
java.io.IOException
-
getRewriteFromFSA
public static java.lang.String getRewriteFromFSA(Query query, java.util.HashMap<java.lang.String,java.lang.Object> rewriterDicts, 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 namerewriterDicts
- list of rewriter dictionaries It has the following format: HashMap<dictionary name, FSA>key
- 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
-
getQPConfig
public static java.lang.String getQPConfig(Query query, java.lang.String rewriterName, java.lang.String paramName)
Get config parameter value set in query profile- Parameters:
query
- Query object from the searcherrewriterName
- Name of the rewriterparamName
- parameter to be retrieved- Returns:
- parameter value or null if not found
-
getRewriterChain
public static java.lang.String getRewriterChain(Query query)
Get rewriter chain value- Parameters:
query
- Query object from the searcher- Returns:
- parameter value or null if not found
-
getUserParam
public static java.lang.String getUserParam(Query query, java.lang.String paramName)
Get user param value- Parameters:
query
- Query object from the searcherparamName
- parameter to be retrieved- Returns:
- parameter value or null if not found
-
getRewriteMeta
public static java.util.HashMap<java.lang.String,java.lang.Object> getRewriteMeta(Query query)
Retrieve metadata passed by previous rewriter from query properties Initialize values if this is the first rewriter- Parameters:
query
- Query object from the searcher- Returns:
- hashmap containing the metadata
-
setRewriteMeta
public static void setRewriteMeta(Query query, java.util.HashMap<java.lang.String,java.lang.Object> metadata)
Pass metadata to the next rewriter through query properties- Parameters:
query
- Query object from the searchermetadata
- HashMap containing the metadata
-
getSpellCorrected
public static java.lang.String getSpellCorrected(Query query, boolean qss_rw, boolean qss_sugg) throws java.lang.RuntimeException
Retrieve spell corrected query with highest score from QLAS- Parameters:
query
- Query object from the searcherqss_rw
- Whether to consider qss_rw modificationqss_sugg
- Whether ot consider qss_sugg modification- Returns:
- Spell corrected query or null if not found
- Throws:
java.lang.RuntimeException
-
getNormalizedOriginalQuery
public static java.lang.String getNormalizedOriginalQuery(Query query)
Retrieve normalized original query from query object- Parameters:
query
- Query object from searcher- Returns:
- normalized query
-
log
public static void log(java.util.logging.Logger logger, java.lang.String msg)
Log message- Parameters:
logger
- Logger used for this msgmsg
- Log message
-
log
public static void log(java.util.logging.Logger logger, Query query, java.lang.String msg)
Log message- Parameters:
logger
- Logger used for this msgquery
- Query object from searchermsg
- Log message
-
error
public static void error(java.util.logging.Logger logger, java.lang.String msg)
Print error message- Parameters:
logger
- Logger used for this msgmsg
- Error message
-
error
public static void error(java.util.logging.Logger logger, Query query, java.lang.String msg)
Print error message- Parameters:
logger
- Logger used for this msgquery
- Query object from searchermsg
- Error message
-
-