Java Code Examples for org.apache.lucene.search.DoubleValuesSource#fromLongField()

The following examples show how to use org.apache.lucene.search.DoubleValuesSource#fromLongField() . These examples are extracted from open source projects. 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
public void testTruncateNegativeScores() throws IOException {
  Directory dir = newDirectory();
  IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
  Document doc = new Document();
  doc.add(new NumericDocValuesField("foo", -2));
  w.addDocument(doc);
  IndexReader reader = DirectoryReader.open(w);
  w.close();
  IndexSearcher searcher = newSearcher(reader);
  Query q = new FunctionScoreQuery(new MatchAllDocsQuery(), DoubleValuesSource.fromLongField("foo"));
  QueryUtils.check(random(), q, searcher);
  Explanation expl = searcher.explain(q, 0);
  assertEquals(0, expl.getValue().doubleValue(), 0f);
  assertTrue(expl.toString(), expl.getDetails()[0].getDescription().contains("truncated score"));
  reader.close();
  dir.close();
}
 
Example 2
Source Project: lucene-solr   File: TestExpressionSorts.java    License: Apache License 2.0 6 votes vote down vote up
private DoubleValuesSource fromSortField(SortField field) {
  switch(field.getType()) {
    case INT:
      return DoubleValuesSource.fromIntField(field.getField());
    case LONG:
      return DoubleValuesSource.fromLongField(field.getField());
    case FLOAT:
      return DoubleValuesSource.fromFloatField(field.getField());
    case DOUBLE:
      return DoubleValuesSource.fromDoubleField(field.getField());
    case SCORE:
      return DoubleValuesSource.SCORES;
    default:
      throw new UnsupportedOperationException();
  }
}
 
Example 3
public void testNoScore() throws Exception {
  Directory indexDir = newDirectory();
  Directory taxoDir = newDirectory();

  DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
  IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(new MockAnalyzer(random())));
  FacetsConfig config = new FacetsConfig();
  for (int i = 0; i < 4; i++) {
    Document doc = new Document();
    doc.add(new NumericDocValuesField("price", (i+1)));
    doc.add(new FacetField("a", Integer.toString(i % 2)));
    iw.addDocument(config.build(taxoWriter, doc));
  }
  
  DirectoryReader r = DirectoryReader.open(iw);
  DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);

  FacetsCollector sfc = new FacetsCollector();
  newSearcher(r).search(new MatchAllDocsQuery(), sfc);
  Facets facets = new TaxonomyFacetSumValueSource(taxoReader, config, sfc, DoubleValuesSource.fromLongField("price"));
  assertEquals("dim=a path=[] value=10.0 childCount=2\n  1 (6.0)\n  0 (4.0)\n", facets.getTopChildren(10, "a").toString());

  iw.close();
  IOUtils.close(taxoWriter, taxoReader, taxoDir, r, indexDir);
}
 
Example 4
private DoubleValuesSource fromSortField(SortField field) {
  switch(field.getType()) {
    case INT:
      return DoubleValuesSource.fromIntField(field.getField());
    case LONG:
      return DoubleValuesSource.fromLongField(field.getField());
    case FLOAT:
      return DoubleValuesSource.fromFloatField(field.getField());
    case DOUBLE:
      return DoubleValuesSource.fromDoubleField(field.getField());
    case SCORE:
      return DoubleValuesSource.SCORES;
    default:
      throw new UnsupportedOperationException();
  }
}
 
Example 5
private static DoubleValuesSource fromSortField(SortField field) {
  switch(field.getType()) {
    case INT:
      return DoubleValuesSource.fromIntField(field.getField());
    case LONG:
      return DoubleValuesSource.fromLongField(field.getField());
    case FLOAT:
      return DoubleValuesSource.fromFloatField(field.getField());
    case DOUBLE:
      return DoubleValuesSource.fromDoubleField(field.getField());
    case SCORE:
      return DoubleValuesSource.SCORES;
    default:
      throw new UnsupportedOperationException();
  }
}
 
Example 6
public void testRollupValues() throws Exception {
  Directory indexDir = newDirectory();
  Directory taxoDir = newDirectory();

  DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
  IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(new MockAnalyzer(random())));
  FacetsConfig config = new FacetsConfig();
  config.setHierarchical("a", true);
  //config.setRequireDimCount("a", true);
  
  for (int i = 0; i < 4; i++) {
    Document doc = new Document();
    doc.add(new NumericDocValuesField("price", (i+1)));
    doc.add(new FacetField("a", Integer.toString(i % 2), "1"));
    iw.addDocument(config.build(taxoWriter, doc));
  }
  
  DirectoryReader r = DirectoryReader.open(iw);
  DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);

  FacetsCollector sfc = new FacetsCollector();
  newSearcher(r).search(new MatchAllDocsQuery(), sfc);
  Facets facets = new TaxonomyFacetSumValueSource(taxoReader, config, sfc, DoubleValuesSource.fromLongField("price"));
  
  assertEquals("dim=a path=[] value=10.0 childCount=2\n  1 (6.0)\n  0 (4.0)\n", facets.getTopChildren(10, "a").toString());

  iw.close();
  IOUtils.close(taxoWriter, taxoReader, taxoDir, r, indexDir);
}