diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /container-search/src/main/java/com/yahoo/prelude/query/MarkerWordItem.java |
Publish
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/query/MarkerWordItem.java')
-rw-r--r-- | container-search/src/main/java/com/yahoo/prelude/query/MarkerWordItem.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/MarkerWordItem.java b/container-search/src/main/java/com/yahoo/prelude/query/MarkerWordItem.java new file mode 100644 index 00000000000..8fb16e8a3ba --- /dev/null +++ b/container-search/src/main/java/com/yahoo/prelude/query/MarkerWordItem.java @@ -0,0 +1,60 @@ +// Copyright 2016 Yahoo Inc. 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; + + +/** + * Special words known by the index used for marking things. + * The reserved word itself is not public, while a symbol representation is. + * + * @author <a href="mailto:bratseth@yahoo-inc.com">Jon S Bratseth</a> + */ +public class MarkerWordItem extends WordItem { + + /** Creates a special word item which marks the start of a host name */ + public static WordItem createStartOfHost() { + return new MarkerWordItem("^", UrlTokenizer.TERM_STARTHOST); + } + + /** Creates a special word item which marks the end of a host name */ + public static WordItem createEndOfHost() { + return new MarkerWordItem("$", UrlTokenizer.TERM_ENDHOST); + } + + private String markerWord; + + private MarkerWordItem(String publicSymbol, String markerWord) { + super(publicSymbol); + this.markerWord = markerWord; + } + + /** Returns the marker word for encoding */ + protected String getEncodedWord() { + return markerWord; + } + + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (!(o instanceof MarkerWordItem)) { + return false; + } + + MarkerWordItem other = (MarkerWordItem) o; + + return markerWord.equals(other.markerWord); + } + + public int hashCode() { + return super.hashCode() + 499 * markerWord.hashCode(); + } + + @Override + public void disclose(Discloser discloser) { + super.disclose(discloser); + discloser.addProperty("markerWord", markerWord); + } +} |