Java Code Examples for org.apache.lucene.document.FieldType#setDocValuesType()

The following examples show how to use org.apache.lucene.document.FieldType#setDocValuesType() . 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: TestMemoryIndex.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testIndexingPointsAndDocValues() throws Exception {
  FieldType type = new FieldType();
  type.setDimensions(1, 4);
  type.setDocValuesType(DocValuesType.BINARY);
  type.freeze();
  Document doc = new Document();
  byte[] packedPoint = "term".getBytes(StandardCharsets.UTF_8);
  doc.add(new BinaryPoint("field", packedPoint, type));
  MemoryIndex mi = MemoryIndex.fromDocument(doc, analyzer);
  LeafReader leafReader = mi.createSearcher().getIndexReader().leaves().get(0).reader();

  assertEquals(1, leafReader.getPointValues("field").size());
  assertArrayEquals(packedPoint, leafReader.getPointValues("field").getMinPackedValue());
  assertArrayEquals(packedPoint, leafReader.getPointValues("field").getMaxPackedValue());

  BinaryDocValues dvs = leafReader.getBinaryDocValues("field");
  assertEquals(0, dvs.nextDoc());
  assertEquals("term", dvs.binaryValue().utf8ToString());
}
 
Example 2
Source File: TestMemoryIndex.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testToStringDebug() {
  MemoryIndex mi = new MemoryIndex(true, true);
  Analyzer analyzer = new MockPayloadAnalyzer();

  mi.addField("analyzedField", "aa bb aa", analyzer);

  FieldType type = new FieldType();
  type.setDimensions(1, 4);
  type.setDocValuesType(DocValuesType.BINARY);
  type.freeze();
  mi.addField(new BinaryPoint("pointAndDvField", "term".getBytes(StandardCharsets.UTF_8), type), analyzer);

  assertEquals("analyzedField:\n" +
      "\t'[61 61]':2: [(0, 0, 2, [70 6f 73 3a 20 30]), (1, 6, 8, [70 6f 73 3a 20 32])]\n" +
      "\t'[62 62]':1: [(1, 3, 5, [70 6f 73 3a 20 31])]\n" +
      "\tterms=2, positions=3\n" +
      "pointAndDvField:\n" +
      "\tterms=0, positions=0\n" +
      "\n" +
      "fields=2, terms=2, positions=3", mi.toStringDebug());
}
 
Example 3
Source File: TestDocValuesIndexing.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testExcIndexingDocBeforeDocValues() throws Exception {
  Directory dir = newDirectory();
  IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
  IndexWriter w = new IndexWriter(dir, iwc);
  Document doc = new Document();
  FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
  ft.setDocValuesType(DocValuesType.SORTED);
  ft.freeze();
  Field field = new Field("test", "value", ft);
  field.setTokenStream(new TokenStream() {
      @Override
      public boolean incrementToken() {
        throw new RuntimeException("no");
      }
    });
  doc.add(field);
  expectThrows(RuntimeException.class, () -> {
    w.addDocument(doc);
  });

  w.addDocument(new Document());
  w.close();
  dir.close();
}
 
Example 4
Source File: TestBBoxStrategy.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testOperations() throws IOException {
  //setup
  if (random().nextInt(4) > 0) {//75% of the time choose geo (more interesting to test)
    this.ctx = SpatialContext.GEO;
  } else {
    SpatialContextFactory factory = new SpatialContextFactory();
    factory.geo = false;
    factory.worldBounds = new RectangleImpl(-300, 300, -100, 100, null);
    this.ctx = factory.newSpatialContext();
  }
  this.strategy = BBoxStrategy.newInstance(ctx, "bbox");
  //test we can disable docValues for predicate tests
  if (random().nextBoolean()) {
    FieldType fieldType = new FieldType(((BBoxStrategy)strategy).getFieldType());
    fieldType.setDocValuesType(DocValuesType.NONE);
    strategy = new BBoxStrategy(ctx, strategy.getFieldName(), fieldType);
  }
  for (SpatialOperation operation : SpatialOperation.values()) {
    if (operation == SpatialOperation.Overlaps)
      continue;//unsupported
    testOperationRandomShapes(operation);

    deleteAll();
    commit();
  }
}