Class Model

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class Model
    extends java.lang.Object
    implements java.lang.Cloneable
    The parameters defining the recall of a query.
    Author:
    Arne Bergene Fossaa, bratseth
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_INDEX  
      static java.lang.String ENCODING  
      static com.yahoo.processing.request.CompoundName ESTIMATE
      The name of the query property used for generating hit count estimate queries.
      static java.lang.String FILTER  
      static java.lang.String LANGUAGE  
      static java.lang.String LOCALE  
      static java.lang.String MODEL  
      static java.lang.String PROGRAM  
      static java.lang.String QUERY_STRING  
      static java.lang.String RESTRICT  
      static java.lang.String SEARCH_PATH  
      static java.lang.String SOURCES  
      static java.lang.String TYPE  
    • Constructor Summary

      Constructors 
      Constructor Description
      Model​(Query query)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearQueryTree()
      Clears the parsed query such that it will be created anew from the textual representation (a query string or select.where expression) on the next access.
      java.lang.Object clone()  
      Model cloneFor​(Query q)  
      boolean equals​(java.lang.Object o)  
      static QueryProfileType getArgumentType()  
      java.lang.String getDefaultIndex()
      Returns the default index for this query.
      java.lang.String getDocumentDb()
      Returns the name of the document db this should search, or null if not set.
      java.lang.String getEncoding()
      Returns the encoding used in the query as a lowercase string
      Execution getExecution()
      Returns the Execution working on this, or a null execution if none.
      java.lang.String getFilter()
      Returns the filter string set for this query.
      static Model getFrom​(Query q)  
      com.yahoo.language.Language getLanguage()
      Returns the explicitly set parsing language of this query model, or null if none
      java.util.Locale getLocale()
      Returns the explicitly set parsing locale of this query model, or null if none.
      Query getParent()
      returns the query owning this, never null
      com.yahoo.language.Language getParsingLanguage()  
      com.yahoo.language.Language getParsingLanguage​(java.lang.String languageDetectionText)
      Gets the language to use for parsing.
      java.lang.String getQueryString()
      Returns the query string which caused the original query tree of this model to come about.
      QueryTree getQueryTree()
      Returns the query as an object structure.
      java.util.Set<java.lang.String> getRestrict()
      Returns the set of types this query will search.
      java.lang.String getSearchPath()  
      java.util.Set<java.lang.String> getSources()
      Returns the set of sources this query will search.
      Query.Type getType()
      Sets the query type of for this query.
      int hashCode()  
      void prepare​(Ranking ranking)
      Prepares this for binary serialization.
      void setDefaultIndex​(java.lang.String defaultIndex)
      Sets the default index for this query.
      void setDocumentDb​(java.lang.String documentDbName)
      Sets the document database this will search - a document type
      void setEncoding​(java.lang.String encoding)
      Sets the encoding which was used in the received query string
      void setExecution​(Execution execution)
      Sets the execution working on this.
      void setFilter​(java.lang.String filter)
      Sets the filter string set for this query.
      void setLanguage​(com.yahoo.language.Language language)
      Explicitly sets the language to be used during parsing
      void setLanguage​(java.lang.String language)
      Explicitly sets the language to be used during parsing.
      void setLocale​(java.lang.String languageTag)
      Explicitly sets the locale to be used during parsing.
      void setLocale​(java.util.Locale locale)
      Explicitly sets the locale to be used during parsing.
      void setParent​(Query parent)
      Assigns the query owning this
      void setQueryString​(java.lang.String queryString)
      Set the query from a string.
      void setRestrict​(java.lang.String restrictString)
      Sets the set of types (document type or search definition names) this query will search from a comma-separated string of type names.
      void setSearchPath​(java.lang.String searchPath)
      Set the path for which backend nodes to forward the search too.
      void setSources​(java.lang.String sourceString)
      Sets the set of sources this query will search from a comma-separated string of source names
      void setType​(Query.Type type)
      Sets the query type of for this query.
      void setType​(java.lang.String typeString)
      Sets the query type of for this query.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Model

        public Model​(Query query)
    • Method Detail

      • getParsingLanguage

        public com.yahoo.language.Language getParsingLanguage()
      • getParsingLanguage

        public com.yahoo.language.Language getParsingLanguage​(java.lang.String languageDetectionText)
        Gets the language to use for parsing. If this is explicitly set in the model, that language is returned. Otherwise, if a query tree is already produced and any node in it specifies a language the first such node encountered in a depth first left to right search is returned. Otherwise the language is guessed from the query string. If this does not yield an actual language, English is returned as the default.
        Returns:
        the language determined, never null
      • getLanguage

        public com.yahoo.language.Language getLanguage()
        Returns the explicitly set parsing language of this query model, or null if none
      • setLanguage

        public void setLanguage​(com.yahoo.language.Language language)
        Explicitly sets the language to be used during parsing
      • setLanguage

        public void setLanguage​(java.lang.String language)
        Explicitly sets the language to be used during parsing. The argument is first normalized by replacing underscores with hyphens (to support locale strings being used as RFC 5646 language tags), and then forwarded to setLocale(String) so that the Locale information of the tag is preserved.
        Parameters:
        language - The language string to parse.
        See Also:
        getLanguage(), setLocale(String)
      • getLocale

        public java.util.Locale getLocale()
        Returns the explicitly set parsing locale of this query model, or null if none.
        Returns:
        the locale of this
        See Also:
        setLocale(Locale)
      • setLocale

        public void setLocale​(java.util.Locale locale)
        Explicitly sets the locale to be used during parsing. This method also calls setLanguage(Language) with the corresponding Language instance.
        Parameters:
        locale - the locale to set
        See Also:
        getLocale(), setLanguage(Language)
      • setLocale

        public void setLocale​(java.lang.String languageTag)
        Explicitly sets the locale to be used during parsing. This creates a Locale instance from the given language tag, and passes that to setLocale(Locale).
        Parameters:
        languageTag - the language tag to parse
        See Also:
        setLocale(Locale)
      • getEncoding

        public java.lang.String getEncoding()
        Returns the encoding used in the query as a lowercase string
      • setEncoding

        public void setEncoding​(java.lang.String encoding)
        Sets the encoding which was used in the received query string
      • setSearchPath

        public void setSearchPath​(java.lang.String searchPath)
        Set the path for which backend nodes to forward the search too.
      • getSearchPath

        public java.lang.String getSearchPath()
      • setQueryString

        public void setQueryString​(java.lang.String queryString)
        Set the query from a string. This will not be parsed into a query tree until that tree is attempted accessed. Note that setting this will clear the current query tree. Usually, this should not be modified - changes to the query should be implemented as modifications on the query tree structure.

        Passing null causes this to be set to an empty string.

      • getQueryString

        public java.lang.String getQueryString()
        Returns the query string which caused the original query tree of this model to come about. Note that changes to the query tree are not reflected in this query string. Note that changes to the query tree are not reflected in this query string.
        Returns:
        the original (or reassigned) query string - never null
      • getQueryTree

        public QueryTree getQueryTree()
        Returns the query as an object structure. Remember to have the correct Query.Type set. This causes parsing of the query string if it has changed since this was last called (i.e query parsing is lazy)
      • clearQueryTree

        public void clearQueryTree()
        Clears the parsed query such that it will be created anew from the textual representation (a query string or select.where expression) on the next access.
      • getFilter

        public java.lang.String getFilter()
        Returns the filter string set for this query. The filter is included in the query tree at the time the query tree is parsed
      • setFilter

        public void setFilter​(java.lang.String filter)
        Sets the filter string set for this query. The filter is included in the query tree at the time the query tree is parsed. Setting this does not cause the query to be reparsed.
      • getDefaultIndex

        public java.lang.String getDefaultIndex()
        Returns the default index for this query. The default index is taken into account at the time the query tree is parsed.
      • setDefaultIndex

        public void setDefaultIndex​(java.lang.String defaultIndex)
        Sets the default index for this query. The default index is taken into account at the time the query tree is parsed. Setting this does not cause the query to be reparsed.
      • getType

        public Query.Type getType()
        Sets the query type of for this query. The type is taken into account at the time the query tree is parsed.
      • setType

        public void setType​(Query.Type type)
        Sets the query type of for this query. The type is taken into account at the time the query tree is parsed. Setting this does not cause the query to be reparsed.
      • setType

        public void setType​(java.lang.String typeString)
        Sets the query type of for this query. The type is taken into account at the time the query tree is parsed. Setting this does not cause the query to be reparsed.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • clone

        public java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object
      • getParent

        public Query getParent()
        returns the query owning this, never null
      • setParent

        public void setParent​(Query parent)
        Assigns the query owning this
      • setSources

        public void setSources​(java.lang.String sourceString)
        Sets the set of sources this query will search from a comma-separated string of source names
      • getSources

        public java.util.Set<java.lang.String> getSources()
        Returns the set of sources this query will search. This set can be modified to change the set of sources. If all sources are to be searched, this returns an empty set
        Returns:
        the set of sources to search, never null
      • setRestrict

        public void setRestrict​(java.lang.String restrictString)
        Sets the set of types (document type or search definition names) this query will search from a comma-separated string of type names. This is useful to narrow a search to just a subset of the types available from a sources
      • getRestrict

        public java.util.Set<java.lang.String> getRestrict()
        Returns the set of types this query will search. This set can be modified to change the set of types. If all types are to be searched, this returns an empty set.
        Returns:
        the set of types to search, never null
      • setExecution

        public void setExecution​(Execution execution)
        Sets the execution working on this. For internal use.
      • setDocumentDb

        public void setDocumentDb​(java.lang.String documentDbName)
        Sets the document database this will search - a document type
      • getDocumentDb

        public java.lang.String getDocumentDb()
        Returns the name of the document db this should search, or null if not set.
      • getExecution

        public Execution getExecution()
        Returns the Execution working on this, or a null execution if none. For internal use.
      • getFrom

        public static Model getFrom​(Query q)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • prepare

        public void prepare​(Ranking ranking)
        Prepares this for binary serialization. For internal use.