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


Java NumericDocValuesField.setLongValue方法代码示例

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


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

示例1: testDateCompression

import org.apache.lucene.document.NumericDocValuesField; //导入方法依赖的package包/类
public void testDateCompression() throws IOException {
  final Directory dir = new RAMDirectory();
  final IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
  final IndexWriter iwriter = new IndexWriter(dir, iwc);

  final long base = 13; // prime
  final long day = 1000L * 60 * 60 * 24;

  final Document doc = new Document();
  final NumericDocValuesField dvf = new NumericDocValuesField("dv", 0);
  doc.add(dvf);
  for (int i = 0; i < 300; ++i) {
    dvf.setLongValue(base + random().nextInt(1000) * day);
    iwriter.addDocument(doc);
  }
  iwriter.forceMerge(1);
  final long size1 = dirSize(dir);
  for (int i = 0; i < 50; ++i) {
    dvf.setLongValue(base + random().nextInt(1000) * day);
    iwriter.addDocument(doc);
  }
  iwriter.forceMerge(1);
  final long size2 = dirSize(dir);
  // make sure the new longs costed less than if they had only been packed
  assertTrue(size2 < size1 + (PackedInts.bitsRequired(day) * 50) / 8);
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:BaseCompressingDocValuesFormatTestCase.java

示例2: testSingleBigValueCompression

import org.apache.lucene.document.NumericDocValuesField; //导入方法依赖的package包/类
public void testSingleBigValueCompression() throws IOException {
  final Directory dir = new RAMDirectory();
  final IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
  final IndexWriter iwriter = new IndexWriter(dir, iwc);

  final Document doc = new Document();
  final NumericDocValuesField dvf = new NumericDocValuesField("dv", 0);
  doc.add(dvf);
  for (int i = 0; i < 20000; ++i) {
    dvf.setLongValue(i & 1023);
    iwriter.addDocument(doc);
  }
  iwriter.forceMerge(1);
  final long size1 = dirSize(dir);
  dvf.setLongValue(Long.MAX_VALUE);
  iwriter.addDocument(doc);
  iwriter.forceMerge(1);
  final long size2 = dirSize(dir);
  // make sure the new value did not grow the bpv for every other value
  assertTrue(size2 < size1 + (20000 * (63 - 10)) / 8);
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:BaseCompressingDocValuesFormatTestCase.java

示例3: testBasicLong

import org.apache.lucene.document.NumericDocValuesField; //导入方法依赖的package包/类
public void testBasicLong() throws Exception {
  Directory d = newDirectory();
  RandomIndexWriter w = new RandomIndexWriter(random(), d);
  Document doc = new Document();
  NumericDocValuesField field = new NumericDocValuesField("field", 0L);
  doc.add(field);
  for(long l=0;l<100;l++) {
    field.setLongValue(l);
    w.addDocument(doc);
  }

  // Also add Long.MAX_VALUE
  field.setLongValue(Long.MAX_VALUE);
  w.addDocument(doc);

  IndexReader r = w.getReader();
  w.close();

  FacetsCollector fc = new FacetsCollector();
  IndexSearcher s = newSearcher(r);
  s.search(new MatchAllDocsQuery(), fc);

  Facets facets = new LongRangeFacetCounts("field", fc,
      new LongRange("less than 10", 0L, true, 10L, false),
      new LongRange("less than or equal to 10", 0L, true, 10L, true),
      new LongRange("over 90", 90L, false, 100L, false),
      new LongRange("90 or above", 90L, true, 100L, false),
      new LongRange("over 1000", 1000L, false, Long.MAX_VALUE, true));

  FacetResult result = facets.getTopChildren(10, "field");
  assertEquals("dim=field path=[] value=22 childCount=5\n  less than 10 (10)\n  less than or equal to 10 (11)\n  over 90 (9)\n  90 or above (10)\n  over 1000 (1)\n",
               result.toString());
  
  r.close();
  d.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:37,代码来源:TestRangeFacetCounts.java

示例4: testLongMinMax

import org.apache.lucene.document.NumericDocValuesField; //导入方法依赖的package包/类
public void testLongMinMax() throws Exception {

    Directory d = newDirectory();
    RandomIndexWriter w = new RandomIndexWriter(random(), d);
    Document doc = new Document();
    NumericDocValuesField field = new NumericDocValuesField("field", 0L);
    doc.add(field);
    field.setLongValue(Long.MIN_VALUE);
    w.addDocument(doc);
    field.setLongValue(0);
    w.addDocument(doc);
    field.setLongValue(Long.MAX_VALUE);
    w.addDocument(doc);

    IndexReader r = w.getReader();
    w.close();

    FacetsCollector fc = new FacetsCollector();
    IndexSearcher s = newSearcher(r);
    s.search(new MatchAllDocsQuery(), fc);

    Facets facets = new LongRangeFacetCounts("field", fc,
        new LongRange("min", Long.MIN_VALUE, true, Long.MIN_VALUE, true),
        new LongRange("max", Long.MAX_VALUE, true, Long.MAX_VALUE, true),
        new LongRange("all0", Long.MIN_VALUE, true, Long.MAX_VALUE, true),
        new LongRange("all1", Long.MIN_VALUE, false, Long.MAX_VALUE, true),
        new LongRange("all2", Long.MIN_VALUE, true, Long.MAX_VALUE, false),
        new LongRange("all3", Long.MIN_VALUE, false, Long.MAX_VALUE, false));

    FacetResult result = facets.getTopChildren(10, "field");
    assertEquals("dim=field path=[] value=3 childCount=6\n  min (1)\n  max (1)\n  all0 (3)\n  all1 (2)\n  all2 (2)\n  all3 (1)\n",
                 result.toString());
    
    r.close();
    d.close();
  }
 
开发者ID:europeana,项目名称:search,代码行数:37,代码来源:TestRangeFacetCounts.java

示例5: testOverlappedEndStart

import org.apache.lucene.document.NumericDocValuesField; //导入方法依赖的package包/类
public void testOverlappedEndStart() throws Exception {
  Directory d = newDirectory();
  RandomIndexWriter w = new RandomIndexWriter(random(), d);
  Document doc = new Document();
  NumericDocValuesField field = new NumericDocValuesField("field", 0L);
  doc.add(field);
  for(long l=0;l<100;l++) {
    field.setLongValue(l);
    w.addDocument(doc);
  }
  field.setLongValue(Long.MAX_VALUE);
  w.addDocument(doc);

  IndexReader r = w.getReader();
  w.close();

  FacetsCollector fc = new FacetsCollector();
  IndexSearcher s = newSearcher(r);
  s.search(new MatchAllDocsQuery(), fc);

  Facets facets = new LongRangeFacetCounts("field", fc,
      new LongRange("0-10", 0L, true, 10L, true),
      new LongRange("10-20", 10L, true, 20L, true),
      new LongRange("20-30", 20L, true, 30L, true),
      new LongRange("30-40", 30L, true, 40L, true));
  
  FacetResult result = facets.getTopChildren(10, "field");
  assertEquals("dim=field path=[] value=41 childCount=4\n  0-10 (11)\n  10-20 (11)\n  20-30 (11)\n  30-40 (11)\n",
               result.toString());
  
  r.close();
  d.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:34,代码来源:TestRangeFacetCounts.java

示例6: testMissingValues

import org.apache.lucene.document.NumericDocValuesField; //导入方法依赖的package包/类
public void testMissingValues() throws Exception {
  assumeTrue("codec does not support docsWithField", defaultCodecSupportsDocsWithField());
  Directory d = newDirectory();
  RandomIndexWriter w = new RandomIndexWriter(random(), d);
  Document doc = new Document();
  NumericDocValuesField field = new NumericDocValuesField("field", 0L);
  doc.add(field);
  for(long l=0;l<100;l++) {
    if (l % 5 == 0) {
      // Every 5th doc is missing the value:
      w.addDocument(new Document());
      continue;
    }
    field.setLongValue(l);
    w.addDocument(doc);
  }

  IndexReader r = w.getReader();

  FacetsCollector fc = new FacetsCollector();

  IndexSearcher s = newSearcher(r);
  s.search(new MatchAllDocsQuery(), fc);
  Facets facets = new LongRangeFacetCounts("field", fc,
      new LongRange("less than 10", 0L, true, 10L, false),
      new LongRange("less than or equal to 10", 0L, true, 10L, true),
      new LongRange("over 90", 90L, false, 100L, false),
      new LongRange("90 or above", 90L, true, 100L, false),
      new LongRange("over 1000", 1000L, false, Long.MAX_VALUE, false));
  
  assertEquals("dim=field path=[] value=16 childCount=5\n  less than 10 (8)\n  less than or equal to 10 (8)\n  over 90 (8)\n  90 or above (8)\n  over 1000 (0)\n",
               facets.getTopChildren(10, "field").toString());

  IOUtils.close(w, r, d);
}
 
开发者ID:europeana,项目名称:search,代码行数:36,代码来源:TestRangeFacetCounts.java

示例7: testUniqueValuesCompression

import org.apache.lucene.document.NumericDocValuesField; //导入方法依赖的package包/类
public void testUniqueValuesCompression() throws IOException {
  final Directory dir = new RAMDirectory();
  final IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
  final IndexWriter iwriter = new IndexWriter(dir, iwc);

  final int uniqueValueCount = TestUtil.nextInt(random(), 1, 256);
  final List<Long> values = new ArrayList<>();

  final Document doc = new Document();
  final NumericDocValuesField dvf = new NumericDocValuesField("dv", 0);
  doc.add(dvf);
  for (int i = 0; i < 300; ++i) {
    final long value;
    if (values.size() < uniqueValueCount) {
      value = random().nextLong();
      values.add(value);
    } else {
      value = RandomPicks.randomFrom(random(), values);
    }
    dvf.setLongValue(value);
    iwriter.addDocument(doc);
  }
  iwriter.forceMerge(1);
  final long size1 = dirSize(dir);
  for (int i = 0; i < 20; ++i) {
    dvf.setLongValue(RandomPicks.randomFrom(random(), values));
    iwriter.addDocument(doc);
  }
  iwriter.forceMerge(1);
  final long size2 = dirSize(dir);
  // make sure the new longs did not cost 8 bytes each
  assertTrue(size2 < size1 + 8 * 20);
}
 
开发者ID:europeana,项目名称:search,代码行数:34,代码来源:BaseCompressingDocValuesFormatTestCase.java

示例8: testNumerics

import org.apache.lucene.document.NumericDocValuesField; //导入方法依赖的package包/类
public void testNumerics() throws Exception {
  BaseDirectoryWrapper dir = newFSDirectory(createTempDir("2BNumerics"));
  if (dir instanceof MockDirectoryWrapper) {
    ((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
  }
  
  IndexWriter w = new IndexWriter(dir,
      new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()))
      .setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH)
      .setRAMBufferSizeMB(256.0)
      .setMergeScheduler(new ConcurrentMergeScheduler())
      .setMergePolicy(newLogMergePolicy(false, 10))
      .setOpenMode(IndexWriterConfig.OpenMode.CREATE));

  Document doc = new Document();
  NumericDocValuesField dvField = new NumericDocValuesField("dv", 0);
  doc.add(dvField);
  
  for (int i = 0; i < Integer.MAX_VALUE; i++) {
    dvField.setLongValue(i);
    w.addDocument(doc);
    if (i % 100000 == 0) {
      System.out.println("indexed: " + i);
      System.out.flush();
    }
  }
  
  w.forceMerge(1);
  w.close();
  
  System.out.println("verifying...");
  System.out.flush();
  
  DirectoryReader r = DirectoryReader.open(dir);
  long expectedValue = 0;
  for (AtomicReaderContext context : r.leaves()) {
    AtomicReader reader = context.reader();
    NumericDocValues dv = reader.getNumericDocValues("dv");
    for (int i = 0; i < reader.maxDoc(); i++) {
      assertEquals(expectedValue, dv.get(i));
      expectedValue++;
    }
  }
  
  r.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:48,代码来源:Test2BNumericDocValues.java


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