diff options
author | Arne H Juul <arnej27959@users.noreply.github.com> | 2022-02-23 17:39:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-23 17:39:27 +0100 |
commit | 3be99cd2b3c48f5a457c9647ffb87a20b9f88332 (patch) | |
tree | e8b53b4cf631c6de5f7f9f750136c7de0c75f928 /config-model | |
parent | 09039a14a0f27e7d3dadfc22cb72a8d0d10f9d65 (diff) | |
parent | 1139a476ac85bcc1fb59066ab32c6506e0f99246 (diff) |
Merge pull request #21341 from vespa-engine/arnej/intermediate-parser-3
convert rest of productions
Diffstat (limited to 'config-model')
18 files changed, 806 insertions, 419 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/DictionaryOption.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/DictionaryOption.java new file mode 100644 index 00000000000..095add74dd2 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/DictionaryOption.java @@ -0,0 +1,5 @@ +package com.yahoo.searchdefinition.parser; + +public enum DictionaryOption { + HASH, BTREE, CASED, UNCASED +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/MatchAlgorithm.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/MatchAlgorithm.java new file mode 100644 index 00000000000..92dc75a9eda --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/MatchAlgorithm.java @@ -0,0 +1,11 @@ +package com.yahoo.searchdefinition.parser; + +public enum MatchAlgorithm { + NORMAL("normal"), + PREFIX("prefix"), + SUBSTRING("substring"), + SUFFIX("suffix"); + private String name; + MatchAlgorithm(String name) { this.name = name; } + public String getName() { return name; } +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/MatchCase.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/MatchCase.java new file mode 100644 index 00000000000..30e968873ec --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/MatchCase.java @@ -0,0 +1,10 @@ +package com.yahoo.searchdefinition.parser; + +public enum MatchCase { + CASED("cased"), + UNCASED("uncased"); + private String name; + MatchCase(String name) { this.name = name; } + public String getName() { return name;} +} + diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/MatchType.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/MatchType.java new file mode 100644 index 00000000000..cd24db6d72e --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/MatchType.java @@ -0,0 +1,11 @@ +package com.yahoo.searchdefinition.parser; + +public enum MatchType { + TEXT("text"), + WORD("word"), + EXACT("exact"), + GRAM("gram"); + private String name; + MatchType(String name) { this.name = name; } + public String getName() { return name; } +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedAnnotation.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedAnnotation.java new file mode 100644 index 00000000000..931c718566e --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedAnnotation.java @@ -0,0 +1,21 @@ +package com.yahoo.searchdefinition.parser; + +/** + * This class holds the extracted information after parsing a + * "annotation" block, using simple data structures as far as + * possible. Do not put advanced logic here! + * @author arnej27959 + **/ +class ParsedAnnotation { + + private final String name; + + ParsedAnnotation(String name) { + this.name = name; + } + + public String name() { return name; } + + void setStruct(ParsedStruct struct) {} + void inherit(String other) {} +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedAttribute.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedAttribute.java new file mode 100644 index 00000000000..31a87a7b04f --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedAttribute.java @@ -0,0 +1,30 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.parser; + +/** + * This class holds the extracted information after parsing a + * "attribute" block, using simple data structures as far as + * possible. Do not put advanced logic here! + * @author arnej27959 + **/ +class ParsedAttribute { + + private final String name; + + ParsedAttribute(String name) { + this.name = name; + } + + public String name() { return name; } + + void addAlias(String from, String to) {} + void setDistanceMetric(String metric) {} + void setEnableBitVectors(boolean value) {} + void setEnableOnlyBitVector(boolean value) {} + void setFastAccess(boolean value) {} + void setFastSearch(boolean value) {} + void setHuge(boolean value) {} + void setMutable(boolean value) {} + void setPaged(boolean value) {} + void setSorting(ParsedSorting sorting) {} +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedDocument.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedDocument.java index 6bde4759eb7..3de1959a977 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedDocument.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedDocument.java @@ -21,12 +21,13 @@ public class ParsedDocument { String name() { return name; } void inherit(String other) { inherited.add(other); } + void addField(ParsedField field) {} + void addStruct(ParsedStruct type) {} + void addAnnotation(ParsedAnnotation type) {} + /* private final List<ParsedField> fields = new ArrayList<>(); List<ParsedField> getFields() { return fields; } - void addField(ParsedField field) { fields.add(field); } - void addStruct(ParsedStruct type) {} - void addAnnotation(ParsedAnnotation type) {} */ } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedDocumentSummary.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedDocumentSummary.java new file mode 100644 index 00000000000..bc0408a5881 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedDocumentSummary.java @@ -0,0 +1,26 @@ + +package com.yahoo.searchdefinition.parser; + +import java.util.ArrayList; +import java.util.List; + +/** + * This class holds the extracted information after parsing a + * "document-summary" block, using simple data structures as far as + * possible. Do not put advanced logic here! + * @author arnej27959 + **/ +class ParsedDocumentSummary { + + public final String name; + final List<ParsedSummaryField> fields = new ArrayList<>(); + + ParsedDocumentSummary(String name) { + this.name = name; + } + + void addField(ParsedSummaryField field) { fields.add(field); } + void setFromDisk(boolean value) {} + void setOmitSummaryFeatures(boolean value) {} + void inherit(String other) {} +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedField.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedField.java new file mode 100644 index 00000000000..39b699afcd1 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedField.java @@ -0,0 +1,45 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.parser; + +import com.yahoo.searchdefinition.document.Stemming; + +/** + * This class holds the extracted information after parsing a "field" + * block, using simple data structures as far as possible. Do not put + * advanced logic here! + * @author arnej27959 + **/ +class ParsedField { + + private final String name; + private ParsedType type; + + ParsedField(String name, ParsedType type) { + this.name = name; + this.type = type; + } + + String name() { return this.name; } + ParsedType getType() { return this.type; } + + void addAlias(String from, String to) {} + void addIndex(ParsedIndex index) {} + void addRankType(String index, String rankType) {} + void dictionary(DictionaryOption option) {} + void setBolding(boolean value) {} + void setFilter(boolean value) {} + void setId(int id) {} + void setIndexingRewrite(boolean value) {} + void setLiteral(boolean value) {} + void setNormal(boolean value) {} + void setNormalizing(String value) {} + void setSorting(ParsedSorting sorting) {} + void setStemming(Stemming stemming) {} + void setWeight(int weight) {} + void addAttribute(ParsedAttribute attr) {} + void addIndexingOperation(Object indx) {} + void addMatchSettings(ParsedMatchSettings settings) {} + void addQueryCommand(String queryCommand) {} + void addStructField(ParsedField structField) {} + void addSummaryField(ParsedSummaryField summaryField) {} +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedFieldSet.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedFieldSet.java new file mode 100644 index 00000000000..ca2734db5e8 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedFieldSet.java @@ -0,0 +1,24 @@ +package com.yahoo.searchdefinition.parser; + +import java.util.ArrayList; +import java.util.List; + +/** + * This class holds the extracted information after parsing a "fieldset" + * block, using simple data structures as far as possible. Do not put + * advanced logic here! + * @author arnej27959 + **/ +class ParsedFieldSet { + + public final String name; + final List<String> fields = new ArrayList<>(); + + ParsedFieldSet(String name) { + this.name = name; + } + + void addField(String field) { fields.add(field); } + void addQueryCommand(String queryCommand) {} + void addMatchSettings(ParsedMatchSettings matchInfo) {} +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedIndex.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedIndex.java new file mode 100644 index 00000000000..d017718e467 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedIndex.java @@ -0,0 +1,29 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.parser; + +import com.yahoo.searchdefinition.document.HnswIndexParams; + +/** + * This class holds the extracted information after parsing an "index" + * block, using simple data structures as far as possible. Do not put + * advanced logic here! + * @author arnej27959 + **/ +class ParsedIndex { + + private final String name; + + ParsedIndex(String name) { + this.name = name; + } + + void addAlias(String alias) {} + void setArity(int arity) {} + void setDensePostingListThreshold(double threshold) {} + void setEnableBm25(boolean value) {} + void setHnswIndexParams(HnswIndexParams params) {} + void setLowerBound(long bound) {} + void setPrefix(boolean value) {} + void setStemming(String stemming) {} + void setUpperBound(long bound) {} +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedMatchSettings.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedMatchSettings.java new file mode 100644 index 00000000000..acc76853453 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedMatchSettings.java @@ -0,0 +1,17 @@ +package com.yahoo.searchdefinition.parser; + +/** + * This class holds the extracted information after parsing a "match" + * block, using simple data structures as far as possible. Do not put + * advanced logic here! + * @author arnej27959 + **/ +public class ParsedMatchSettings { + + void setType(MatchType type) {} + void setCase(MatchCase type) {} + void setAlgorithm(MatchAlgorithm type) {} + void setExactTerminator(String terminator) {} + void setGramSize(int size) {} + void setMaxLength(int size) {} +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java index 85e20b2f714..1bfbb2a045c 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java @@ -24,11 +24,17 @@ public class ParsedSchema { String name() { return name; } + void addAnnotation(ParsedAnnotation annotation) {} void addDocument(ParsedDocument document) {} + void addDocumentSummary(ParsedDocumentSummary docsum) {} + void addField(ParsedField field) {} + void addFieldSet(ParsedFieldSet fieldSet) {} void addImportedField(String asFieldName, String refFieldName, String foregnFieldName) {} + void addIndex(ParsedIndex index) {} void addOnnxModel(OnnxModel model) {} - void addRankingConstant(RankingConstant constant) {} void addRankProfile(ParsedRankProfile profile) {} + void addRankingConstant(RankingConstant constant) {} + void addStruct(ParsedStruct struct) {} void enableRawAsBase64(boolean value) {} void inherit(String other) { inherited.add(other); } void setStemming(Stemming value) {} @@ -36,12 +42,6 @@ public class ParsedSchema { /* private final List<ParsedField> fields = new ArrayList<>(); List<ParsedField> getFields() { return fields; } - void addField(ParsedField field) { fields.add(field); } - void addAnnotation(ParsedAnnotation annotation) {} - void addIndex(ParsedIndex index) {} - void addStruct(ParsedStruct struct) {} - void addFieldSet(ParsedFieldSet fieldSet) {} - void addDocumentSummary(ParsedDocumentSummary docsum) {} */ } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSorting.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSorting.java new file mode 100644 index 00000000000..2a090e94312 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSorting.java @@ -0,0 +1,23 @@ + +package com.yahoo.searchdefinition.parser; + +/** + * This class holds the extracted information after parsing a "sorting" + * block, using simple data structures as far as possible. Do not put + * advanced logic here! + * @author arnej27959 + **/ +class ParsedSorting { + + enum Function { RAW, LOWERCASE, UCA } + + enum Strength { PRIMARY, SECONDARY, TERTIARY, QUATERNARY, IDENTICAL } + + void setAscending() {} + void setDescending() {} + + void setLocale(String locale) {} + + void setFunction(Function func) {} + void setStrength(Strength strength) {} +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedStruct.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedStruct.java new file mode 100644 index 00000000000..b081e0505ee --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedStruct.java @@ -0,0 +1,28 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.parser; + +import java.util.ArrayList; +import java.util.List; + +/** + * This class holds the extracted information after parsing a "struct" + * block, using simple data structures as far as possible. Do not put + * advanced logic here! + * @author arnej27959 + **/ +public class ParsedStruct { + private final String name; + private final List<String> inherited = new ArrayList<>(); + private final List<ParsedField> fields = new ArrayList<>(); + + public ParsedStruct(String name) { + this.name = name; + } + + /* TODO make immutable */ + List<ParsedField> getFields() { return fields; } + + void inherit(String other) { inherited.add(other); } + void addField(ParsedField field) { fields.add(field); } +} + diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSummaryField.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSummaryField.java new file mode 100644 index 00000000000..d18a4906b86 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSummaryField.java @@ -0,0 +1,44 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.parser; + +import java.util.ArrayList; +import java.util.List; + +/** + * This class holds the extracted information after parsing a summary + * field declaration, either from "field" inside "document-summary" or + * "summary" inside "field". Using simple data structures as far as + * possible. Do not put advanced logic here! + * @author arnej27959 + **/ +class ParsedSummaryField { + + public final String name; + public final Object type; + + ParsedSummaryField(String name) { + this.name = name; + this.type = null; + } + ParsedSummaryField(String name, Object type) { + this.name = name; + this.type = type; + } + + String getName() { return name; } + Object getType() { return type; } + + boolean isDyn = false; + boolean isMEO = false; + boolean isFull = false; + boolean isBold = false; + final List<String> sources = new ArrayList<>(); + final List<String> destinations = new ArrayList<>(); + + void addDestination(String dst) { destinations.add(dst); } + void addSource(String src) { sources.add(src); } + void setBold(boolean value) { this.isBold = value; } + void setDynamic() { this.isDyn = true; } + void setFull() { this.isFull = true; } + void setMatchedElementsOnly() { this.isMEO = true; } +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedType.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedType.java new file mode 100644 index 00000000000..ff1f7641ba0 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedType.java @@ -0,0 +1,130 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.parser; + +import com.yahoo.tensor.TensorType; + + +/** + * This class holds the extracted information after parsing a type + * declaration (typically for a field). Since types can be complex, + * struct names (known or unknown), or even document names, this class + * is somewhat complicated. + * @author arnej27959 + **/ +class ParsedType { + public enum Variant { + NONE, + BOOL, BYTE, INT, LONG, + STRING, + FLOAT, DOUBLE, + URI, PREDICATE, TENSOR, + ARRAY, WSET, MAP, + DOC_REFERENCE, + ANN_REFERENCE, + STRUCT, + DOCUMENT, + UNKNOWN + } + + private final String name; + private final ParsedType keyType; + private final ParsedType valType; + private final TensorType tensorType; + private Variant variant; + private boolean createIfNonExistent = false; + private boolean removeIfZero = false; + + private static Variant guessVariant(String name) { + switch (name) { + case "bool": return Variant.BOOL; + case "byte": return Variant.BYTE; + case "int": return Variant.INT; + case "long": return Variant.LONG; + case "string": return Variant.STRING; + case "float": return Variant.FLOAT; + case "double": return Variant.DOUBLE; + case "uri": return Variant.URI; + case "predicate": return Variant.PREDICATE; + case "tensor": return Variant.TENSOR; + case "position": return Variant.STRUCT; + } + if (name.startsWith("array<")) return Variant.ARRAY; + if (name.startsWith("weightedset<")) return Variant.WSET; + if (name.startsWith("map<")) return Variant.MAP; + if (name.startsWith("tensor(")) return Variant.TENSOR; + if (name.startsWith("struct<")) return Variant.STRUCT; + if (name.startsWith("document<")) return Variant.DOCUMENT; + if (name.startsWith("reference<")) return Variant.DOC_REFERENCE; + if (name.startsWith("annotationreference<")) return Variant.ANN_REFERENCE; + return Variant.UNKNOWN; + } + + public String name() { return name; } + public Variant getVariant() { return variant; } + + private ParsedType(String name, Variant variant) { + this(name, variant, null, null, null); + } + private ParsedType(String name, Variant variant, ParsedType vt) { + this(name, variant, vt, null, null); + } + private ParsedType(String name, Variant variant, ParsedType kt, ParsedType vt) { + this(name, variant, vt, kt, null); + } + private ParsedType(String name, Variant variant, ParsedType kt, ParsedType vt, TensorType tType) { + this.name = name; + this.variant = variant; + this.keyType = kt; + this.valType = vt; + this.tensorType = tType; + } + + static ParsedType mapType(ParsedType kt, ParsedType vt) { + String name = "map<" + kt.name() + "," + vt.name() + ">"; + return new ParsedType(name, Variant.MAP, kt, vt); + } + static ParsedType arrayOf(ParsedType vt) { + return new ParsedType("array<" + vt.name() + ">", Variant.ARRAY, vt); + } + static ParsedType wsetOf(ParsedType vt) { + return new ParsedType("weightedset<" + vt.name() + ">", Variant.WSET, vt); + } + static ParsedType documentRef(ParsedType docType) { + return new ParsedType("reference<" + docType.name + ">", Variant.DOC_REFERENCE, docType); + } + static ParsedType annotationRef(String name) { + return new ParsedType("annotationreference<" + name + ">", Variant.ANN_REFERENCE); + } + static ParsedType tensorType(TensorType tType) { + return new ParsedType(tType.toString(), Variant.TENSOR, null, null, tType); + } + static ParsedType fromName(String name) { + return new ParsedType(name, guessVariant(name)); + } + static ParsedType documentType(String name) { + return new ParsedType(name, Variant.DOCUMENT); + } + + void setCreateIfNonExistent(boolean value) { + if (variant != Variant.WSET) { + throw new IllegalArgumentException("CreateIfNonExistent only valid for weightedset, not "+variant); + } + this.createIfNonExistent = value; + } + + void setRemoveIfZero(boolean value) { + if (variant != Variant.WSET) { + throw new IllegalArgumentException("RemoveIfZero only valid for weightedset, not "+variant); + } + this.removeIfZero = value; + } + + void setVariant(Variant value) { + if (variant == value) return; // already OK + if (variant != Variant.UNKNOWN) { + throw new IllegalArgumentException("setVariant("+value+") only valid for UNKNOWN, not: "+variant); + } + // maybe even more checking would be useful + this.variant = value; + } +} diff --git a/config-model/src/main/javacc/IntermediateParser.jj b/config-model/src/main/javacc/IntermediateParser.jj index a6482ca0b81..b6fc94cf15c 100644 --- a/config-model/src/main/javacc/IntermediateParser.jj +++ b/config-model/src/main/javacc/IntermediateParser.jj @@ -442,14 +442,12 @@ void rootSchemaItem(ParsedSchema schema) : { } | rankingConstant(schema) | useDocument(schema) | rankProfile(schema) -/* | documentSummary(schema) - | field(null, schema) - | index(schema, null) + | fieldOutsideDoc(schema) + | indexOutsideDoc(schema) | structOutside(schema) | annotationOutside(schema) | fieldSet(schema) -*/ | onnxModel(schema) ) } @@ -539,9 +537,9 @@ void documentBody(ParsedDocument document) : ( compression() | headercfg() | bodycfg() - /* | annotation(schema, document) - | structInside(document, schema) - | field(document, schema) */ + | annotation(document) + | structInside(document) + | fieldInsideDoc(document) ) } @@ -600,20 +598,19 @@ void compressionItem() : } /** - * Consumes a struct inheritance statement. + * Consumes struct inheritance * - * @param document The struct type to modify. + * @param struct The struct type to modify. */ -void inheritsStruct(SDDocumentType document) : +void inheritsStruct(ParsedStruct struct) : { String name; } { - <INHERITS> name = identifier() { document.inherit(new DataTypeName(name)); } - ( <COMMA> name = identifier() { document.inherit(new DataTypeName(name)); } )* + <INHERITS> name = identifier() { struct.inherit(name); } + ( <COMMA> name = identifier() { struct.inherit(name); } )* } - /** * Consumes a document inheritance statement. * @@ -628,18 +625,40 @@ void inheritsDocument(ParsedDocument document) : ( <COMMA> name = identifier() { document.inherit(name); } )* } - /** * Consumes a field block from within a document element. * * @param document the document type to modify - * @param schema the schema object to add content to */ -void field(SDDocumentType document, Schema schema) : +void fieldInsideDoc(ParsedDocument document) : +{ + ParsedField field; +} +{ + field = field() { document.addField(field); } +} + +/** + * Consumes a field block from outside a document element. + * + * @param schema the schema to modify + */ +void fieldOutsideDoc(ParsedSchema schema) : +{ + ParsedField field; +} +{ + field = field() { schema.addField(field); } +} + +/** + * Consumes a field block + */ +ParsedField field() : { String name; - SDField field; - DataType type; + ParsedField field; + ParsedType type; } { <FIELD> name = identifier() <TYPE> type = dataType() @@ -647,120 +666,92 @@ void field(SDDocumentType document, Schema schema) : if (name != null && Schema.isReservedName(name.toLowerCase())) { throw new IllegalArgumentException("Reserved name '" + name + "' can not be used as a field name."); } - field = new TemporarySDField(name, type, document); + field = new ParsedField(name, type); } - lbrace() (fieldBody(field, schema, document) (<NL>)*)* <RBRACE> + lbrace() (fieldBody(field) (<NL>)*)* <RBRACE> { - if (document != null) { - document.addField(field); - } else { - schema.addExtraField(field); - } + return field; } } -void fieldSet(Schema schema) : +/** Consumes a fieldset block */ +void fieldSet(ParsedSchema schema) : { - String setName; - String field; + String name; String queryCommand; - List queryCommands = new ArrayList(); - FieldOperationContainer matchSetting; - List matchSettings = new ArrayList(); + ParsedMatchSettings matchInfo; + ParsedFieldSet fieldSet; } { - <FIELDSET> setName = identifier() lbrace() + <FIELDSET> name = identifier() lbrace() { fieldSet = new ParsedFieldSet(name); } (( - ( <FIELDS><COLON> field = identifier() { schema.fieldSets().addUserFieldSetItem(setName, field); } - ( <COMMA> field = identifier() { schema.fieldSets().addUserFieldSetItem(setName, field); } )* ) + ( <FIELDS><COLON> name = identifier() { fieldSet.addField(name); } + ( <COMMA> name = identifier() { fieldSet.addField(name); } )* ) | - ( <QUERYCOMMAND> <COLON> (queryCommand = identifierWithDash() | queryCommand = quotedString())) { queryCommands.add(queryCommand); } + ( <QUERYCOMMAND> <COLON> (queryCommand = identifierWithDash() | queryCommand = quotedString())) { fieldSet.addQueryCommand(queryCommand); } | - ( matchSetting = match(new SDField(setName, DataType.STRING)) ) { matchSettings.add(matchSetting); } - )(<NL>)*)+ + ( matchInfo = matchSettings() ) { fieldSet.addMatchSettings(matchInfo); } + ) (<NL>)* )+ <RBRACE> { - // Apply settings after parsing since all user field items must be set first - - for (Object command : queryCommands) - schema.fieldSets().userFieldSets().get(setName).queryCommands().add((String)command); - - for (Object setting : matchSettings) { - ((SDField)setting).applyOperations(); - schema.fieldSets().userFieldSets().get(setName).setMatching(((SDField)setting).getMatching()); - } + schema.addFieldSet(fieldSet); } } /** - * This rule consumes a annotation block from within either a document element or a schema element. - + * This rule consumes a annotation block from within a schema element. + * * @param schema the schema object to add content to */ -void annotationOutside(Schema schema) : +void annotationOutside(ParsedSchema schema) : { String name; - SDAnnotationType type; + ParsedAnnotation type; } { - <ANNOTATION> name = identifier() - { - type = new SDAnnotationType(name.trim()); - } + <ANNOTATION> name = identifier() { type = new ParsedAnnotation(name); } [ inheritsAnnotation(type) (<NL>)* ] - lbrace() (type = annotationBody(schema, type)) <RBRACE> + lbrace() annotationBody(type) <RBRACE> { - if (schema.getDocument()==null) throw new IllegalArgumentException("Can't add annotation '"+name+"' to a document type, define a document type first or declare the annotation inside of one."); schema.addAnnotation(type); } } /** - * Consumes a annotation block from within either a document element. + * Consumes an annotation block from within a document element * * @param document the document object to add content to */ -void annotation(Schema schema, SDDocumentType document) : +void annotation(ParsedDocument document) : { String name; - SDAnnotationType type; + ParsedAnnotation type; } { - <ANNOTATION> name = identifier() - { - type = new SDAnnotationType(name.trim()); - } + <ANNOTATION> name = identifier() { type = new ParsedAnnotation(name); } [ inheritsAnnotation(type) (<NL>)* ] - lbrace() (type = annotationBody(schema, type)) <RBRACE> + lbrace() annotationBody(type) <RBRACE> { document.addAnnotation(type); } } - /** * Consumes a single element of an annotation body block. - * - * @param schema the schema object to add content to - * @param type the type being built - * @return a modified or new AnnotationType instance */ -SDAnnotationType annotationBody(Schema schema, SDAnnotationType type) : +void annotationBody(ParsedAnnotation type) : { - SDDocumentType struct = new SDDocumentType("annotation." + type.getName(), schema); + ParsedStruct struct = new ParsedStruct("annotation." + type.name()); + boolean seenField = false; } { - (structFieldDefinition(struct) (<NL>)*)* + (structFieldDefinition(struct) { seenField = true; } (<NL>)*)* { - if (struct.getFieldCount() > 0) { // Must account for the temporary TemporarySDField. - type = new SDAnnotationType(type.getName(), struct, type.getInherits()); - struct.setStruct(null); - } - return type; + if (seenField) type.setStruct(struct); } } -void inheritsAnnotation(SDAnnotationType annotation) : +void inheritsAnnotation(ParsedAnnotation annotation) : { String name; } @@ -768,71 +759,44 @@ void inheritsAnnotation(SDAnnotationType annotation) : <INHERITS> name = identifier() { annotation.inherit(name); } } - /** * This rule consumes a struct block from within a document element. - * - * @param schema the schema object to add content to + * @param document the document object to add content to */ -void structInside(SDDocumentType document, Schema schema) : +void structInside(ParsedDocument document) : { - SDDocumentType struct; + ParsedStruct struct; } { - ( - struct = structDefinition(schema, document) - ) - { - document.addType(struct); - } + struct = structDefinition() { document.addStruct(struct); } } /** - * This rule consumes a struct block from within a document element. - * + * This rule consumes a struct block from within a schema element. * @param schema the schema object to add content to */ -void structOutside(Schema schema) : +void structOutside(ParsedSchema schema) : { - SDDocumentType struct; + ParsedStruct struct; } { - ( - struct = structDefinition(schema, schema.getDocument()) - ) - { - schema.addType(struct); - } + struct = structDefinition() { schema.addStruct(struct); } } /** - * This rule consumes a struct block from within a document element. - * - * @param schema the schema object to add content to + * This rule consumes a struct declaration block */ -SDDocumentType structDefinition(Schema schema, SDDocumentType repo) : +ParsedStruct structDefinition() : { String name; - String inherited = null; - SDDocumentType struct; + String inherited; + ParsedStruct struct; } { - ( <STRUCT> name = identifier() (<NL>)* { struct = new SDDocumentType(name, schema); } + ( <STRUCT> name = identifier() (<NL>)* { struct = new ParsedStruct(name); } [ inheritsStruct(struct) (<NL>)* ] lbrace() (structFieldDefinition(struct) (<NL>)*)* <RBRACE> ) { - try { - docMan.getDataType(name); - throw new ParseException("Reserved name '" + name + "' can not be used to declare a struct."); - } catch (IllegalArgumentException e) { - // empty - } - if (repo==null) throw new IllegalArgumentException("Can't add struct '"+name+"' to a document type, define a document type first or declare the struct inside of one."); - SDDocumentType sdtype = repo.getOwnedType(struct.getDocumentName()); - DataType stype = sdtype != null - ? sdtype.getStruct() - : TemporaryStructuredDataType.create(struct.getName()); - struct.setStruct(stype); return struct; } } @@ -842,77 +806,68 @@ SDDocumentType structDefinition(Schema schema, SDDocumentType repo) : * * @return the consumed data type */ -DataType dataType() : +ParsedType dataType() : { String typeName = null; boolean isArrayOldStyle = false; - DataType mapType = null; - DataType arrayType = null; - DataType wsetType = null; + ParsedType mapType = null; + ParsedType arrayType = null; + ParsedType wsetType = null; TensorType tensorType; - TemporaryStructuredDataType referenceType; + ParsedType referenceType; } { - ( LOOKAHEAD(<ARRAY> <LESSTHAN>) ( <ARRAY> <LESSTHAN> arrayType = dataType() <GREATERTHAN> { return DataType.getArray(arrayType); } ) - | LOOKAHEAD(<WEIGHTEDSET> <LESSTHAN>) ( <WEIGHTEDSET> <LESSTHAN> wsetType = dataType() <GREATERTHAN> { return DataType.getWeightedSet(wsetType); } ) + ( LOOKAHEAD(<ARRAY> <LESSTHAN>) ( <ARRAY> <LESSTHAN> arrayType = dataType() <GREATERTHAN> { return ParsedType.arrayOf(arrayType); } ) + | LOOKAHEAD(<WEIGHTEDSET> <LESSTHAN>) ( <WEIGHTEDSET> <LESSTHAN> wsetType = dataType() <GREATERTHAN> { return ParsedType.wsetOf(wsetType); } ) | LOOKAHEAD(<MAP> <LESSTHAN>) ( mapType = mapDataType() { return mapType; } ) | LOOKAHEAD(<ANNOTATIONREFERENCE> <LESSTHAN>) ( mapType = annotationRefDataType() { return mapType; } ) - | LOOKAHEAD(<TENSOR_TYPE>) ( tensorType = tensorType("Field type") { return DataType.getTensor(tensorType); } ) - | LOOKAHEAD(<REFERENCE>) ( <REFERENCE> <LESSTHAN> referenceType = referenceType() <GREATERTHAN> { return ReferenceDataType.createWithInferredId(referenceType); } ) + | LOOKAHEAD(<TENSOR_TYPE>) ( tensorType = tensorType("Field type") { return ParsedType.tensorType(tensorType); } ) + | LOOKAHEAD(<REFERENCE>) ( <REFERENCE> <LESSTHAN> referenceType = referenceType() <GREATERTHAN> { return ParsedType.documentRef(referenceType); } ) | ( typeName = identifier() ["[]" { isArrayOldStyle = true; }] ) ) { - DataType type = VespaDocumentType.INSTANCE.getDataType(typeName); - - if (type == null) { - // we are basically creating TemporaryStructDataType instances for ANYTHING here!! - // we must do this and clean them up later. - type = TemporaryStructuredDataType.create(typeName); - } - + ParsedType type = ParsedType.fromName(typeName); if (isArrayOldStyle) { deployLogger.logApplicationPackage(Level.WARNING, "Data type syntax '" + typeName + "[]' is deprecated, use 'array<" + typeName + ">' instead."); - type = DataType.getArray(type); + type = ParsedType.arrayOf(type); } - if ("tag".equalsIgnoreCase(typeName) && type instanceof WeightedSetDataType) ((WeightedSetDataType)type).setTag(true); return type; } } -TemporaryStructuredDataType referenceType() : +ParsedType referenceType() : { String documentName; } { ( documentName = identifier() ) { - return TemporaryStructuredDataType.create(documentName); + return ParsedType.documentType(documentName); } } -DataType annotationRefDataType() : +ParsedType annotationRefDataType() : { - DataType dataType; + ParsedType dataType; String targetName; } { ( <ANNOTATIONREFERENCE> <LESSTHAN> targetName = identifier() <GREATERTHAN> ) { - return new TemporaryAnnotationReferenceDataType(targetName); + return ParsedType.annotationRef(targetName); } } -DataType mapDataType() : +ParsedType mapDataType() : { - DataType keyType; - DataType valType; + ParsedType keyType; + ParsedType valType; } { ( <MAP> <LESSTHAN> keyType = dataType() <COMMA> valType = dataType() <GREATERTHAN> ) { - return DataType.getMap(keyType, valType); + return ParsedType.mapType(keyType, valType); } - } /* Note: not currently used, remove when decided that map type will not support @@ -929,21 +884,22 @@ DataType wildCardType() : * * @param struct The struct to modify. */ -void structFieldDefinition(SDDocumentType struct) : +void structFieldDefinition(ParsedStruct struct) : { String name; - SDField field; - DataType type; + ParsedType type; + ParsedField field; + int fieldId; } { <FIELD> name = identifier() <TYPE> type = dataType() { if (name != null && Schema.isReservedName(name.toLowerCase())) { throw new IllegalArgumentException("Reserved name '" + name + "' can not be used as a field name."); } - field = new TemporarySDField(name, type, struct); - struct.addField(field); + field = new ParsedField(name, type); } - lbrace() (id(field,struct) (<NL>)*)? (match(field) (<NL>)*)* <RBRACE> { + lbrace() (id(field) (<NL>)*)? (match(field) (<NL>)*)* <RBRACE> { + struct.addField(field); } } @@ -952,45 +908,40 @@ void structFieldDefinition(SDDocumentType struct) : * struct's fields, but rather this is a subfield of a document field of type struct. * * @param field the field to modify - * @param schema the schema object to add content to - * @param document the document type to modify */ -void structField(FieldOperationContainer field, Schema schema, SDDocumentType document) : +void structField(ParsedField field) : { String name; - SDField structField; + ParsedField structField; } { <STRUCTFIELD> name = identifier() { if (name != null && Schema.isReservedName(name.toLowerCase())) { throw new IllegalArgumentException("Reserved name '" + name + "' can not be used as a field name."); } - FieldOperationContainer structFieldOp = new StructFieldOperation(name); - field.addOperation((StructFieldOperation) structFieldOp); + structField = new ParsedField(name, null); } - lbrace() (structFieldBody(structFieldOp, schema, document) (<NL>)*)* <RBRACE> + lbrace() (structFieldBody(structField) (<NL>)*)* <RBRACE> + { field.addStructField(structField); } } - /** * This rule consumes a single element of a field body block. * * @param field the field being built - * @param schema the schema object to add content to - * @param document the owning document, or null if this is a search field */ -void fieldBody(SDField field, Schema schema, SDDocumentType document) : { } +void fieldBody(ParsedField field) : { } { ( alias(field) | attribute(field) | - body(field) | + body() | bolding(field) | dictionary(field) | fieldStemming(field) | - header(field) | - id(field, document) | + header() | + id(field) | summaryInField(field) | - index(schema, field) | + indexInsideField(field) | indexing(field) | indexingRewrite(field) | match(field) | @@ -998,11 +949,11 @@ void fieldBody(SDField field, Schema schema, SDDocumentType document) : { } queryCommand(field) | rank(field) | rankType(field) | - sorting(field, field.getName()) | - structField(field, schema, document) | + fieldSorting(field) | + structField(field) | summaryTo(field) | weight(field) | - weightedset(field) ) + weightedset(field.getType()) ) } /** @@ -1010,17 +961,15 @@ void fieldBody(SDField field, Schema schema, SDDocumentType document) : { } * Only elements that are supported in streaming schema and indexed schema (with complex attributes) are allowed. * * @param field the field being built - * @param schema the schema object to add content to - * @param document the owning document, or null if this is a schema field */ -void structFieldBody(FieldOperationContainer field, Schema schema, SDDocumentType document) : { } +void structFieldBody(ParsedField field) : { } { ( summaryInField(field) | indexing(field) | attribute(field) | match(field) | queryCommand(field) | - structField(field, schema, document) | + structField(field) | summaryTo(field) ) } @@ -1029,7 +978,7 @@ void structFieldBody(FieldOperationContainer field, Schema schema, SDDocumentTyp * * @param field The field to modify. */ -void indexing(FieldOperationContainer field) : { } +void indexing(ParsedField field) : { } { ( <INDEXING> ( (<COLON> indexingOperation(field, false)) | indexingOperation(field, true) ) ) } @@ -1039,9 +988,9 @@ void indexing(FieldOperationContainer field) : { } * * @param field The field to modify. */ -void indexingOperation(FieldOperationContainer field, boolean multiLine) : { } +void indexingOperation(ParsedField field, boolean multiLine) : { } { - { field.addOperation(newIndexingOperation(multiLine)); } + { field.addIndexingOperation(newIndexingOperation(multiLine)); } } /** @@ -1049,69 +998,60 @@ void indexingOperation(FieldOperationContainer field, boolean multiLine) : { } * * @param field The field to modify. */ -void summaryTo(FieldOperationContainer field) : +void summaryTo(ParsedField field) : { - SummaryToOperation op = new SummaryToOperation(); + String name = field.name(); String destination; - String name = field.getName(); + ParsedSummaryField psf; } { <SUMMARYTO> [name = identifier()] <COLON> destination = identifier() { - op.setName(name); - op.addDestination(destination); + psf = new ParsedSummaryField(name); + psf.addDestination(destination); } - ( <COMMA> destination = identifier() {op.addDestination(destination); } )* + ( <COMMA> destination = identifier() { psf.addDestination(destination); } )* { - field.addOperation(op); + field.addSummaryField(psf); } } - /** * This rule consumes a weight statement of a field element. * * @param field The field to modify. */ -void weight(FieldOperationContainer field) : +void weight(ParsedField field) : { int num; } { <WEIGHT> <COLON> num = integer() { - WeightOperation op = new WeightOperation(); - op.setWeight(num); - field.addOperation(op); + field.setWeight(num); } } /** * This rule consumes a weighted set statement of a field element. * - * @param field The field to modify. + * @param fieldType The field type to modify. */ -void weightedset(FieldOperationContainer field) : -{ - WeightedSetOperation op = new WeightedSetOperation(); -} +void weightedset(ParsedType fieldType) : { } { - <WEIGHTEDSET> ( (<COLON> weightedsetBody(op)) - | (lbrace() (weightedsetBody(op) (<NL>)*)* <RBRACE>) ) - { - field.addOperation(op); - } + <WEIGHTEDSET> ( (<COLON> weightedsetBody(fieldType)) + | (lbrace() (weightedsetBody(fieldType) (<NL>)*)* <RBRACE>) ) } /** * This rule consumes one body item of a weighted set block. * - * @param field The field to modify. + * @param type The field type to modify. */ -void weightedsetBody(WeightedSetOperation field) : { } +void weightedsetBody(ParsedType type) : { } { - ( <CREATEIFNONEXISTENT> { field.setCreateIfNonExistent(true); } - | <REMOVEIFZERO> { field.setRemoveIfZero(true); } ) + ( <CREATEIFNONEXISTENT> { type.setCreateIfNonExistent(true); } + | <REMOVEIFZERO> { type.setRemoveIfZero(true); } ) } /** @@ -1119,18 +1059,15 @@ void weightedsetBody(WeightedSetOperation field) : { } * * @param field The field to modify. */ -void rankType(FieldOperationContainer field) : +void rankType(ParsedField field) : { String typeName; - String indexName = null; + String indexName = field.name(); } { <RANKTYPE> [indexName = identifier()] <COLON> typeName = identifier() { - RankTypeOperation op = new RankTypeOperation(); - op.setType(RankType.fromString(typeName)); - op.setIndexName(indexName); - field.addOperation(op); + field.addRankType(indexName, typeName); } } @@ -1139,36 +1076,54 @@ void rankType(FieldOperationContainer field) : * * @param field The field to modify. */ -void attribute(FieldOperationContainer field) : +void attribute(ParsedField field) : { - String name = field.getName(); + String name = field.name(); } { <ATTRIBUTE> [name = identifier()] { - AttributeOperation op = new AttributeOperation(name); + ParsedAttribute attr = new ParsedAttribute(name); } - ( (<COLON> attributeSetting(field, op, name)) - | (lbrace() (attributeSetting(field, op, name) (<NL>)*)* <RBRACE>) ) + ( (<COLON> attributeSetting(attr)) + | (lbrace() (attributeSetting(attr) (<NL>)*)* <RBRACE>) ) { - field.addOperation(op); + field.addAttribute(attr); } } -void sorting(FieldOperationContainer field, String name) : +/* pick up sorting in field block */ +void fieldSorting(ParsedField field) : { - SortingOperation op = new SortingOperation(name); + ParsedSorting sortInfo; +} +{ + sortInfo = sorting() { field.setSorting(sortInfo); } +} + +/* pick up sorting in field block */ +void attributeSorting(ParsedAttribute attribute) : +{ + ParsedSorting sortInfo; +} +{ + sortInfo = sorting() { attribute.setSorting(sortInfo); } +} + +ParsedSorting sorting() : +{ + ParsedSorting sort = new ParsedSorting(); } { <SORTING> - ( (<COLON> sortingSetting(op, name)) - | (lbrace() (sortingSetting(op, name) (<NL>)*)* <RBRACE>) ) + ( (<COLON> sortingSetting(sort)) + | (lbrace() (sortingSetting(sort) (<NL>)*)* <RBRACE>) ) { - field.addOperation(op); + return sort; } } -void sortingSetting(SortingOperation sorting, String attributeName) : +void sortingSetting(ParsedSorting sorting) : { String locale; } @@ -1177,16 +1132,16 @@ void sortingSetting(SortingOperation sorting, String attributeName) : <ASCENDING> { sorting.setAscending(); } | <DESCENDING> { sorting.setDescending(); } | <FUNCTION> <COLON> ( - <UCA> { sorting.setFunction(Sorting.Function.UCA); } - | <RAW> { sorting.setFunction(Sorting.Function.RAW); } - | <LOWERCASE> { sorting.setFunction(Sorting.Function.LOWERCASE); } + <UCA> { sorting.setFunction(ParsedSorting.Function.UCA); } + | <RAW> { sorting.setFunction(ParsedSorting.Function.RAW); } + | <LOWERCASE> { sorting.setFunction(ParsedSorting.Function.LOWERCASE); } ) | <STRENGTH> <COLON> ( - <PRIMARY> { sorting.setStrength(Sorting.Strength.PRIMARY); } - | <SECONDARY> { sorting.setStrength(Sorting.Strength.SECONDARY); } - | <TERTIARY> { sorting.setStrength(Sorting.Strength.TERTIARY); } - | <QUATERNARY> { sorting.setStrength(Sorting.Strength.QUATERNARY); } - | <IDENTICAL> { sorting.setStrength(Sorting.Strength.IDENTICAL); } + <PRIMARY> { sorting.setStrength(ParsedSorting.Strength.PRIMARY); } + | <SECONDARY> { sorting.setStrength(ParsedSorting.Strength.SECONDARY); } + | <TERTIARY> { sorting.setStrength(ParsedSorting.Strength.TERTIARY); } + | <QUATERNARY> { sorting.setStrength(ParsedSorting.Strength.QUATERNARY); } + | <IDENTICAL> { sorting.setStrength(ParsedSorting.Strength.IDENTICAL); } ) | <LOCALE> <COLON> locale = identifierWithDash() { sorting.setLocale(locale); } ) @@ -1195,10 +1150,9 @@ void sortingSetting(SortingOperation sorting, String attributeName) : /** * This rule consumes a single attribute setting statement of an attribute element. * - * @param field The field to modify. - * @param attributeName The name of the attribute to change. + * @param attribute The attribute to change. */ -void attributeSetting(FieldOperationContainer field, AttributeOperation attribute, String attributeName) : +void attributeSetting(ParsedAttribute attribute) : { String str; } @@ -1211,11 +1165,9 @@ void attributeSetting(FieldOperationContainer field, AttributeOperation attribut | <PAGED> { attribute.setPaged(true); } | <ENABLEBITVECTORS> { attribute.setEnableBitVectors(true); } | <ENABLEONLYBITVECTOR> { attribute.setEnableOnlyBitVector(true); } - | sorting(field, attributeName) - | <ALIAS> { String alias; String aliasedName=attributeName; } [aliasedName = identifier()] <COLON> alias = identifierWithDash() { - attribute.setDoAlias(true); - attribute.setAlias(alias); - attribute.setAliasedName(aliasedName); + | attributeSorting(attribute) + | <ALIAS> { String alias; String aliasedName=attribute.name(); } [aliasedName = identifier()] <COLON> alias = identifierWithDash() { + attribute.addAlias(aliasedName, alias); } | attributeTensorType(attribute) | <DISTANCEMETRIC> <COLON> str = identifierWithDash() { attribute.setDistanceMetric(str); } @@ -1227,46 +1179,37 @@ void attributeSetting(FieldOperationContainer field, AttributeOperation attribut * * @param attribute The attribute to modify. */ -void attributeTensorType(AttributeOperation attribute) : +void attributeTensorType(ParsedAttribute attribute) : { TensorType tensorType; } { - tensorType = tensorType("For attribute field '" + attribute.getName() + "'") + tensorType = tensorType("For attribute field '" + attribute.name() + "'") { // TODO: Remove on Vespa 8 - deployLogger.logApplicationPackage(Level.WARNING, "In field '" + attribute.getName() + "': Specifying tensor type on the attribute is deprecated and has no effect."); + deployLogger.logApplicationPackage(Level.WARNING, "In field '" + attribute.name() + "': Specifying tensor type on the attribute is deprecated and has no effect."); } } /** * This rule consumes a summary statement defined inside a document-summary block. * - * @param document The document summary to modify. + * @param docsum The document summary to modify. */ -void summaryInDocument(DocumentSummary document) : +void summaryInDocument(ParsedDocumentSummary docsum) : { String name; - DataType type; - SummaryField summary; - + ParsedType type; + ParsedSummaryField psf; } { <SUMMARY> name = identifierWithDash() { } <TYPE> type = dataType() { - summary = new SummaryField(name, type); - summary.setVsmCommand(SummaryField.VsmCommand.FLATTENSPACE); - - SummaryInFieldLongOperation op = new SummaryInFieldLongOperation(); + psf = new ParsedSummaryField(name, type); } - lbrace() (summaryItem(op) (<NL>)*)* <RBRACE> + lbrace() (summaryItem(psf) (<NL>)*)* <RBRACE> { - if (op.destinationIterator().hasNext()) { - throw new ParseException("Summaries defined in a document-summary section " + - "can not have a 'to' line."); - } - op.applyToSummary(summary); - document.add(summary); + docsum.addField(psf); } } @@ -1275,40 +1218,38 @@ void summaryInDocument(DocumentSummary document) : * * @param field The field to modify. */ -void summaryInField(FieldOperationContainer field) : +void summaryInField(ParsedField field) : { - SummaryInFieldOperation summary; + ParsedSummaryField psf; } { - ( <SUMMARY> ( LOOKAHEAD(2) summary = summaryInFieldShort(field) - | summary = summaryInFieldLong(field)) ) + ( <SUMMARY> ( LOOKAHEAD(2) psf = summaryInFieldShort(field.name()) + | psf = summaryInFieldLong(field.name())) ) { - field.addOperation(summary); + field.addSummaryField(psf); } } /** * This rule consumes a single-line summary field. * - * @param field The field to modify. * @return The consumed summary field. */ -SummaryInFieldOperation summaryInFieldShort(FieldOperationContainer field) : +ParsedSummaryField summaryInFieldShort(String fieldName) : { - String name = field.getName(); - SummaryField ret; + String name = fieldName; + ParsedSummaryField psf; } { [ name = identifier() ] { - SummaryInFieldShortOperation op = new SummaryInFieldShortOperation(name); + psf = new ParsedSummaryField(name); } - <COLON> ( <DYNAMIC> { op.setTransform(SummaryTransform.DYNAMICTEASER); - op.addSource(name); - } - | <MATCHEDELEMENTSONLY> { op.setTransform(SummaryTransform.MATCHED_ELEMENTS_FILTER); } - | (<FULL> | <STATIC>) { op.setTransform(SummaryTransform.NONE); } ) - { return op; } + <COLON> ( <DYNAMIC> { psf.setDynamic(); } + | <MATCHEDELEMENTSONLY> { psf.setMatchedElementsOnly(); } + | (<FULL> | <STATIC>) { psf.setFull(); } + ) + { return psf; } } /** @@ -1316,20 +1257,20 @@ SummaryInFieldOperation summaryInFieldShort(FieldOperationContainer field) : * * @return The consumed summary field. */ -SummaryInFieldOperation summaryInFieldLong(FieldOperationContainer field) : +ParsedSummaryField summaryInFieldLong(String fieldName) : { - String name = field.getName(); - DataType type = null; + String name = fieldName; + ParsedType type = null; + ParsedSummaryField psf; } { ( [ name = identifier() [ <TYPE> type = dataType() ] ] lbrace() { - SummaryInFieldLongOperation op = new SummaryInFieldLongOperation(name); - op.setType(type); + psf = new ParsedSummaryField(name, type); } - (summaryItem(op) (<NL>)*)* <RBRACE> ) - { return op; } + (summaryItem(psf) (<NL>)*)* <RBRACE> ) + { return psf; } } /** @@ -1337,7 +1278,7 @@ SummaryInFieldOperation summaryInFieldLong(FieldOperationContainer field) : * * @param field The field to modify. */ -void summaryItem(SummaryInFieldLongOperation field) : { } +void summaryItem(ParsedSummaryField field) : { } { ( summaryTransform(field) | summaryBolding(field) @@ -1351,11 +1292,12 @@ void summaryItem(SummaryInFieldLongOperation field) : { } * * @param field The field to modify. */ -void summaryTransform(SummaryInFieldOperation field) : { } +void summaryTransform(ParsedSummaryField field) : { } { - ( <DYNAMIC> { field.setTransform(SummaryTransform.DYNAMICTEASER); } - | <MATCHEDELEMENTSONLY> { field.setTransform(SummaryTransform.MATCHED_ELEMENTS_FILTER); } - | (<FULL> | <STATIC>) { field.setTransform(SummaryTransform.NONE); } ) + ( <DYNAMIC> { field.setDynamic(); } + | <MATCHEDELEMENTSONLY> { field.setMatchedElementsOnly(); } + | (<FULL> | <STATIC>) { field.setFull(); } + ) } /** @@ -1363,7 +1305,7 @@ void summaryTransform(SummaryInFieldOperation field) : { } * * @param field The summary field to modify. */ -void summaryBolding(SummaryInFieldLongOperation field) : +void summaryBolding(ParsedSummaryField field) : { boolean bold; } @@ -1377,7 +1319,7 @@ void summaryBolding(SummaryInFieldLongOperation field) : * * @param field The summary field to modify. */ -void summarySourceList(SummaryInFieldOperation field) : +void summarySourceList(ParsedSummaryField field) : { String str; } @@ -1391,7 +1333,7 @@ void summarySourceList(SummaryInFieldOperation field) : * * @param field The summary field to modify. */ -void summaryDestinationList(SummaryInFieldLongOperation field) : +void summaryDestinationList(ParsedSummaryField field) : { String str; } @@ -1405,7 +1347,7 @@ void summaryDestinationList(SummaryInFieldLongOperation field) : * * @param field The summary field to modify. */ -void summaryProperties(SummaryInFieldLongOperation field) : { } +void summaryProperties(ParsedSummaryField field) : { } { <PROPERTIES> lbrace() (summaryProperty(field) <NL>)+ <RBRACE> } @@ -1415,7 +1357,7 @@ void summaryProperties(SummaryInFieldLongOperation field) : { } * * @param field The summary field to modify. */ -void summaryProperty(SummaryInFieldLongOperation field) : +void summaryProperty(ParsedSummaryField field) : { String name, value; } @@ -1429,16 +1371,14 @@ void summaryProperty(SummaryInFieldLongOperation field) : * * @param field The field to modify. */ -void fieldStemming(FieldOperationContainer field) : +void fieldStemming(ParsedField field) : { String setting; - StemmingOperation op = new StemmingOperation(); } { <STEMMING> <COLON> setting = identifierWithDash() { - op.setSetting(setting); - field.addOperation(op); + field.setStemming(Stemming.get(setting)); } } @@ -1457,19 +1397,19 @@ void searchStemming(ParsedSchema schema) : } /** - * This rule consumes a normalizing statement of a field element. At the moment, this can only be used to turn off - * normalizing. + * This rule consumes a normalizing statement of a field element. + * At the moment, this can only be used to turn off normalizing. * * @param field The field to modify. */ -void normalizing(FieldOperationContainer field) : +void normalizing(ParsedField field) : { String setting; } { <NORMALIZING> <COLON> setting = identifierWithDash() { - field.addOperation(new NormalizingOperation(setting)); + field.setNormalizing(setting); } } @@ -1478,15 +1418,12 @@ void normalizing(FieldOperationContainer field) : * * @param field The field to modify. */ -void bolding(FieldOperationContainer field) : +void bolding(ParsedField field) : { boolean bold; } { - <BOLDING> <COLON> bold = bool() - { - field.addOperation(new BoldingOperation(bold)); - } + <BOLDING> <COLON> bold = bool() { field.setBolding(bold); } } /** @@ -1494,7 +1431,7 @@ void bolding(FieldOperationContainer field) : * * @param field The field to modify. */ -void dictionary(FieldOperationContainer field) : +void dictionary(ParsedField field) : { } { @@ -1505,161 +1442,148 @@ void dictionary(FieldOperationContainer field) : } } -void dictionarySetting(FieldOperationContainer field) : +void dictionarySetting(ParsedField field) : { Dictionary.Type type; } { - ( <HASH> { field.addOperation(new DictionaryOperation(DictionaryOperation.Operation.HASH)); } - | <BTREE> { field.addOperation(new DictionaryOperation(DictionaryOperation.Operation.BTREE)); } - | <CASED> { field.addOperation(new DictionaryOperation(DictionaryOperation.Operation.CASED)); } - | <UNCASED> { field.addOperation(new DictionaryOperation(DictionaryOperation.Operation.UNCASED)); }) + ( <HASH> { field.dictionary(DictionaryOption.HASH); } + | <BTREE> { field.dictionary(DictionaryOption.BTREE); } + | <CASED> { field.dictionary(DictionaryOption.CASED); } + | <UNCASED> { field.dictionary(DictionaryOption.UNCASED); } ) { } } /** * This rule consumes a body statement of a field element. - * - * @param field The field to modify. */ -void body(SDField field) : { } +void body() : { } { <BODY> { - deployLogger.logApplicationPackage(Level.WARNING, field + ": 'header/body' is deprecated and has no effect."); + deployLogger.logApplicationPackage(Level.WARNING, "'body' is deprecated and has no effect."); } } /** * This rule consumes a header statement of a field element. - * - * @param field The field to modify. */ -void header(SDField field) : { } +void header() : { } { <HEADER> { - deployLogger.logApplicationPackage(Level.WARNING, field + ": 'header/body' is deprecated and has no effect."); + deployLogger.logApplicationPackage(Level.WARNING, "'header' is deprecated and has no effect."); } } -void queryCommand(FieldOperationContainer container) : +void queryCommand(ParsedField field) : { String command; - QueryCommandOperation field = new QueryCommandOperation(); } { <QUERYCOMMAND> <COLON> ( command = identifierWithDash() | command = quotedString() ) { field.addQueryCommand(command); - container.addOperation(field); } } -void alias(FieldOperationContainer container) : +void alias(ParsedField field) : { - String aliasedName = null; + String aliasedName = field.name(); String alias; } { <ALIAS> [aliasedName = identifier()] <COLON> alias = identifierWithDash() { - AliasOperation op = new AliasOperation(aliasedName, alias); - container.addOperation(op); + field.addAlias(aliasedName, alias); } } -FieldOperationContainer match(FieldOperationContainer field) : { } +void match(ParsedField field) : { - <MATCH> ( (<COLON> matchType(field)) - | (lbrace() (matchItem(field) (<NL>)*)* <RBRACE>) ) - { return field; } + ParsedMatchSettings matchInfo; +} +{ + matchInfo = matchSettings() { field.addMatchSettings(matchInfo); } } -/** - * This rule consumes a single match item for a match block. - * - * @param field The field to modify. - */ -void matchItem(FieldOperationContainer field) : { } +ParsedMatchSettings matchSettings() : +{ + ParsedMatchSettings matchInfo = new ParsedMatchSettings(); +} { - ( matchType(field) | exactTerminator(field) | gramSize(field) | matchSize(field) ) + <MATCH> ( (<COLON> matchType(matchInfo)) + | (lbrace() (matchItem(matchInfo) (<NL>)*)* <RBRACE>) ) + { return matchInfo; } } -void matchType(FieldOperationContainer container) : +void matchType(ParsedMatchSettings matchInfo) : { } { - MatchOperation matchOp = new MatchOperation(); + ( <MTOKEN> { matchInfo.setType(MatchType.TEXT); } // Deprecated synonym to TEXT + | <TEXT> { matchInfo.setType(MatchType.TEXT); } + | <WORD> { matchInfo.setType(MatchType.WORD); } + | <EXACT> { matchInfo.setType(MatchType.EXACT); } + | <GRAM> { matchInfo.setType(MatchType.GRAM); } + | <CASED> { matchInfo.setCase(MatchCase.CASED); } + | <UNCASED> { matchInfo.setCase(MatchCase.UNCASED); } + | <PREFIX> { matchInfo.setAlgorithm(MatchAlgorithm.PREFIX); } + | <SUBSTRING> { matchInfo.setAlgorithm(MatchAlgorithm.SUBSTRING); } + | <SUFFIX> { matchInfo.setAlgorithm(MatchAlgorithm.SUFFIX); } ) } + + +/** + * This rule consumes a single match item for a match block. + * + * @param matchInfo The settings to modify. + */ +void matchItem(ParsedMatchSettings matchInfo) : { } { - ( <MTOKEN> { matchOp.setMatchingType(Matching.Type.TEXT); } // Deprecated synonym to TEXT - | <TEXT> { matchOp.setMatchingType(Matching.Type.TEXT); } - | <WORD> { matchOp.setMatchingType(Matching.Type.WORD); } - | <EXACT> { matchOp.setMatchingType(Matching.Type.EXACT); } - | <GRAM> { matchOp.setMatchingType(Matching.Type.GRAM); } - | <CASED> { matchOp.setCase(Case.CASED); } - | <UNCASED> { matchOp.setCase(Case.UNCASED); } - | <PREFIX> { matchOp.setMatchingAlgorithm(Matching.Algorithm.PREFIX); } - | <SUBSTRING> { matchOp.setMatchingAlgorithm(Matching.Algorithm.SUBSTRING); } - | <SUFFIX> { matchOp.setMatchingAlgorithm(Matching.Algorithm.SUFFIX); } ) - { - container.addOperation(matchOp); - } + ( matchType(matchInfo) | exactTerminator(matchInfo) | gramSize(matchInfo) | matchSize(matchInfo) ) } -void exactTerminator(FieldOperationContainer container) : +void exactTerminator(ParsedMatchSettings matchInfo) : { String terminator; - MatchOperation field = new MatchOperation(); } { <EXACTTERMINATOR> <COLON> terminator = quotedString() { - field.setExactMatchTerminator(terminator); - container.addOperation(field); + matchInfo.setExactTerminator(terminator); } } -void gramSize(FieldOperationContainer container) : +void gramSize(ParsedMatchSettings matchInfo) : { int gramSize; - MatchOperation field = new MatchOperation(); } { <GRAMSIZE> <COLON> gramSize = integer() { - field.setGramSize(gramSize); - container.addOperation(field); + matchInfo.setGramSize(gramSize); } } -void matchSize(FieldOperationContainer container) : +void matchSize(ParsedMatchSettings matchInfo) : { int matchSize; - MatchOperation field = new MatchOperation(); } { - <MAXLENGTH> <COLON> matchSize = integer() - { - field.setMaxLength(matchSize); - container.addOperation(field); + <MAXLENGTH> <COLON> matchSize = integer() { + matchInfo.setMaxLength(matchSize); } } + /** * Consumes a rank statement of a field element. * * @param field The field to modify. */ -void rank(FieldOperationContainer field) : +void rank(ParsedField field) : { } { - RankOperation op = new RankOperation(); -} -{ - <RANK> ( (<COLON> rankSetting(op)) - | (lbrace() (rankSetting(op) (<NL>)*)* <RBRACE>) ) - { - field.addOperation(op); - } + <RANK> ( (<COLON> rankSetting(field)) + | (lbrace() (rankSetting(field) (<NL>)*)* <RBRACE>) ) } /** @@ -1667,7 +1591,7 @@ void rank(FieldOperationContainer field) : * * @param field The field to modify. */ -void rankSetting(RankOperation field) : { } +void rankSetting(ParsedField field) : { } { ( <LITERAL> { field.setLiteral(true); } | <NORMAL> { field.setNormal(true); } @@ -1678,19 +1602,15 @@ void rankSetting(RankOperation field) : { } * Consumes an id statement of a field body block. * * @param field The field to modify. - * @param document The document type to modify. */ -void id(FieldOperationContainer field, SDDocumentType document) : +void id(ParsedField field) : { int fieldId; - IdOperation op = new IdOperation(); } { <ID> <COLON> fieldId = integer() { - op.setDocument(document); - op.setFieldId(fieldId); - field.addOperation(op); + field.setId(fieldId); } } @@ -1699,7 +1619,7 @@ void id(FieldOperationContainer field, SDDocumentType document) : * * @param field The field to modify. */ -void indexingRewrite(FieldOperationContainer field) : { } +void indexingRewrite(ParsedField field) : { } { <INDEXINGREWRITE> <COLON> <NONE> { deployLogger.logApplicationPackage(Level.WARNING, "Specifying 'indexing-rewrite' is deprecated and has no effect."); } @@ -1710,15 +1630,15 @@ void indexingRewrite(FieldOperationContainer field) : { } * * @param schema the schema object to add content to */ -void documentSummary(Schema schema) : +void documentSummary(ParsedSchema schema) : { String name; - DocumentSummary summary; + ParsedDocumentSummary summary; } { ( <DOCUMENTSUMMARY> - name = identifierWithDash() { schema.addSummary(summary = new DocumentSummary(name, schema)); } - [inheritsDocumentSummary(summary, schema)] + name = identifierWithDash() { summary = new ParsedDocumentSummary(name); } + [inheritsDocumentSummary(summary)] lbrace() ( <FROMDISK> { summary.setFromDisk(true); } | @@ -1727,23 +1647,23 @@ void documentSummary(Schema schema) : <NL> )* <RBRACE> - ) + ) + { schema.addDocumentSummary(summary); } } /** * This rule consumes an inherits statement of a document summary. * * @param documentSummary the document summary to modify - * @param schema the schema object documentSummary is being added to */ -void inheritsDocumentSummary(DocumentSummary documentSummary, Schema schema) : +void inheritsDocumentSummary(ParsedDocumentSummary documentSummary) : { String name; } { <INHERITS> name = identifierWithDash() { - documentSummary.setInherited(name); + documentSummary.inherit(name); } } @@ -1752,50 +1672,62 @@ void inheritsDocumentSummary(DocumentSummary documentSummary, Schema schema) : * * @param summary The document summary to modify. */ -void documentSummaryItem(DocumentSummary summary) : { } +void documentSummaryItem(ParsedDocumentSummary summary) : { } { summaryInDocument(summary) } /** - * Consumes an index block for a field element. + * Consumes an index block in a schema element. * * @param schema the schema object to add content to + */ +void indexOutsideDoc(ParsedSchema schema) : +{ + ParsedIndex op; + String indexName; +} +{ + <INDEX> indexName = identifier() + { + op = new ParsedIndex(indexName); + } + ( (<COLON> indexBody(op) (<COMMA> indexBody(op))*) | + (lbrace() (indexBody(op) (<NL>)*)* <RBRACE>) ) + { + schema.addIndex(op); + } +} + +/** + * Consumes an index block for a field element. + * * @param field the field to modify */ -void index(Schema schema, FieldOperationContainer field) : +void indexInsideField(ParsedField field) : { - IndexOperation op = new IndexOperation(); - String indexName = (field != null) ? field.getName() : null; + ParsedIndex op; + String indexName = field.name(); } { <INDEX> [indexName = identifier()] { - if (indexName == null) { - throw new ParseException("Index statements outside fields must have an explicit name."); - } - op.setIndexName(indexName); + op = new ParsedIndex(indexName); } ( (<COLON> indexBody(op) (<COMMA> indexBody(op))*) | (lbrace() (indexBody(op) (<NL>)*)* <RBRACE>) ) { - if (field == null) { - - Index index = new Index(indexName); - op.applyToIndex(index); - schema.addIndex(index); - } else { - field.addOperation(op); - } + field.addIndex(op); } } + /** * Consumes a single index statement for an index block. * * @param index The index to modify. */ -void indexBody(IndexOperation index) : +void indexBody(ParsedIndex index) : { String str; int arity; @@ -1815,7 +1747,7 @@ void indexBody(IndexOperation index) : ) } -void hnswIndex(IndexOperation index) : +void hnswIndex(ParsedIndex index) : { HnswIndexParams.Builder params = new HnswIndexParams.Builder(); } @@ -1824,7 +1756,7 @@ void hnswIndex(IndexOperation index) : <HNSW> ( (lbrace() (hnswIndexBody(params) (<NL>)*)* <RBRACE>) ) | <HNSW> ) { - index.setHnswIndexParams(params); + index.setHnswIndexParams(params.build()); } } |