blob: 75187f8b8e13f043104a554f5530bec37b44f050 (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.query;
import com.yahoo.net.UrlTokenizer;
import com.yahoo.prelude.query.textualrepresentation.Discloser;
import java.util.Objects;
/**
* Special words known by the index used for marking things.
* The reserved word itself is not public, while a symbol representation is.
*
* @author bratseth
*/
public class MarkerWordItem extends WordItem {
private final String markerWord;
private final static String startAnchor = "^";
private final static String endAnchor = "$";
private MarkerWordItem(String publicSymbol, String markerWord, String indexName) {
super(publicSymbol, indexName);
this.markerWord = markerWord;
}
public boolean isStartAnchor() { return getWord().equals(startAnchor); }
public boolean isEndAnchor() { return getWord().equals(endAnchor); }
/** Returns the marker word for encoding */
@Override
protected String getEncodedWord() {
return markerWord;
}
@Override
public boolean equals(Object o) {
if (!super.equals(o)) return false;
MarkerWordItem other = (MarkerWordItem) o;
return markerWord.equals(other.markerWord);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), markerWord);
}
@Override
public void disclose(Discloser discloser) {
super.disclose(discloser);
discloser.addProperty("markerWord", markerWord);
}
/** Creates a special word item which marks the start of a host name */
public static MarkerWordItem createStartOfHost(String indexName) {
return new MarkerWordItem(startAnchor, UrlTokenizer.TERM_STARTHOST, indexName);
}
/** Creates a special word item which marks the start of a host name, matching the default index */
public static MarkerWordItem createStartOfHost() {
return createStartOfHost("");
}
/** Creates a special word item which marks the end of a host name */
public static MarkerWordItem createEndOfHost(String indexName) {
return new MarkerWordItem(endAnchor, UrlTokenizer.TERM_ENDHOST, indexName);
}
/** Creates a special word item which marks the end of a host name matching the default index */
public static MarkerWordItem createEndOfHost() {
return createEndOfHost("");
}
}
|