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/AndSegmentItem.java |
Publish
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/query/AndSegmentItem.java')
-rw-r--r-- | container-search/src/main/java/com/yahoo/prelude/query/AndSegmentItem.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/AndSegmentItem.java b/container-search/src/main/java/com/yahoo/prelude/query/AndSegmentItem.java new file mode 100644 index 00000000000..189c8260785 --- /dev/null +++ b/container-search/src/main/java/com/yahoo/prelude/query/AndSegmentItem.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 java.util.Iterator; + +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * An immutable and'ing of a collection of sub-expressions. It does not extend + * AndItem to avoid code using instanceof handling it as an AndItem. + * + * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + */ +public class AndSegmentItem extends SegmentItem implements BlockItem { + + public AndSegmentItem(String rawWord, boolean isFromQuery, boolean stemmed) { + super(rawWord, rawWord, isFromQuery, stemmed, null); + } + + public AndSegmentItem(String rawWord, String current, boolean isFromQuery, boolean stemmed) { + super(rawWord, current, isFromQuery, stemmed, null); + } + + public AndSegmentItem(PhraseSegmentItem item) { + super(item.getRawWord(), item.stringValue(), item.isFromQuery(), item.isStemmed(), null); + int weight = item.getWeight(); + if (item.getItemCount() > 0) { + for (Iterator<Item> i = item.getItemIterator(); i.hasNext();) { + WordItem word = (WordItem) i.next(); + word.setWeight(weight); + addItem(word); + } + } + } + + public ItemType getItemType() { + return ItemType.AND; + } + + public String getName() { + return "SAND"; + } + + @NonNull + public String getIndexName() { + if (getItemCount() == 0) { + return ""; + } else { + return ((IndexedItem) getItem(0)).getIndexName(); + } + } + + // TODO: Is it necessary to override equals? + + public void setWeight(int w) { + for (Iterator<Item> i = getItemIterator(); i.hasNext();) { + i.next().setWeight(w); + } + } +} |