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 /predicate-search/src/main/java/com/yahoo/search/predicate/PredicateQuery.java |
Publish
Diffstat (limited to 'predicate-search/src/main/java/com/yahoo/search/predicate/PredicateQuery.java')
-rw-r--r-- | predicate-search/src/main/java/com/yahoo/search/predicate/PredicateQuery.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/predicate-search/src/main/java/com/yahoo/search/predicate/PredicateQuery.java b/predicate-search/src/main/java/com/yahoo/search/predicate/PredicateQuery.java new file mode 100644 index 00000000000..779cd6cfd47 --- /dev/null +++ b/predicate-search/src/main/java/com/yahoo/search/predicate/PredicateQuery.java @@ -0,0 +1,84 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.search.predicate; + +import com.google.common.annotations.Beta; + +import java.util.ArrayList; +import java.util.List; + +/** + * Represents a query in the form of a set of boolean variables that are considered true. + * + * @author <a href="mailto:magnarn@yahoo-inc.com">Magnar Nedland</a> + * @author bjorncs + */ +@Beta +public class PredicateQuery { + + private final ArrayList<Feature> features = new ArrayList<>(); + private final ArrayList<RangeFeature> rangeFeatures = new ArrayList<>(); + + /** + * Adds a feature to the query. + * @param key Feature key + * @param value Feature value + */ + public void addFeature(String key, String value) { + addFeature(key, value, SubqueryBitmap.DEFAULT_VALUE); + } + /** + * Adds a feature to the query, e.g. gender = male. + * @param key Feature key + * @param value Feature value + * @param subqueryBitMap The subquery bitmap for which this term is true + */ + public void addFeature(String key, String value, long subqueryBitMap) { + features.add(new Feature(key, value, subqueryBitMap)); + } + public void addRangeFeature(String key, long value) { addRangeFeature(key, value, SubqueryBitmap.DEFAULT_VALUE);} + /** + * Adds a range feature to the query, e.g. age = 25. + * @param key Feature key + * @param value Feature value + * @param subqueryBitMap The subquery bitmap for which this term is true + */ + public void addRangeFeature(String key, long value, long subqueryBitMap) { + rangeFeatures.add(new RangeFeature(key, value, subqueryBitMap)); + } + /** + * @return A list of features + */ + public List<Feature> getFeatures() { return features; } + + /** + * @return A list of range features + */ + public List<RangeFeature> getRangeFeatures() { return rangeFeatures; } + + public static class Feature { + public final String key; + public final String value; + public final long subqueryBitmap; + public final long featureHash; + + public Feature(String key, String value, long subqueryBitmap) { + this.featureHash = com.yahoo.search.predicate.index.Feature.createHash(key, value); + this.subqueryBitmap = subqueryBitmap; + this.value = value; + this.key = key; + } + } + + public static class RangeFeature { + public final String key; + public final long value; + public final long subqueryBitmap; + + public RangeFeature(String key, long value, long subqueryBitmap) { + this.key = key; + this.value = value; + this.subqueryBitmap = subqueryBitmap; + } + } + +} |