Package com.yahoo.searchdefinition
Class SchemaBuilder
- java.lang.Object
-
- com.yahoo.searchdefinition.SchemaBuilder
-
public class SchemaBuilder extends Object
Helper class for buildingSchema
s. 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 thegetSchema(String)
method.
-
-
Constructor Summary
Constructors Constructor Description SchemaBuilder()
For testing onlySchemaBuilder(boolean documentsOnly)
Used for generating documents for typed access to document fields in JavaSchemaBuilder(com.yahoo.config.application.api.ApplicationPackage app, com.yahoo.config.application.api.DeployLogger deployLogger)
For testing onlySchemaBuilder(com.yahoo.config.application.api.ApplicationPackage app, com.yahoo.config.application.api.DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry)
For testing onlySchemaBuilder(com.yahoo.config.application.api.ApplicationPackage app, com.yahoo.config.application.api.FileRegistry fileRegistry, com.yahoo.config.application.api.DeployLogger deployLogger, com.yahoo.config.model.api.ModelContext.Properties properties, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
SchemaBuilder(com.yahoo.config.application.api.DeployLogger deployLogger)
For testing onlySchemaBuilder(com.yahoo.config.application.api.DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry)
For testing onlySchemaBuilder(RankProfileRegistry rankProfileRegistry)
For testing onlySchemaBuilder(RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
For testing onlySchemaBuilder(RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry, com.yahoo.config.model.api.ModelContext.Properties properties)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Application
application()
void
build()
Processes and finalizes the schemas of this.void
build(boolean validate)
Processes and finalizes the schemas of this.static Schema
buildFromFile(String fileName)
Convenience factory method to import and build aSchema
object from a file.static Schema
buildFromFile(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 aSchema
from a file.static Schema
buildFromFile(String fileName, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
Convenience factory method to import and build aSchema
object from a file.static Schema
buildFromRawSchema(Schema rawSchema, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
Convenience factory method to import and build aSchema
object from a raw object.static SchemaBuilder
createFromDirectory(String dir, com.yahoo.config.application.api.FileRegistry fileRegistry, com.yahoo.config.application.api.DeployLogger logger, com.yahoo.config.model.api.ModelContext.Properties properties)
static SchemaBuilder
createFromDirectory(String dir, com.yahoo.config.application.api.FileRegistry fileRegistry, com.yahoo.config.application.api.DeployLogger logger, com.yahoo.config.model.api.ModelContext.Properties properties, RankProfileRegistry rankProfileRegistry)
static SchemaBuilder
createFromFile(String fileName)
Convenience factory method to import and build aSchema
object from a file.static SchemaBuilder
createFromFile(String fileName, com.yahoo.config.application.api.DeployLogger logger)
static SchemaBuilder
createFromFiles(Collection<String> fileNames)
Convenience factory methdd to create a SearchBuilder from multiple SD files.static SchemaBuilder
createFromRawSchema(Schema rawSchema, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
Convenience factory method to import and build aSchema
object from a raw object.static SchemaBuilder
createFromString(String sd)
Convenience factory method to import and build aSchema
object from a string.static SchemaBuilder
createFromString(String sd, com.yahoo.config.application.api.DeployLogger logger)
static SchemaBuilder
createFromStrings(com.yahoo.config.application.api.DeployLogger logger, String... schemas)
com.yahoo.config.application.api.DeployLogger
getDeployLogger()
DocumentModel
getModel()
com.yahoo.config.model.api.ModelContext.Properties
getProperties()
com.yahoo.search.query.profile.QueryProfileRegistry
getQueryProfileRegistry()
RankProfileRegistry
getRankProfileRegistry()
Schema
getSchema()
Convenience method to callgetSchema(String)
when there is only a singleSchema
object built.Schema
getSchema(String name)
Returns the builtSchema
object that has the given name.List<Schema>
getSchemaList()
Convenience method to return a list of all builtSchema
objects.String
importFile(String fileName)
Import search definition.String
importRawSchema(Schema schema)
Registers the given schema to the application to be built duringbuild()
.String
importReader(com.yahoo.io.reader.NamedReader reader, String searchDefDir)
Reads and parses the search definition string provided by the given reader.String
importString(String str)
Import search definition.Set<Class<? extends Processor>>
processorsToSkip()
Returns a modifiable set of processors we should skip for these schemas.
-
-
-
Constructor Detail
-
SchemaBuilder
public SchemaBuilder()
For testing only
-
SchemaBuilder
public SchemaBuilder(com.yahoo.config.application.api.DeployLogger deployLogger)
For testing only
-
SchemaBuilder
public SchemaBuilder(com.yahoo.config.application.api.DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry)
For testing only
-
SchemaBuilder
public SchemaBuilder(boolean documentsOnly)
Used for generating documents for typed access to document fields in Java
-
SchemaBuilder
public SchemaBuilder(com.yahoo.config.application.api.ApplicationPackage app, com.yahoo.config.application.api.DeployLogger deployLogger)
For testing only
-
SchemaBuilder
public SchemaBuilder(com.yahoo.config.application.api.ApplicationPackage app, com.yahoo.config.application.api.DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry)
For testing only
-
SchemaBuilder
public SchemaBuilder(RankProfileRegistry rankProfileRegistry)
For testing only
-
SchemaBuilder
public SchemaBuilder(RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
For testing only
-
SchemaBuilder
public SchemaBuilder(RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry, com.yahoo.config.model.api.ModelContext.Properties properties)
-
SchemaBuilder
public SchemaBuilder(com.yahoo.config.application.api.ApplicationPackage app, com.yahoo.config.application.api.FileRegistry fileRegistry, com.yahoo.config.application.api.DeployLogger deployLogger, com.yahoo.config.model.api.ModelContext.Properties properties, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
-
-
Method Detail
-
importFile
public String importFile(String fileName) throws IOException, ParseException
Import search definition.- Parameters:
fileName
- the name of the file to import- Returns:
- the name of the imported object
- Throws:
IOException
- thrown if the file can not be read for some reasonParseException
- thrown if the file does not contain a valid search definition
-
importReader
public String importReader(com.yahoo.io.reader.NamedReader reader, String searchDefDir) throws 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 importsearchDefDir
- 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 definitionIOException
-
importString
public String importString(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
-
importRawSchema
public String importRawSchema(Schema schema)
Registers the given schema to the application to be built duringbuild()
. ASchema
object is considered to be "raw" if it has not already been processed. This is the case for most programmatically constructed schemas used in unit tests.- Parameters:
schema
- the object to import- Returns:
- the name of the imported object
- Throws:
IllegalArgumentException
- if the given search object has already been processed
-
build
public void build()
Processes and finalizes the schemas of this. Only for testing.- Throws:
IllegalStateException
- Thrown if this method has already been called.
-
build
public void build(boolean validate)
Processes and finalizes the schemas of this.- Throws:
IllegalStateException
- thrown if this method has already been called
-
processorsToSkip
public Set<Class<? extends Processor>> processorsToSkip()
Returns a modifiable set of processors we should skip for these schemas. Useful for testing.
-
getSchema
public Schema getSchema()
Convenience method to callgetSchema(String)
when there is only a singleSchema
object built. This method will never return null.- Returns:
- the built object
- Throws:
IllegalStateException
- if there is not exactly one search.
-
getModel
public DocumentModel getModel()
-
getSchema
public Schema getSchema(String name)
Returns the builtSchema
object that has the given name. If the name is unknown, this method will simply return null.- Parameters:
name
- the name of the schema 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:
IllegalStateException
- ifbuild()
has not been called.
-
application
public Application application()
-
getSchemaList
public List<Schema> getSchemaList()
Convenience method to return a list of all builtSchema
objects.- Returns:
- the list of built searches
-
createFromString
public static SchemaBuilder createFromString(String sd) throws ParseException
Convenience factory method to import and build aSchema
object from a string.- Parameters:
sd
- the string to build from- Returns:
- the built
SchemaBuilder
object - Throws:
ParseException
- thrown if there is a problem parsing the string
-
createFromString
public static SchemaBuilder createFromString(String sd, com.yahoo.config.application.api.DeployLogger logger) throws ParseException
- Throws:
ParseException
-
createFromStrings
public static SchemaBuilder createFromStrings(com.yahoo.config.application.api.DeployLogger logger, String... schemas) throws ParseException
- Throws:
ParseException
-
createFromFile
public static SchemaBuilder createFromFile(String fileName) throws IOException, ParseException
Convenience factory method to import and build aSchema
object from a file. Only for testing.- Parameters:
fileName
- the file to build from- Returns:
- the built
SchemaBuilder
object - Throws:
IOException
- if there was a problem reading the file.ParseException
- if there was a problem parsing the file content.
-
createFromFiles
public static SchemaBuilder createFromFiles(Collection<String> fileNames) throws IOException, ParseException
Convenience factory methdd to create a SearchBuilder from multiple SD files. Only for testing.- Throws:
IOException
ParseException
-
createFromFile
public static SchemaBuilder createFromFile(String fileName, com.yahoo.config.application.api.DeployLogger logger) throws IOException, ParseException
- Throws:
IOException
ParseException
-
createFromDirectory
public static SchemaBuilder createFromDirectory(String dir, com.yahoo.config.application.api.FileRegistry fileRegistry, com.yahoo.config.application.api.DeployLogger logger, com.yahoo.config.model.api.ModelContext.Properties properties) throws IOException, ParseException
- Throws:
IOException
ParseException
-
createFromDirectory
public static SchemaBuilder createFromDirectory(String dir, com.yahoo.config.application.api.FileRegistry fileRegistry, com.yahoo.config.application.api.DeployLogger logger, com.yahoo.config.model.api.ModelContext.Properties properties, RankProfileRegistry rankProfileRegistry) throws IOException, ParseException
- Throws:
IOException
ParseException
-
buildFromFile
public static Schema buildFromFile(String fileName) throws IOException, ParseException
Convenience factory method to import and build aSchema
object from a file. Only for testing.- Parameters:
fileName
- the file to build from- Returns:
- the built
Schema
object - Throws:
IOException
- thrown if there was a problem reading the fileParseException
- thrown if there was a problem parsing the file content
-
buildFromFile
public static Schema buildFromFile(String fileName, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry) throws IOException, ParseException
Convenience factory method to import and build aSchema
object from a file.- Parameters:
fileName
- the file to build fromrankProfileRegistry
- registry for rank profiles- Returns:
- the built
Schema
object - Throws:
IOException
- thrown if there was a problem reading the fileParseException
- thrown if there was a problem parsing the file content
-
buildFromFile
public static Schema buildFromFile(String fileName, com.yahoo.config.application.api.DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry) throws IOException, ParseException
Convenience factory method to import and build aSchema
from a file.- Parameters:
fileName
- the file to build fromdeployLogger
- logger for deploy messagesrankProfileRegistry
- registry for rank profiles- Returns:
- the built
Schema
object - Throws:
IOException
- thrown if there was a problem reading the fileParseException
- thrown if there was a problem parsing the file content
-
createFromRawSchema
public static SchemaBuilder createFromRawSchema(Schema rawSchema, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
Convenience factory method to import and build aSchema
object from a raw object.- Parameters:
rawSchema
- the raw object to build from- Returns:
- the built
SchemaBuilder
object - See Also:
importRawSchema(Schema)
-
buildFromRawSchema
public static Schema buildFromRawSchema(Schema rawSchema, RankProfileRegistry rankProfileRegistry, com.yahoo.search.query.profile.QueryProfileRegistry queryProfileRegistry)
Convenience factory method to import and build aSchema
object from a raw object.- Parameters:
rawSchema
- the raw object to build from- Returns:
- the built
Schema
object - See Also:
importRawSchema(Schema)
-
getRankProfileRegistry
public RankProfileRegistry getRankProfileRegistry()
-
getQueryProfileRegistry
public com.yahoo.search.query.profile.QueryProfileRegistry getQueryProfileRegistry()
-
getProperties
public com.yahoo.config.model.api.ModelContext.Properties getProperties()
-
getDeployLogger
public com.yahoo.config.application.api.DeployLogger getDeployLogger()
-
-