Example usage for org.apache.lucene.queries.function FunctionValues exists

List of usage examples for org.apache.lucene.queries.function FunctionValues exists

Introduction

In this page you can find the example usage for org.apache.lucene.queries.function FunctionValues exists.

Prototype

public boolean exists(int doc) throws IOException 

Source Link

Document

Returns true if there is a value for this document

Usage

From source file:org.apache.solr.analytics.util.valuesource.DualDoubleFunction.java

License:Apache License

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues aVals = a.getValues(context, readerContext);
    final FunctionValues bVals = b.getValues(context, readerContext);
    return new DoubleDocValues(this) {
        @Override//from w w  w .ja  va2  s .  c  o  m
        public double doubleVal(int doc) {
            return func(doc, aVals, bVals);
        }

        @Override
        public boolean exists(int doc) {
            return aVals.exists(doc) & bVals.exists(doc);
        }

        @Override
        public String toString(int doc) {
            return name() + '(' + aVals.toString(doc) + ',' + bVals.toString(doc) + ')';
        }
    };
}

From source file:org.apache.solr.analytics.util.valuesource.MultiDateFunction.java

License:Apache License

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues[] valsArr = new FunctionValues[sources.length];
    for (int i = 0; i < sources.length; i++) {
        valsArr[i] = sources[i].getValues(context, readerContext);
    }/* w w  w.  ja va  2 s  .  c o  m*/

    return new LongDocValues(this) {
        @Override
        public long longVal(int doc) {
            return func(doc, valsArr);
        }

        @Override
        public boolean exists(int doc) {
            boolean exists = true;
            for (FunctionValues val : valsArr) {
                exists = exists & val.exists(doc);
            }
            return exists;
        }

        @Override
        public String toString(int doc) {
            StringBuilder sb = new StringBuilder();
            sb.append(name()).append('(');
            boolean firstTime = true;
            for (FunctionValues vals : valsArr) {
                if (firstTime) {
                    firstTime = false;
                } else {
                    sb.append(',');
                }
                sb.append(vals.toString(doc));
            }
            sb.append(')');
            return sb.toString();
        }

        @Override
        public ValueFiller getValueFiller() {
            return new ValueFiller() {
                private final MutableValueDate mval = new MutableValueDate();

                @Override
                public MutableValue getValue() {
                    return mval;
                }

                @Override
                public void fillValue(int doc) {
                    mval.value = longVal(doc);
                    mval.exists = exists(doc);
                }
            };
        }
    };
}

From source file:org.apache.solr.analytics.util.valuesource.MultiDoubleFunction.java

License:Apache License

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues[] valsArr = new FunctionValues[sources.length];
    for (int i = 0; i < sources.length; i++) {
        valsArr[i] = sources[i].getValues(context, readerContext);
    }//ww  w. j a  v  a  2 s .c  o  m

    return new DoubleDocValues(this) {
        @Override
        public double doubleVal(int doc) {
            return func(doc, valsArr);
        }

        @Override
        public boolean exists(int doc) {
            boolean exists = true;
            for (FunctionValues val : valsArr) {
                exists = exists & val.exists(doc);
            }
            return exists;
        }

        @Override
        public String toString(int doc) {
            StringBuilder sb = new StringBuilder();
            sb.append(name()).append('(');
            boolean firstTime = true;
            for (FunctionValues vals : valsArr) {
                if (firstTime) {
                    firstTime = false;
                } else {
                    sb.append(',');
                }
                sb.append(vals.toString(doc));
            }
            sb.append(')');
            return sb.toString();
        }
    };
}

From source file:org.apache.solr.analytics.util.valuesource.MultiStringFunction.java

License:Apache License

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues[] valsArr = new FunctionValues[sources.length];
    for (int i = 0; i < sources.length; i++) {
        valsArr[i] = sources[i].getValues(context, readerContext);
    }//from  ww  w .j  av  a  2  s. c  o  m

    return new StrDocValues(this) {
        @Override
        public String strVal(int doc) {
            CharSequence cs = func(doc, valsArr);
            return cs != null ? cs.toString() : null;
        }

        @Override
        public boolean exists(int doc) {
            boolean exists = true;
            for (FunctionValues val : valsArr) {
                exists = exists & val.exists(doc);
            }
            return exists;
        }

        @Override
        public boolean bytesVal(int doc, BytesRefBuilder bytes) {
            bytes.clear();
            CharSequence cs = func(doc, valsArr);
            if (cs != null) {
                bytes.copyChars(func(doc, valsArr));
                return true;
            } else {
                return false;
            }
        }

        @Override
        public String toString(int doc) {
            StringBuilder sb = new StringBuilder();
            sb.append(name()).append('(');
            boolean firstTime = true;
            for (FunctionValues vals : valsArr) {
                if (firstTime) {
                    firstTime = false;
                } else {
                    sb.append(',');
                }
                sb.append(vals.toString(doc));
            }
            sb.append(')');
            return sb.toString();
        }

        @Override
        public ValueFiller getValueFiller() {
            return new ValueFiller() {
                private final MutableValueStr mval = new MutableValueStr();

                @Override
                public MutableValue getValue() {
                    return mval;
                }

                @Override
                public void fillValue(int doc) {
                    mval.exists = bytesVal(doc, mval.value);
                }
            };
        }
    };
}

From source file:org.apache.solr.analytics.util.valuesource.SingleDoubleFunction.java

License:Apache License

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues vals = source.getValues(context, readerContext);
    return new DoubleDocValues(this) {
        @Override//w  w w  .j a  va2s.com
        public double doubleVal(int doc) {
            return func(doc, vals);
        }

        @Override
        public boolean exists(int doc) {
            return vals.exists(doc);
        }

        @Override
        public String toString(int doc) {
            return name() + '(' + vals.toString(doc) + ')';
        }
    };
}

From source file:org.apache.solr.analytics.util.valuesource.SingleStringFunction.java

License:Apache License

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues vals = source.getValues(context, readerContext);
    return new StrDocValues(this) {
        @Override/*  www  .j  av a2s  .  c  om*/
        public String strVal(int doc) {
            CharSequence cs = func(doc, vals);
            return cs != null ? cs.toString() : null;
        }

        @Override
        public boolean bytesVal(int doc, BytesRefBuilder bytes) {
            CharSequence cs = func(doc, vals);
            if (cs != null) {
                bytes.copyChars(func(doc, vals));
                return true;
            } else {
                bytes.clear();
                return false;
            }
        }

        @Override
        public Object objectVal(int doc) {
            return strVal(doc);
        }

        @Override
        public boolean exists(int doc) {
            return vals.exists(doc);
        }

        @Override
        public String toString(int doc) {
            return name() + '(' + strVal(doc) + ')';
        }

        @Override
        public ValueFiller getValueFiller() {
            return new ValueFiller() {
                private final MutableValueStr mval = new MutableValueStr();

                @Override
                public MutableValue getValue() {
                    return mval;
                }

                @Override
                public void fillValue(int doc) {
                    mval.exists = bytesVal(doc, mval.value);
                }
            };
        }
    };
}

From source file:org.apache.solr.search.function.MultiStringFunction.java

License:Apache License

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues[] valsArr = new FunctionValues[sources.length];
    for (int i = 0; i < sources.length; i++) {
        valsArr[i] = sources[i].getValues(context, readerContext);
    }//from  w ww  .j  av a2s.  c  o m

    return new StrDocValues(this) {
        @Override
        public String strVal(int doc) throws IOException {
            CharSequence cs = func(doc, valsArr);
            return cs != null ? cs.toString() : null;
        }

        @Override
        public boolean exists(int doc) throws IOException {
            boolean exists = true;
            for (FunctionValues val : valsArr) {
                exists = exists & val.exists(doc);
            }
            return exists;
        }

        @Override
        public boolean bytesVal(int doc, BytesRefBuilder bytes) throws IOException {
            bytes.clear();
            CharSequence cs = func(doc, valsArr);
            if (cs != null) {
                bytes.copyChars(func(doc, valsArr));
                return true;
            } else {
                return false;
            }
        }

        @Override
        public String toString(int doc) throws IOException {
            StringBuilder sb = new StringBuilder();
            sb.append(name()).append('(');
            boolean firstTime = true;
            for (FunctionValues vals : valsArr) {
                if (firstTime) {
                    firstTime = false;
                } else {
                    sb.append(',');
                }
                sb.append(vals.toString(doc));
            }
            sb.append(')');
            return sb.toString();
        }

        @Override
        public ValueFiller getValueFiller() {
            return new ValueFiller() {
                private final MutableValueStr mval = new MutableValueStr();

                @Override
                public MutableValue getValue() {
                    return mval;
                }

                @Override
                public void fillValue(int doc) throws IOException {
                    mval.exists = bytesVal(doc, mval.value);
                }
            };
        }
    };
}