Package org.apache.lucene.index

Examples of org.apache.lucene.index.DirectoryReader.document()


   
    Directory dir = newDirectory();
    RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
    iw.addDocument(doc);
    DirectoryReader ir = iw.getReader();
    Document sdoc = ir.document(0);
    assertEquals("5", sdoc.get("int"));
    assertNull(sdoc.get("somethingElse"));
    assertArrayEquals(new String[] { "5", "4" }, sdoc.getValues("int"));
    ir.close();
    iw.close();
View Full Code Here


    for (int i = 0; i < totalShardCount; i++) {
      HdfsDirectory directory = new HdfsDirectory(configuration, new Path(path, BlurUtil.getShardName(i)));
      DirectoryReader reader = DirectoryReader.open(directory);
      int numDocs = reader.numDocs();
      for (int d = 0; d < numDocs; d++) {
        Document document = reader.document(d);
        IndexableField field = document.getField("id");
        Integer id = (Integer) field.numericValue();
        int partition = partitioner.getPartition(new IntWritable(id), null, totalShardCount);
        assertEquals(i, partition);
      }
View Full Code Here

    assertEquals(1, reader2.maxDoc());
    assertEquals(1, reader1.numDocs());
    assertEquals(1, reader2.numDocs());

    Document document1 = reader1.document(0);
    Document document2 = reader2.document(0);

    assertEquals(document1.get("id"), document2.get("id"));
  }

  private Document getDoc() {
View Full Code Here

    for (int i = 0; i < 2; i++) {

      long t1 = System.nanoTime();
      Document document1 = reader1.document(0);
      long t2 = System.nanoTime();
      Document document2 = reader2.document(1);
      long t3 = System.nanoTime();

      System.out.println((t3 - t2) / 1000000.0);
      System.out.println((t2 - t1) / 1000000.0);
View Full Code Here

    writer2.close();

    DirectoryReader reader = DirectoryReader.open(directory);
    int maxDoc = reader.maxDoc();
    assertEquals(1, maxDoc);
    Document document = reader.document(0);
    assertEquals("2", document.get("id"));
    reader.close();
  }

  private void addDoc(IndexWriter writer, Document doc) throws IOException {
View Full Code Here

        Document document1 = reader1.document(d);
        hash1 += document1.hashCode();
      }
      long t2 = System.nanoTime();
      for (int d = 0; d < 1000; d++) {
        Document document2 = reader2.document(d + 1000);
        hash2 += document2.hashCode();
      }
      long t3 = System.nanoTime();

      System.out.println((t3 - t2) / 1000000.0);
View Full Code Here

    DirectoryReader reader = DirectoryReader.open(_cacheDirectory);
    System.out.println("done opening");
    assertEquals(docs, reader.numDocs());

    Document document = reader.document(0);
    System.out.println("done fetching");
    System.out.println(document);

    IndexSearcher searcher = new IndexSearcher(reader);
    TopDocs topDocs = searcher.search(new TermQuery(new Term("test", "test")), 10);
View Full Code Here

    for (int i = 0; i < totalShardCount; i++) {
      HdfsDirectory directory = new HdfsDirectory(configuration, new Path(path, BlurUtil.getShardName(i)));
      DirectoryReader reader = DirectoryReader.open(directory);
      int numDocs = reader.numDocs();
      for (int d = 0; d < numDocs; d++) {
        Document document = reader.document(d);
        IndexableField field = document.getField("id");
        Integer id = (Integer) field.numericValue();
        int partition = partitioner.getPartition(new IntWritable(id), null, totalShardCount);
        assertEquals(i, partition);
      }
View Full Code Here

    final DirectoryReader ir = DirectoryReader.open(dir);
    assertTrue(ir.numDocs() > 0);
    int numDocs = 0;
    for (int i = 0; i < ir.maxDoc(); ++i) {
      final Document doc = ir.document(i);
      if (doc == null) {
        continue;
      }
      ++ numDocs;
      final int docId = doc.getField("id").numericValue().intValue();
View Full Code Here

    final DirectoryReader reader = DirectoryReader.open(dir);
    final int docID = random().nextInt(100);
    for (Field fld : fields) {
      String fldName = fld.name();
      final Document sDoc = reader.document(docID, Collections.singleton(fldName));
      final IndexableField sField = sDoc.getField(fldName);
      if (Field.class.equals(fld.getClass())) {
        assertEquals(fld.binaryValue(), sField.binaryValue());
        assertEquals(fld.stringValue(), sField.stringValue());
      } else {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.