summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/SchemaBuilder.java
diff options
context:
space:
mode:
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition/SchemaBuilder.java')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/SchemaBuilder.java110
1 files changed, 53 insertions, 57 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/SchemaBuilder.java b/config-model/src/main/java/com/yahoo/searchdefinition/SchemaBuilder.java
index ae849b0b538..76385a87d83 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/SchemaBuilder.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/SchemaBuilder.java
@@ -35,15 +35,14 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
import java.util.Set;
/**
- * Helper class for importing {@link Schema} objects in an unambiguous way. The pattern for using this is to 1) Import
+ * Helper class for building {@link Schema}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 the {@link #build()} method, and 4) retrieve the built
- * search objects using the {@link #getSearch(String)} method.
+ * search objects using the {@link #getSchema(String)} method.
*/
// NOTE: Since this was created we have added Application, and much of the content in this should migrate there.
public class SchemaBuilder {
@@ -161,9 +160,9 @@ public class SchemaBuilder {
/**
* Import search definition.
*
- * @param str the string to parse.
- * @return the name of the imported object.
- * @throws ParseException thrown if the file does not contain a valid search definition.
+ * @param str the string to parse
+ * @return the name of the imported object
+ * @throws ParseException thrown if the file does not contain a valid search definition
*/
public String importString(String str) throws ParseException {
return importString(str, null);
@@ -172,7 +171,7 @@ public class SchemaBuilder {
private String importString(String str, String searchDefDir) throws ParseException {
SimpleCharStream stream = new SimpleCharStream(str);
try {
- return importRawSearch(new SDParser(stream, fileRegistry, deployLogger, properties, application,
+ return importRawSchema(new SDParser(stream, fileRegistry, deployLogger, properties, application,
application.rankProfileRegistry(), documentsOnly)
.schema(docTypeMgr, searchDefDir));
} catch (TokenMgrException e) {
@@ -183,15 +182,15 @@ public class SchemaBuilder {
}
/**
- * Registers the given search object to the internal list of objects to be processed during {@link #build()}. A
+ * Registers the given schema to the application to be built during {@link #build()}. A
* {@link Schema} 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.
+ * programmatically constructed schemas used in unit tests.
*
- * @param schema the object to import.
- * @return the name of the imported object.
- * @throws IllegalArgumentException if the given search object has already been processed.
+ * @param schema the object to import
+ * @return the name of the imported object
+ * @throws IllegalArgumentException if the given search object has already been processed
*/
- public String importRawSearch(Schema schema) {
+ public String importRawSchema(Schema schema) {
if (schema.getName() == null)
throw new IllegalArgumentException("Schema has no name");
String rawName = schema.getName();
@@ -200,11 +199,9 @@ public class SchemaBuilder {
}
/**
+ * Processes and finalizes the schemas of this.
* Only for testing.
*
- * Processes and finalizes the imported search definitions so that they become available through the {@link
- * #getSearch(String)} method.
- *
* @throws IllegalStateException Thrown if this method has already been called.
*/
public void build() {
@@ -212,13 +209,12 @@ public class SchemaBuilder {
}
/**
- * Processes and finalizes the imported search definitions so that they become available through the {@link
- * #getSearch(String)} method.
+ * Processes and finalizes the schemas of this.
*
* @throws IllegalStateException thrown if this method has already been called
*/
public void build(boolean validate) {
- if (isBuilt) throw new IllegalStateException("Model already built");
+ if (isBuilt) throw new IllegalStateException("Application already built");
if (validate)
application.validate(deployLogger);
@@ -270,14 +266,14 @@ public class SchemaBuilder {
}
/**
- * Convenience method to call {@link #getSearch(String)} when there is only a single {@link Schema} object
+ * Convenience method to call {@link #getSchema(String)} when there is only a single {@link Schema} object
* built. This method will never return null.
*
* @return the built object
* @throws IllegalStateException if there is not exactly one search.
*/
- public Schema getSearch() {
- if ( ! isBuilt) throw new IllegalStateException("Searches not built.");
+ public Schema getSchema() {
+ if ( ! isBuilt) throw new IllegalStateException("Application not built.");
if (application.schemas().size() != 1)
throw new IllegalStateException("This call only works if we have 1 schema. Schemas: " +
application.schemas().values());
@@ -293,14 +289,14 @@ public class SchemaBuilder {
* Returns the built {@link Schema} object that has the given name. If the name is unknown, this method will simply
* return null.
*
- * @param name the name of the search definition to return,
+ * @param 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
* @return the built object, or null if none with this name
* @throws IllegalStateException if {@link #build()} has not been called.
*/
- public Schema getSearch(String name) {
- if ( ! isBuilt) throw new IllegalStateException("Searches not built.");
- if (name == null) return getSearch();
+ public Schema getSchema(String name) {
+ if ( ! isBuilt) throw new IllegalStateException("Application not built.");
+ if (name == null) return getSchema();
return application.schemas().get(name);
}
@@ -311,16 +307,16 @@ public class SchemaBuilder {
*
* @return the list of built searches
*/
- public List<Schema> getSearchList() {
+ public List<Schema> getSchemaList() {
return new ArrayList<>(application.schemas().values());
}
/**
* Convenience factory method to import and build a {@link Schema} object from a string.
*
- * @param sd The string to build from.
- * @return The built {@link SchemaBuilder} object.
- * @throws ParseException Thrown if there was a problem parsing the string.
+ * @param sd the string to build from
+ * @return the built {@link SchemaBuilder} object
+ * @throws ParseException thrown if there is a problem parsing the string
*/
public static SchemaBuilder createFromString(String sd) throws ParseException {
return createFromString(sd, new BaseDeployLogger());
@@ -462,10 +458,10 @@ public class SchemaBuilder {
/**
* Convenience factory method to import and build a {@link Schema} object from a file. Only for testing.
*
- * @param fileName The file to build from.
- * @return The built {@link Schema} object.
- * @throws IOException Thrown if there was a problem reading the file.
- * @throws ParseException Thrown if there was a problem parsing the file content.
+ * @param fileName the file to build from
+ * @return the built {@link Schema} object
+ * @throws IOException thrown if there was a problem reading the file
+ * @throws ParseException thrown if there was a problem parsing the file content
*/
public static Schema buildFromFile(String fileName) throws IOException, ParseException {
return buildFromFile(fileName, new BaseDeployLogger(), new RankProfileRegistry(), new QueryProfileRegistry());
@@ -474,11 +470,11 @@ public class SchemaBuilder {
/**
* Convenience factory method to import and build a {@link Schema} object from a file.
*
- * @param fileName The file to build from.
- * @param rankProfileRegistry Registry for rank profiles.
- * @return The built {@link Schema} object.
- * @throws IOException Thrown if there was a problem reading the file.
- * @throws ParseException Thrown if there was a problem parsing the file content.
+ * @param fileName the file to build from
+ * @param rankProfileRegistry registry for rank profiles
+ * @return the built {@link Schema} object
+ * @throws IOException thrown if there was a problem reading the file
+ * @throws ParseException thrown if there was a problem parsing the file content
*/
public static Schema buildFromFile(String fileName,
RankProfileRegistry rankProfileRegistry,
@@ -488,35 +484,35 @@ public class SchemaBuilder {
}
/**
- * Convenience factory method to import and build a {@link Schema} object from a file.
+ * Convenience factory method to import and build a {@link Schema} from a file.
*
- * @param fileName The file to build from.
- * @param deployLogger Logger for deploy messages.
- * @param rankProfileRegistry Registry for rank profiles.
- * @return The built {@link Schema} object.
- * @throws IOException Thrown if there was a problem reading the file.
- * @throws ParseException Thrown if there was a problem parsing the file content.
+ * @param fileName the file to build from
+ * @param deployLogger logger for deploy messages
+ * @param rankProfileRegistry registry for rank profiles
+ * @return the built {@link Schema} object
+ * @throws IOException thrown if there was a problem reading the file
+ * @throws ParseException thrown if there was a problem parsing the file content
*/
public static Schema buildFromFile(String fileName,
DeployLogger deployLogger,
RankProfileRegistry rankProfileRegistry,
QueryProfileRegistry queryProfileRegistry)
throws IOException, ParseException {
- return createFromFile(fileName, deployLogger, rankProfileRegistry, queryProfileRegistry).getSearch();
+ return createFromFile(fileName, deployLogger, rankProfileRegistry, queryProfileRegistry).getSchema();
}
/**
* Convenience factory method to import and build a {@link Schema} object from a raw object.
*
- * @param rawSchema the raw object to build from.
- * @return the built {@link SchemaBuilder} object.
- * @see #importRawSearch(Schema)
+ * @param rawSchema the raw object to build from
+ * @return the built {@link SchemaBuilder} object
+ * @see #importRawSchema(Schema)
*/
- public static SchemaBuilder createFromRawSearch(Schema rawSchema,
+ public static SchemaBuilder createFromRawSchema(Schema rawSchema,
RankProfileRegistry rankProfileRegistry,
QueryProfileRegistry queryProfileRegistry) {
SchemaBuilder builder = new SchemaBuilder(rankProfileRegistry, queryProfileRegistry);
- builder.importRawSearch(rawSchema);
+ builder.importRawSchema(rawSchema);
builder.build();
return builder;
}
@@ -524,14 +520,14 @@ public class SchemaBuilder {
/**
* Convenience factory method to import and build a {@link Schema} object from a raw object.
*
- * @param rawSchema The raw object to build from.
- * @return The built {@link Schema} object.
- * @see #importRawSearch(Schema)
+ * @param rawSchema the raw object to build from
+ * @return the built {@link Schema} object
+ * @see #importRawSchema(Schema)
*/
- public static Schema buildFromRawSearch(Schema rawSchema,
+ public static Schema buildFromRawSchema(Schema rawSchema,
RankProfileRegistry rankProfileRegistry,
QueryProfileRegistry queryProfileRegistry) {
- return createFromRawSearch(rawSchema, rankProfileRegistry, queryProfileRegistry).getSearch();
+ return createFromRawSchema(rawSchema, rankProfileRegistry, queryProfileRegistry).getSchema();
}
public RankProfileRegistry getRankProfileRegistry() {