Class RewriterUtils

java.lang.Object
com.yahoo.search.query.rewrite.RewriterUtils

public class RewriterUtils extends Object
Contains common utilities used by rewriters
Author:
Karen Sze Wing Lee
  • Constructor Details

    • RewriterUtils

      public RewriterUtils()
  • Method Details

    • loadFSA

      public static com.yahoo.fsa.FSA loadFSA(File file, Query query) throws IOException
      Load FSA from file
      Parameters:
      file - FSA dictionary file object
      query - Query object from the searcher, could be null if not available
      Returns:
      FSA The FSA object for the input file path
      Throws:
      IOException
    • loadFSA

      public static com.yahoo.fsa.FSA loadFSA(String filename, Query query) throws IOException
      Load FSA from file
      Parameters:
      filename - FSA dictionary file path
      query - Query object from the searcher, could be null if not available
      Returns:
      FSA The FSA object for the input file path
      Throws:
      IOException
    • getRewriteFromFSA

      public static String getRewriteFromFSA(Query query, HashMap<String,Object> rewriterDicts, String dictName, String key) throws RuntimeException
      Retrieve rewrite from FSA given the original query
      Parameters:
      query - Query object from searcher
      dictName - FSA dictionary name
      rewriterDicts - 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:
      RuntimeException
    • getQPConfig

      public static String getQPConfig(Query query, String rewriterName, String paramName)
      Get config parameter value set in query profile
      Parameters:
      query - Query object from the searcher
      rewriterName - Name of the rewriter
      paramName - parameter to be retrieved
      Returns:
      parameter value or null if not found
    • getRewriterChain

      public static 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 String getUserParam(Query query, String paramName)
      Get user param value
      Parameters:
      query - Query object from the searcher
      paramName - parameter to be retrieved
      Returns:
      parameter value or null if not found
    • getRewriteMeta

      public static HashMap<String,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, HashMap<String,Object> metadata)
      Pass metadata to the next rewriter through query properties
      Parameters:
      query - Query object from the searcher
      metadata - HashMap containing the metadata
    • getSpellCorrected

      public static String getSpellCorrected(Query query, boolean qss_rw, boolean qss_sugg) throws RuntimeException
      Retrieve spell corrected query with highest score from QLAS
      Parameters:
      query - Query object from the searcher
      qss_rw - Whether to consider qss_rw modification
      qss_sugg - Whether ot consider qss_sugg modification
      Returns:
      Spell corrected query or null if not found
      Throws:
      RuntimeException
    • getNormalizedOriginalQuery

      public static 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(Logger logger, String msg)
      Log message
      Parameters:
      logger - Logger used for this msg
      msg - Log message
    • log

      public static void log(Logger logger, Query query, String msg)
      Log message
      Parameters:
      logger - Logger used for this msg
      query - Query object from searcher
      msg - Log message
    • error

      public static void error(Logger logger, String msg)
      Print error message
      Parameters:
      logger - Logger used for this msg
      msg - Error message
    • error

      public static void error(Logger logger, Query query, String msg)
      Print error message
      Parameters:
      logger - Logger used for this msg
      query - Query object from searcher
      msg - Error message