当前位置: 首页>>代码示例>>Java>>正文


Java ValueSource.getValues方法代码示例

本文整理汇总了Java中org.apache.lucene.queries.function.ValueSource.getValues方法的典型用法代码示例。如果您正苦于以下问题:Java ValueSource.getValues方法的具体用法?Java ValueSource.getValues怎么用?Java ValueSource.getValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.queries.function.ValueSource的用法示例。


在下文中一共展示了ValueSource.getValues方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRangeScorer

import org.apache.lucene.queries.function.ValueSource; //导入方法依赖的package包/类
public void testRangeScorer() throws Exception {
  Expression expr = JavascriptCompiler.compile("2*popularity");
  SimpleBindings bindings = new SimpleBindings();
  bindings.add(new SortField("popularity", SortField.Type.LONG));
  ValueSource vs = expr.getValueSource(bindings);
  
  assertEquals(1, reader.leaves().size());
  AtomicReaderContext leaf = reader.leaves().get(0);
  FunctionValues values = vs.getValues(new HashMap<String,Object>(), leaf);
  
  // everything
  ValueSourceScorer scorer = values.getRangeScorer(leaf.reader(), "4", "40", true, true);
  assertEquals(-1, scorer.docID());
  assertEquals(0, scorer.nextDoc());
  assertEquals(1, scorer.nextDoc());
  assertEquals(2, scorer.nextDoc());
  assertEquals(DocIdSetIterator.NO_MORE_DOCS, scorer.nextDoc());

  // just the first doc
  scorer = values.getRangeScorer(leaf.reader(), "4", "40", false, false);
  assertEquals(-1, scorer.docID());
  assertEquals(0, scorer.nextDoc());
  assertEquals(DocIdSetIterator.NO_MORE_DOCS, scorer.nextDoc());
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:TestExpressionValueSource.java

示例2: getVersionFromIndex

import org.apache.lucene.queries.function.ValueSource; //导入方法依赖的package包/类
public Long getVersionFromIndex(BytesRef idBytes) {
  // TODO: we could cache much of this and invalidate during a commit.
  // TODO: most DocValues classes are threadsafe - expose which.

  RefCounted<SolrIndexSearcher> newestSearcher = ulog.uhandler.core.getRealtimeSearcher();
  try {
    SolrIndexSearcher searcher = newestSearcher.get();
    long lookup = searcher.lookupId(idBytes);
    if (lookup < 0) return null;

    ValueSource vs = versionField.getType().getValueSource(versionField, null);
    Map context = ValueSource.newContext(searcher);
    vs.createWeight(context, searcher);
    FunctionValues fv = vs.getValues(context, searcher.getTopReaderContext().leaves().get((int)(lookup>>32)));
    long ver = fv.longVal((int)lookup);
    return ver;

  } catch (IOException e) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error reading version from index", e);
  } finally {
    if (newestSearcher != null) {
      newestSearcher.decref();
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:VersionInfo.java

示例3: testTypes

import org.apache.lucene.queries.function.ValueSource; //导入方法依赖的package包/类
public void testTypes() throws Exception {
  Expression expr = JavascriptCompiler.compile("2*popularity");
  SimpleBindings bindings = new SimpleBindings();
  bindings.add(new SortField("popularity", SortField.Type.LONG));
  ValueSource vs = expr.getValueSource(bindings);
  
  assertEquals(1, reader.leaves().size());
  AtomicReaderContext leaf = reader.leaves().get(0);
  FunctionValues values = vs.getValues(new HashMap<String,Object>(), leaf);
  
  assertEquals(10, values.doubleVal(0), 0);
  assertEquals(10, values.floatVal(0), 0);
  assertEquals(10, values.longVal(0));
  assertEquals(10, values.intVal(0));
  assertEquals(10, values.shortVal(0));
  assertEquals(10, values.byteVal(0));
  assertEquals("10.0", values.strVal(0));
  assertEquals(new Double(10), values.objectVal(0));
  
  assertEquals(40, values.doubleVal(1), 0);
  assertEquals(40, values.floatVal(1), 0);
  assertEquals(40, values.longVal(1));
  assertEquals(40, values.intVal(1));
  assertEquals(40, values.shortVal(1));
  assertEquals(40, values.byteVal(1));
  assertEquals("40.0", values.strVal(1));
  assertEquals(new Double(40), values.objectVal(1));
  
  assertEquals(4, values.doubleVal(2), 0);
  assertEquals(4, values.floatVal(2), 0);
  assertEquals(4, values.longVal(2));
  assertEquals(4, values.intVal(2));
  assertEquals(4, values.shortVal(2));
  assertEquals(4, values.byteVal(2));
  assertEquals("4.0", values.strVal(2));
  assertEquals(new Double(4), values.objectVal(2));    
}
 
开发者ID:europeana,项目名称:search,代码行数:38,代码来源:TestExpressionValueSource.java

示例4: sumValues

import org.apache.lucene.queries.function.ValueSource; //导入方法依赖的package包/类
private final void sumValues(List<MatchingDocs> matchingDocs, boolean keepScores, ValueSource valueSource) throws IOException {
  final FakeScorer scorer = new FakeScorer();
  Map<String, Scorer> context = new HashMap<>();
  if (keepScores) {
    context.put("scorer", scorer);
  }
  IntsRef scratch = new IntsRef();
  for(MatchingDocs hits : matchingDocs) {
    OrdinalsReader.OrdinalsSegmentReader ords = ordinalsReader.getReader(hits.context);
    
    int scoresIdx = 0;
    float[] scores = hits.scores;

    FunctionValues functionValues = valueSource.getValues(context, hits.context);
    DocIdSetIterator docs = hits.bits.iterator();
    
    int doc;
    while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
      ords.get(doc, scratch);
      if (keepScores) {
        scorer.docID = doc;
        scorer.score = scores[scoresIdx++];
      }
      float value = (float) functionValues.doubleVal(doc);
      for(int i=0;i<scratch.length;i++) {
        values[scratch.ints[i]] += value;
      }
    }
  }

  rollup();
}
 
开发者ID:europeana,项目名称:search,代码行数:33,代码来源:TaxonomyFacetSumValueSource.java

示例5: getStringVal

import org.apache.lucene.queries.function.ValueSource; //导入方法依赖的package包/类
private String getStringVal(SolrQueryRequest sqr, String field, int doc) throws IOException {
  SchemaField sf = sqr.getSchema().getField(field);
  ValueSource vs = sf.getType().getValueSource(sf, null);
  Map context = ValueSource.newContext(sqr.getSearcher());
  vs.createWeight(context, sqr.getSearcher());
  IndexReaderContext topReaderContext = sqr.getSearcher().getTopReaderContext();
  List<AtomicReaderContext> leaves = topReaderContext.leaves();
  int idx = ReaderUtil.subIndex(doc, leaves);
  AtomicReaderContext leaf = leaves.get(idx);
  FunctionValues vals = vs.getValues(context, leaf);
  return vals.strVal(doc-leaf.docBase);
}
 
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:TestIndexSearcher.java

示例6: count

import org.apache.lucene.queries.function.ValueSource; //导入方法依赖的package包/类
private void count(ValueSource valueSource, List<MatchingDocs> matchingDocs) throws IOException {

    DoubleRange[] ranges = (DoubleRange[]) this.ranges;

    LongRange[] longRanges = new LongRange[ranges.length];
    for(int i=0;i<ranges.length;i++) {
      DoubleRange range = ranges[i];
      longRanges[i] =  new LongRange(range.label,
                                     NumericUtils.doubleToSortableLong(range.minIncl), true,
                                     NumericUtils.doubleToSortableLong(range.maxIncl), true);
    }

    LongRangeCounter counter = new LongRangeCounter(longRanges);

    int missingCount = 0;
    for (MatchingDocs hits : matchingDocs) {
      FunctionValues fv = valueSource.getValues(Collections.emptyMap(), hits.context);
      
      totCount += hits.totalHits;
      Bits bits;
      if (fastMatchFilter != null) {
        DocIdSet dis = fastMatchFilter.getDocIdSet(hits.context, null);
        if (dis == null) {
          // No documents match
          continue;
        }
        bits = dis.bits();
        if (bits == null) {
          throw new IllegalArgumentException("fastMatchFilter does not implement DocIdSet.bits");
        }
      } else {
        bits = null;
      }

      DocIdSetIterator docs = hits.bits.iterator();
      
      int doc;
      while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
        if (bits != null && bits.get(doc) == false) {
          doc++;
          continue;
        }
        // Skip missing docs:
        if (fv.exists(doc)) {
          counter.add(NumericUtils.doubleToSortableLong(fv.doubleVal(doc)));
        } else {
          missingCount++;
        }
      }
    }

    missingCount += counter.fillCounts(counts);
    totCount -= missingCount;
  }
 
开发者ID:europeana,项目名称:search,代码行数:55,代码来源:DoubleRangeFacetCounts.java

示例7: getFilter

import org.apache.lucene.queries.function.ValueSource; //导入方法依赖的package包/类
@Override
public Filter getFilter(final Filter fastMatchFilter, final ValueSource valueSource) {
  return new Filter() {

    @Override
    public String toString() {
      return "Filter(" + LongRange.this.toString() + ")";
    }

    @Override
    public DocIdSet getDocIdSet(AtomicReaderContext context, final Bits acceptDocs) throws IOException {

      // TODO: this is just like ValueSourceScorer,
      // ValueSourceFilter (spatial),
      // ValueSourceRangeFilter (solr); also,
      // https://issues.apache.org/jira/browse/LUCENE-4251

      final FunctionValues values = valueSource.getValues(Collections.emptyMap(), context);

      final int maxDoc = context.reader().maxDoc();

      final Bits fastMatchBits;
      if (fastMatchFilter != null) {
        DocIdSet dis = fastMatchFilter.getDocIdSet(context, null);
        if (dis == null) {
          // No documents match
          return null;
        }
        fastMatchBits = dis.bits();
        if (fastMatchBits == null) {
          throw new IllegalArgumentException("fastMatchFilter does not implement DocIdSet.bits");
        }
      } else {
        fastMatchBits = null;
      }

      return new DocIdSet() {

        @Override
        public Bits bits() {
          return new Bits() {
            @Override
            public boolean get(int docID) {
              if (acceptDocs != null && acceptDocs.get(docID) == false) {
                return false;
              }
              if (fastMatchBits != null && fastMatchBits.get(docID) == false) {
                return false;
              }
              return accept(values.longVal(docID));
            }

            @Override
            public int length() {
              return maxDoc;
            }
          };
        }

        @Override
        public DocIdSetIterator iterator() {
          throw new UnsupportedOperationException("this filter can only be accessed via bits()");
        }
      };
    }
  };
}
 
开发者ID:europeana,项目名称:search,代码行数:68,代码来源:LongRange.java

示例8: getFilter

import org.apache.lucene.queries.function.ValueSource; //导入方法依赖的package包/类
@Override
public Filter getFilter(final Filter fastMatchFilter, final ValueSource valueSource) {
  return new Filter() {

    @Override
    public String toString() {
      return "Filter(" + DoubleRange.this.toString() + ")";
    }

    @Override
    public DocIdSet getDocIdSet(AtomicReaderContext context, final Bits acceptDocs) throws IOException {

      // TODO: this is just like ValueSourceScorer,
      // ValueSourceFilter (spatial),
      // ValueSourceRangeFilter (solr); also,
      // https://issues.apache.org/jira/browse/LUCENE-4251

      final FunctionValues values = valueSource.getValues(Collections.emptyMap(), context);

      final int maxDoc = context.reader().maxDoc();

      final Bits fastMatchBits;
      if (fastMatchFilter != null) {
        DocIdSet dis = fastMatchFilter.getDocIdSet(context, null);
        if (dis == null) {
          // No documents match
          return null;
        }
        fastMatchBits = dis.bits();
        if (fastMatchBits == null) {
          throw new IllegalArgumentException("fastMatchFilter does not implement DocIdSet.bits");
        }
      } else {
        fastMatchBits = null;
      }

      return new DocIdSet() {

        @Override
        public Bits bits() {
          return new Bits() {
            @Override
            public boolean get(int docID) {
              if (acceptDocs != null && acceptDocs.get(docID) == false) {
                return false;
              }
              if (fastMatchBits != null && fastMatchBits.get(docID) == false) {
                return false;
              }
              return accept(values.doubleVal(docID));
            }

            @Override
            public int length() {
              return maxDoc;
            }
          };
        }

        @Override
        public DocIdSetIterator iterator() {
          throw new UnsupportedOperationException("this filter can only be accessed via bits()");
        }
      };
    }
  };
}
 
开发者ID:europeana,项目名称:search,代码行数:68,代码来源:DoubleRange.java

示例9: count

import org.apache.lucene.queries.function.ValueSource; //导入方法依赖的package包/类
private void count(ValueSource valueSource, List<MatchingDocs> matchingDocs) throws IOException {

    LongRange[] ranges = (LongRange[]) this.ranges;

    LongRangeCounter counter = new LongRangeCounter(ranges);

    int missingCount = 0;
    for (MatchingDocs hits : matchingDocs) {
      FunctionValues fv = valueSource.getValues(Collections.emptyMap(), hits.context);
      
      totCount += hits.totalHits;
      Bits bits;
      if (fastMatchFilter != null) {
        DocIdSet dis = fastMatchFilter.getDocIdSet(hits.context, null);
        if (dis == null) {
          // No documents match
          continue;
        }
        bits = dis.bits();
        if (bits == null) {
          throw new IllegalArgumentException("fastMatchFilter does not implement DocIdSet.bits");
        }
      } else {
        bits = null;
      }

      DocIdSetIterator docs = hits.bits.iterator();      
      int doc;
      while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
        if (bits != null && bits.get(doc) == false) {
          doc++;
          continue;
        }
        // Skip missing docs:
        if (fv.exists(doc)) {
          counter.add(fv.longVal(doc));
        } else {
          missingCount++;
        }
      }
    }
    
    int x = counter.fillCounts(counts);

    missingCount += x;

    //System.out.println("totCount " + totCount + " missingCount " + counter.missingCount);
    totCount -= missingCount;
  }
 
开发者ID:europeana,项目名称:search,代码行数:50,代码来源:LongRangeFacetCounts.java


注:本文中的org.apache.lucene.queries.function.ValueSource.getValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。