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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.processing.multifieldresolver;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.searchdefinition.document.SDField;
import com.yahoo.searchdefinition.Search;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
/**
* Resolver-class for harmonizing index-commands in multifield indexes
*/
public class IndexCommandResolver extends MultiFieldResolver {
/** Commands which don't have to be harmonized between fields */
private static List<String> ignoredCommands = new ArrayList<>();
/** Commands which must be harmonized between fields */
private static List<String> harmonizedCommands = new ArrayList<>();
static {
String[] ignore = { "complete-boost", "literal-boost", "highlight" };
ignoredCommands.addAll(Arrays.asList(ignore));
String[] harmonize = { "stemming", "normalizing" };
harmonizedCommands.addAll(Arrays.asList(harmonize));
}
public IndexCommandResolver(String indexName, List<SDField> fields, Search search, DeployLogger logger) {
super(indexName, fields, search, logger);
}
/**
* Check index-commands for each field, report and attempt to fix any
* inconsistencies
*/
public void resolve() {
for (SDField field : fields) {
for (String command : field.getQueryCommands()) {
if (!ignoredCommands.contains(command))
checkCommand(command);
}
}
}
private void checkCommand(String command) {
for (SDField field : fields) {
if (!field.hasQueryCommand(command)) {
if (harmonizedCommands.contains(command)) {
deployLogger.log(Level.WARNING, command + " must be added to all fields going to the same index (" + indexName + ")" +
", adding to field " + field.getName());
field.addQueryCommand(command);
} else {
deployLogger.log(Level.WARNING, "All fields going to the same index should have the same query-commands. Field \'" + field.getName() +
"\' doesn't contain command \'" + command+"\'");
}
}
}
}
}
|