1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema.processing;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.schema.RankProfileRegistry;
import com.yahoo.schema.Schema;
import com.yahoo.schema.document.FieldSet;
import com.yahoo.schema.document.ImmutableSDField;
import com.yahoo.schema.document.Matching;
import com.yahoo.schema.document.NormalizeLevel;
import com.yahoo.schema.document.Stemming;
import com.yahoo.vespa.model.container.search.QueryProfiles;
/**
* Computes the right "index commands" for each fieldset in a search definition.
*
* @author vegardh
* @author bratseth
*/
// See also IndexInfo.addFieldSetCommands, which does more of this in a complicated way.
// That should be moved here, and done in the way the match setting is done below
// (this requires adding normalizing and stemming settings to FieldSet).
public class FieldSetSettings extends Processor {
public FieldSetSettings(Schema schema,
DeployLogger deployLogger,
RankProfileRegistry rankProfileRegistry,
QueryProfiles queryProfiles) {
super(schema, deployLogger, rankProfileRegistry, queryProfiles);
}
@Override
public void process(boolean validate, boolean documentsOnly) {
for (FieldSet fieldSet : schema.fieldSets().userFieldSets().values()) {
if (validate)
checkFieldNames(schema, fieldSet);
checkMatching(schema, fieldSet);
checkNormalization(schema, fieldSet);
checkStemming(schema, fieldSet);
}
}
private void checkFieldNames(Schema schema, FieldSet fieldSet) {
for (String field : fieldSet.getFieldNames()) {
if (schema.getField(field) == null)
throw new IllegalArgumentException("For " + schema + ": Field '" + field + "' in " +
fieldSet + " does not exist.");
}
}
private void checkMatching(Schema schema, FieldSet fieldSet) {
Matching matching = fieldSet.getMatching();
for (String fieldName : fieldSet.getFieldNames()) {
ImmutableSDField field = schema.getField(fieldName);
Matching fieldMatching = field.getMatching();
if (matching == null) {
matching = fieldMatching;
} else {
if ( ! matching.equals(fieldMatching)) {
warn(schema, field.asField(),
"The matching settings for the fields in " + fieldSet + " are inconsistent " +
"(explicitly or because of field type). This may lead to recall and ranking issues.");
return;
}
}
}
fieldSet.setMatching(matching); // Assign the uniquely determined matching to the field set
}
private void checkNormalization(Schema schema, FieldSet fieldSet) {
NormalizeLevel.Level normalizing = null;
for (String fieldName : fieldSet.getFieldNames()) {
ImmutableSDField field = schema.getField(fieldName);
NormalizeLevel.Level fieldNorm = field.getNormalizing().getLevel();
if (normalizing == null) {
normalizing = fieldNorm;
} else {
if ( ! normalizing.equals(fieldNorm)) {
warn(schema, field.asField(),
"The normalization settings for the fields in " + fieldSet + " are inconsistent " +
"(explicitly or because of field type). This may lead to recall and ranking issues.");
return;
}
}
}
}
private void checkStemming(Schema schema, FieldSet fieldSet) {
Stemming stemming = null;
for (String fieldName : fieldSet.getFieldNames()) {
ImmutableSDField field = schema.getField(fieldName);
Stemming fieldStemming = field.getStemming();
if (stemming == null) {
stemming = fieldStemming;
} else {
if ( ! stemming.equals(fieldStemming)) {
warn(schema, field.asField(),
"The stemming settings for the fields in the fieldset '"+fieldSet.getName()+
"' are inconsistent (explicitly or because of field type). " +
"This may lead to recall and ranking issues.");
return;
}
}
}
}
}
|