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
|
// Copyright 2017 Yahoo Holdings. 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.document.ArrayDataType;
import com.yahoo.document.CollectionDataType;
import com.yahoo.document.DataType;
import com.yahoo.document.WeightedSetDataType;
import com.yahoo.searchdefinition.RankProfileRegistry;
import com.yahoo.searchdefinition.Search;
import com.yahoo.searchdefinition.document.SDField;
import com.yahoo.searchdefinition.document.Stemming;
import com.yahoo.vespa.model.container.search.QueryProfiles;
import java.util.Arrays;
import java.util.List;
/**
* @author baldersheim
*/
public class UriHack extends Processor {
private static final List<String> URL_SUFFIX =
Arrays.asList("scheme", "host", "port", "path", "query", "fragment", "hostname");
UriHack(Search search,
DeployLogger deployLogger,
RankProfileRegistry rankProfileRegistry,
QueryProfiles queryProfiles) {
super(search, deployLogger, rankProfileRegistry, queryProfiles);
}
@Override
public void process(boolean validate, boolean documentsOnly) {
for (SDField field : search.allConcreteFields()) {
if (field.doesIndexing()) {
DataType fieldType = field.getDataType();
if (fieldType instanceof CollectionDataType) {
fieldType = ((CollectionDataType)fieldType).getNestedType();
}
if (fieldType == DataType.URI) {
processField(search, field);
}
}
}
}
private void processField(Search search, SDField uriField) {
String uriName = uriField.getName();
uriField.setStemming(Stemming.NONE);
DataType generatedType = DataType.STRING;
if (uriField.getDataType() instanceof ArrayDataType) {
generatedType = new ArrayDataType(DataType.STRING);
}
else if (uriField.getDataType() instanceof WeightedSetDataType) {
WeightedSetDataType wdt = (WeightedSetDataType) uriField.getDataType();
generatedType = new WeightedSetDataType(DataType.STRING, wdt.createIfNonExistent(), wdt.removeIfZero());
}
for (String suffix : URL_SUFFIX) {
String partName = uriName + "." + suffix;
// I wonder if this is explicit in qrs or implicit in backend?
// search.addFieldSetItem(uriName, partName);
SDField partField = new SDField(partName, generatedType);
partField.setIndexStructureField(uriField.doesIndexing());
partField.setRankType(uriField.getRankType());
partField.setStemming(Stemming.NONE);
partField.getNormalizing().inferLowercase();
if (uriField.getIndex(suffix) != null) {
partField.addIndex(uriField.getIndex(suffix));
}
search.addExtraField(partField);
search.fieldSets().addBuiltInFieldSetItem(BuiltInFieldSets.INTERNAL_FIELDSET_NAME, partField.getName());
}
}
}
|