Java Code Examples for org.apache.lucene.queries.function.FunctionValues#exists()

The following examples show how to use org.apache.lucene.queries.function.FunctionValues#exists() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScaleFloatFunction.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private ScaleInfo createScaleInfo(Map<Object, Object> context, LeafReaderContext readerContext) throws IOException {
  final List<LeafReaderContext> leaves = ReaderUtil.getTopLevelContext(readerContext).leaves();

  float minVal = Float.POSITIVE_INFINITY;
  float maxVal = Float.NEGATIVE_INFINITY;

  for (LeafReaderContext leaf : leaves) {
    int maxDoc = leaf.reader().maxDoc();
    FunctionValues vals =  source.getValues(context, leaf);
    for (int i=0; i<maxDoc; i++) {
      if ( ! vals.exists(i) ) {
        continue;
      }
      float val = vals.floatVal(i);
      if ((Float.floatToRawIntBits(val) & (0xff<<23)) == 0xff<<23) {
        // if the exponent in the float is all ones, then this is +Inf, -Inf or NaN
        // which don't make sense to factor into the scale function
        continue;
      }
      if (val < minVal) {
        minVal = val;
      }
      if (val > maxVal) {
        maxVal = val;
      }
    }
  }

  if (minVal == Float.POSITIVE_INFINITY) {
  // must have been an empty index
    minVal = maxVal = 0;
  }

  ScaleInfo scaleInfo = new ScaleInfo();
  scaleInfo.minVal = minVal;
  scaleInfo.maxVal = maxVal;
  context.put(ScaleFloatFunction.this, scaleInfo);
  return scaleInfo;
}
 
Example 2
Source File: MaxFloatFunction.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected float func(int doc, FunctionValues[] valsArr) throws IOException {
  if ( ! exists(doc, valsArr) ) return 0.0f;

  float val = Float.NEGATIVE_INFINITY;
  for (FunctionValues vals : valsArr) {
    if (vals.exists(doc)) {
      val = Math.max(vals.floatVal(doc), val);
    }
  }
  return val;
}
 
Example 3
Source File: MultiFunction.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Helper utility for {@link FunctionValues}
 *
 * @return true if <em>all</em> of the specified <code>values</code>
 *         {@link FunctionValues#exists} for the specified doc, else false.
 */
public static boolean allExists(int doc, FunctionValues[] values) throws IOException {
  for (FunctionValues v : values) {
    if ( ! v.exists(doc) ) {
      return false;
    }
  }
  return true;
}
 
Example 4
Source File: MultiFunction.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Helper utility for {@link FunctionValues}
 *
 * @return true if <em>any</em> of the specified <code>values</code>
 *         {@link FunctionValues#exists} for the specified doc, else false.
 */
public static boolean anyExists(int doc, FunctionValues[] values) throws IOException {
  for (FunctionValues v : values) {
    if ( v.exists(doc) ) {
      return true;
    }
  }
  return false;
}
 
Example 5
Source File: MinFloatFunction.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected float func(int doc, FunctionValues[] valsArr) throws IOException {
  if ( ! exists(doc, valsArr) ) return 0.0f;

  float val = Float.POSITIVE_INFINITY;
  for (FunctionValues vals : valsArr) {
    if (vals.exists(doc)) {
      val = Math.min(vals.floatVal(doc), val);
    }
  }
  return val;
}
 
Example 6
Source File: ValueSourceParser.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
  ValueSource vs = fp.parseValueSource();
  return new SimpleBoolFunction(vs) {
    @Override
    protected String name() {
      return "exists";
    }
    @Override
    protected boolean func(int doc, FunctionValues vals) throws IOException {
      return vals.exists(doc);
    }
  };
}
 
Example 7
Source File: MultiFunction.java    From lucene-solr with Apache License 2.0 2 votes vote down vote up
/**
 * Equivalent to the {@code FunctionValues[]} method with the same name, but optimized for
 * dealing with exactly 2 arguments.
 *
 * @return true if <em>both</em> of the specified <code>values</code>
 *         {@link FunctionValues#exists} for the specified doc, else false.
 * @see #anyExists(int,FunctionValues[])
 */
public static boolean allExists(int doc, FunctionValues values1, FunctionValues values2) throws IOException {
  return values1.exists(doc) && values2.exists(doc);
}
 
Example 8
Source File: MultiFunction.java    From lucene-solr with Apache License 2.0 2 votes vote down vote up
/**
 * Equivalent to the {@code FunctionValues[]} method with the same name, but optimized for
 * dealing with exactly 2 arguments.
 *
 * @return true if <em>either</em> of the specified <code>values</code>
 *         {@link FunctionValues#exists} for the specified doc, else false.
 * @see #anyExists(int,FunctionValues[])
 */
public static boolean anyExists(int doc, FunctionValues values1, FunctionValues values2) throws IOException {
  return values1.exists(doc) || values2.exists(doc);
}