blob: d3fa3282f4f320927f8c6136a04a605a688edb93 (
plain) (
blame)
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.processing;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.searchdefinition.RankProfileRegistry;
import com.yahoo.document.DataType;
import com.yahoo.searchdefinition.Schema;
import com.yahoo.searchdefinition.document.ImmutableSDField;
import com.yahoo.searchdefinition.document.Matching;
import com.yahoo.document.NumericDataType;
import com.yahoo.vespa.model.container.search.QueryProfiles;
/**
* Fields that derive to attribute(s) and no indices should use the WORD indexing form,
* in a feeble attempt to match the most peoples expectations as closely as possible.
*
* @author Vegard Havdal
*/
public class AttributesImplicitWord extends Processor {
public AttributesImplicitWord(Schema schema, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
super(schema, deployLogger, rankProfileRegistry, queryProfiles);
}
@Override
public void process(boolean validate, boolean documentsOnly) {
for (ImmutableSDField field : schema.allConcreteFields()) {
processFieldRecursive(field);
}
}
private void processFieldRecursive(ImmutableSDField field) {
processField(field);
for (ImmutableSDField structField : field.getStructFields()) {
processFieldRecursive(structField);
}
}
private void processField(ImmutableSDField field) {
if (fieldImplicitlyWordMatch(field)) {
field.getMatching().setType(Matching.Type.WORD);
}
}
private boolean fieldImplicitlyWordMatch(ImmutableSDField field) {
// numeric types should not trigger exact-match query parsing
DataType dt = field.getDataType().getPrimitiveType();
if (dt != null && dt instanceof NumericDataType) {
return false;
}
return (! field.hasIndex()
&& !field.getAttributes().isEmpty()
&& field.getIndices().isEmpty()
&& !field.getMatching().isTypeUserSet());
}
}
|