Package com.yahoo.searchdefinition
Class SearchBuilder
- java.lang.Object
-
- com.yahoo.searchdefinition.SearchBuilder
-
public class SearchBuilder extends java.lang.Object
Helper class for importingSearch
objects in an unambiguous way. The pattern for using this is to 1) Import all available search definitions, using the importXXX() methods, 2) provide the available rank types and rank expressions, using the setRankXXX() methods, 3) invoke thebuild()
method, and 4) retrieve the built search objects using thegetSearch(String)
method.
-
-
Constructor Summary
Constructors Constructor Description SearchBuilder()
For testing onlySearchBuilder(boolean documentsOnly)
Used for generating documents for typed access to document fields in JavaSearchBuilder(com.yahoo.config.application.api.ApplicationPackage app)
For testing onlySearchBuilder(com.yahoo.config.application.api.ApplicationPackage app, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
SearchBuilder(com.yahoo.config.application.api.ApplicationPackage app, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry, boolean documentsOnly)
SearchBuilder(RankProfileRegistry rankProfileRegistry)
For testing onlySearchBuilder(RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
For testing only
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
build()
Only for testing.void
build(boolean validate, com.yahoo.config.application.api.DeployLogger deployLogger)
Processes and finalizes the imported search definitions so that they become available through thegetSearch(String)
method.static Search
buildFromFile(java.lang.String fileName)
Convenience factory method to import and build aSearch
object from a file.static Search
buildFromFile(java.lang.String fileName, com.yahoo.config.application.api.DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
Convenience factory method to import and build aSearch
object from a file.static Search
buildFromFile(java.lang.String fileName, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
Convenience factory method to import and build aSearch
object from a file.static Search
buildFromRawSearch(Search rawSearch, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
Convenience factory method to import and build aSearch
object from a raw object.static SearchBuilder
createFromDirectory(java.lang.String dir)
static SearchBuilder
createFromDirectory(java.lang.String dir, RankProfileRegistry rankProfileRegistry)
static SearchBuilder
createFromDirectory(java.lang.String dir, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
static SearchBuilder
createFromFile(java.lang.String fileName)
Convenience factory method to import and build aSearch
object from a file.static SearchBuilder
createFromFile(java.lang.String fileName, com.yahoo.config.application.api.DeployLogger logger)
static SearchBuilder
createFromFile(java.lang.String fileName, com.yahoo.config.application.api.DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryprofileRegistry)
Convenience factory method to import and build aSearch
object from a file.static SearchBuilder
createFromFiles(java.util.Collection<java.lang.String> fileNames)
Convenience factory methdd to create a SearchBuilder from multiple SD files.static SearchBuilder
createFromFiles(java.util.Collection<java.lang.String> fileNames, com.yahoo.config.application.api.DeployLogger logger)
static SearchBuilder
createFromFiles(java.util.Collection<java.lang.String> fileNames, com.yahoo.config.application.api.DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryprofileRegistry)
Convenience factory methdd to create a SearchBuilder from multiple SD files..static SearchBuilder
createFromRawSearch(Search rawSearch, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
Convenience factory method to import and build aSearch
object from a raw object.static SearchBuilder
createFromString(java.lang.String sd)
Convenience factory method to import and build aSearch
object from a string.static SearchBuilder
createFromString(java.lang.String sd, com.yahoo.config.application.api.DeployLogger logger)
DocumentModel
getModel()
com.yahoo.search.query.profile.QueryProfileRegistry
getQueryProfileRegistry()
RankProfileRegistry
getRankProfileRegistry()
Search
getSearch()
Convenience method to callgetSearch(String)
when there is only a singleSearch
object built.Search
getSearch(java.lang.String name)
Returns the builtSearch
object that has the given name.java.util.List<Search>
getSearchList()
Convenience method to return a list of all builtSearch
objects.java.lang.String
importFile(java.lang.String fileName)
Import search definition.java.lang.String
importFile(java.lang.String fileName, com.yahoo.config.application.api.DeployLogger deployLogger)
Import search definition.java.lang.String
importFile(java.nio.file.Path file)
java.lang.String
importRawSearch(Search rawSearch)
Registers the given search object to the internal list of objects to be processed duringbuild()
.java.lang.String
importReader(com.yahoo.io.reader.NamedReader reader, java.lang.String searchDefDir)
See #importReader(com.yahoo.io.reader.NamedReader, java.lang.String, com.yahoo.config.application.api.DeployLogger)
Convenience, should only be used for testing as logs will be swallowed.java.lang.String
importReader(com.yahoo.io.reader.NamedReader reader, java.lang.String searchDefDir, com.yahoo.config.application.api.DeployLogger deployLogger)
Reads and parses the search definition string provided by the given reader.java.lang.String
importString(java.lang.String str)
Import search definition.java.lang.String
importString(java.lang.String str, com.yahoo.config.application.api.DeployLogger logger)
Import search definition.protected void
process(Search search, com.yahoo.config.application.api.DeployLogger deployLogger, QueryProfiles queryProfiles, boolean validate)
Processes and returns the givenSearch
object.
-
-
-
Constructor Detail
-
SearchBuilder
public SearchBuilder()
For testing only
-
SearchBuilder
public SearchBuilder(boolean documentsOnly)
Used for generating documents for typed access to document fields in Java
-
SearchBuilder
public SearchBuilder(com.yahoo.config.application.api.ApplicationPackage app)
For testing only
-
SearchBuilder
public SearchBuilder(RankProfileRegistry rankProfileRegistry)
For testing only
-
SearchBuilder
public SearchBuilder(RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
For testing only
-
SearchBuilder
public SearchBuilder(com.yahoo.config.application.api.ApplicationPackage app, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
-
SearchBuilder
public SearchBuilder(com.yahoo.config.application.api.ApplicationPackage app, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry, boolean documentsOnly)
-
-
Method Detail
-
importFile
public java.lang.String importFile(java.lang.String fileName, com.yahoo.config.application.api.DeployLogger deployLogger) throws java.io.IOException, ParseException
Import search definition.- Parameters:
fileName
- The name of the file to import.deployLogger
- Logger for deploy messages.- Returns:
- The name of the imported object.
- Throws:
java.io.IOException
- Thrown if the file can not be read for some reason.ParseException
- Thrown if the file does not contain a valid search definition. ```
-
importFile
public java.lang.String importFile(java.lang.String fileName) throws java.io.IOException, ParseException
Import search definition.- Parameters:
fileName
- The name of the file to import.- Returns:
- The name of the imported object.
- Throws:
java.io.IOException
- Thrown if the file can not be read for some reason.ParseException
- Thrown if the file does not contain a valid search definition.
-
importFile
public java.lang.String importFile(java.nio.file.Path file) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
importReader
public java.lang.String importReader(com.yahoo.io.reader.NamedReader reader, java.lang.String searchDefDir, com.yahoo.config.application.api.DeployLogger deployLogger) throws java.io.IOException, ParseException
Reads and parses the search definition string provided by the given reader. Once all search definitions have been imported, callbuild()
.- Parameters:
reader
- The reader whose content to import.searchDefDir
- The path to use when resolving file references.- Returns:
- The name of the imported object.
- Throws:
ParseException
- Thrown if the file does not contain a valid search definition.java.io.IOException
-
importReader
public java.lang.String importReader(com.yahoo.io.reader.NamedReader reader, java.lang.String searchDefDir) throws java.io.IOException, ParseException
See #importReader(com.yahoo.io.reader.NamedReader, java.lang.String, com.yahoo.config.application.api.DeployLogger)
Convenience, should only be used for testing as logs will be swallowed.- Throws:
java.io.IOException
ParseException
-
importString
public java.lang.String importString(java.lang.String str) throws ParseException
Import search definition.- Parameters:
str
- the string to parse.- Returns:
- the name of the imported object.
- Throws:
ParseException
- thrown if the file does not contain a valid search definition.
-
importString
public java.lang.String importString(java.lang.String str, com.yahoo.config.application.api.DeployLogger logger) throws ParseException
Import search definition.- Parameters:
str
- the string to parse.- Returns:
- the name of the imported object.
- Throws:
ParseException
- thrown if the file does not contain a valid search definition.
-
importRawSearch
public java.lang.String importRawSearch(Search rawSearch)
Registers the given search object to the internal list of objects to be processed duringbuild()
. ASearch
object is considered to be "raw" if it has not already been processed. This is the case for most programmatically constructed search objects used in unit tests.- Parameters:
rawSearch
- the object to import.- Returns:
- the name of the imported object.
- Throws:
java.lang.IllegalArgumentException
- if the given search object has already been processed.
-
build
public void build()
Only for testing. Processes and finalizes the imported search definitions so that they become available through thegetSearch(String)
method.- Throws:
java.lang.IllegalStateException
- Thrown if this method has already been called.
-
build
public void build(boolean validate, com.yahoo.config.application.api.DeployLogger deployLogger)
Processes and finalizes the imported search definitions so that they become available through thegetSearch(String)
method.- Parameters:
deployLogger
- The logger to use during build- Throws:
java.lang.IllegalStateException
- Thrown if this method has already been called.
-
process
protected void process(Search search, com.yahoo.config.application.api.DeployLogger deployLogger, QueryProfiles queryProfiles, boolean validate)
-
getSearch
public Search getSearch()
Convenience method to callgetSearch(String)
when there is only a singleSearch
object built. This method will never return null.- Returns:
- the built object
- Throws:
java.lang.IllegalStateException
- if there is not exactly one search.
-
getModel
public DocumentModel getModel()
-
getSearch
public Search getSearch(java.lang.String name)
Returns the builtSearch
object that has the given name. If the name is unknown, this method will simply return null.- Parameters:
name
- the name of the search definition to return, or null to return the only one or throw an exception if there are multiple to choose from- Returns:
- the built object, or null if none with this name
- Throws:
java.lang.IllegalStateException
- ifbuild()
has not been called.
-
getSearchList
public java.util.List<Search> getSearchList()
Convenience method to return a list of all builtSearch
objects.- Returns:
- The list of built searches.
-
createFromString
public static SearchBuilder createFromString(java.lang.String sd) throws ParseException
Convenience factory method to import and build aSearch
object from a string.- Parameters:
sd
- The string to build from.- Returns:
- The built
SearchBuilder
object. - Throws:
ParseException
- Thrown if there was a problem parsing the string.
-
createFromString
public static SearchBuilder createFromString(java.lang.String sd, com.yahoo.config.application.api.DeployLogger logger) throws ParseException
- Throws:
ParseException
-
createFromFile
public static SearchBuilder createFromFile(java.lang.String fileName) throws java.io.IOException, ParseException
Convenience factory method to import and build aSearch
object from a file. Only for testing.- Parameters:
fileName
- the file to build from- Returns:
- the built
SearchBuilder
object - Throws:
java.io.IOException
- if there was a problem reading the file.ParseException
- if there was a problem parsing the file content.
-
createFromFiles
public static SearchBuilder createFromFiles(java.util.Collection<java.lang.String> fileNames) throws java.io.IOException, ParseException
Convenience factory methdd to create a SearchBuilder from multiple SD files. Only for testing.- Throws:
java.io.IOException
ParseException
-
createFromFile
public static SearchBuilder createFromFile(java.lang.String fileName, com.yahoo.config.application.api.DeployLogger logger) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
createFromFiles
public static SearchBuilder createFromFiles(java.util.Collection<java.lang.String> fileNames, com.yahoo.config.application.api.DeployLogger logger) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
createFromFile
public static SearchBuilder createFromFile(java.lang.String fileName, com.yahoo.config.application.api.DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryprofileRegistry) throws java.io.IOException, ParseException
Convenience factory method to import and build aSearch
object from a file.- Parameters:
fileName
- the file to build from.deployLogger
- logger for deploy messages.rankProfileRegistry
- registry for rank profiles.- Returns:
- the built
SearchBuilder
object. - Throws:
java.io.IOException
- if there was a problem reading the file.ParseException
- if there was a problem parsing the file content.
-
createFromFiles
public static SearchBuilder createFromFiles(java.util.Collection<java.lang.String> fileNames, com.yahoo.config.application.api.DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryprofileRegistry) throws java.io.IOException, ParseException
Convenience factory methdd to create a SearchBuilder from multiple SD files..- Throws:
java.io.IOException
ParseException
-
createFromDirectory
public static SearchBuilder createFromDirectory(java.lang.String dir) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
createFromDirectory
public static SearchBuilder createFromDirectory(java.lang.String dir, RankProfileRegistry rankProfileRegistry) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
createFromDirectory
public static SearchBuilder createFromDirectory(java.lang.String dir, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
buildFromFile
public static Search buildFromFile(java.lang.String fileName) throws java.io.IOException, ParseException
Convenience factory method to import and build aSearch
object from a file. Only for testing.- Parameters:
fileName
- The file to build from.- Returns:
- The built
Search
object. - Throws:
java.io.IOException
- Thrown if there was a problem reading the file.ParseException
- Thrown if there was a problem parsing the file content.
-
buildFromFile
public static Search buildFromFile(java.lang.String fileName, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry) throws java.io.IOException, ParseException
Convenience factory method to import and build aSearch
object from a file.- Parameters:
fileName
- The file to build from.rankProfileRegistry
- Registry for rank profiles.- Returns:
- The built
Search
object. - Throws:
java.io.IOException
- Thrown if there was a problem reading the file.ParseException
- Thrown if there was a problem parsing the file content.
-
buildFromFile
public static Search buildFromFile(java.lang.String fileName, com.yahoo.config.application.api.DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry) throws java.io.IOException, ParseException
Convenience factory method to import and build aSearch
object from a file.- Parameters:
fileName
- The file to build from.deployLogger
- Logger for deploy messages.rankProfileRegistry
- Registry for rank profiles.- Returns:
- The built
Search
object. - Throws:
java.io.IOException
- Thrown if there was a problem reading the file.ParseException
- Thrown if there was a problem parsing the file content.
-
createFromRawSearch
public static SearchBuilder createFromRawSearch(Search rawSearch, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
Convenience factory method to import and build aSearch
object from a raw object.- Parameters:
rawSearch
- the raw object to build from.- Returns:
- the built
SearchBuilder
object. - See Also:
importRawSearch(Search)
-
buildFromRawSearch
public static Search buildFromRawSearch(Search rawSearch, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
Convenience factory method to import and build aSearch
object from a raw object.- Parameters:
rawSearch
- The raw object to build from.- Returns:
- The built
Search
object. - See Also:
importRawSearch(Search)
-
getRankProfileRegistry
public RankProfileRegistry getRankProfileRegistry()
-
getQueryProfileRegistry
public com.yahoo.search.query.profile.QueryProfileRegistry getQueryProfileRegistry()
-
-