Package org.apache.lucene.util

Examples of org.apache.lucene.util.BytesRef


    TermsEnum termsEnum = vector.iterator(null);
    assertNotNull(termsEnum);
    assertEquals(testTerms.length, vector.size());
    DocsAndPositionsEnum dpEnum = null;
    for (int i = 0; i < testTerms.length; i++) {
      final BytesRef text = termsEnum.next();
      assertNotNull(text);
      String term = text.utf8ToString();
      assertEquals(testTerms[i], term);

      dpEnum = termsEnum.docsAndPositions(null, dpEnum);
      assertNotNull(dpEnum);
      assertTrue(dpEnum.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
View Full Code Here


    Field f = newField("foo", "bar", ft);
    doc.add(f);
    iw.addDocument(doc);
    IndexReader ir = iw.getReader();
    iw.close();
    assertEquals(-1, ir.totalTermFreq(new Term("foo", new BytesRef("bar"))));
    assertEquals(-1, ir.getSumTotalTermFreq("foo"));
    ir.close();
    dir.close();
  }
View Full Code Here

      assertEquals(1, reader.numDocs());
      Term t = new Term("field", "a");
      assertEquals(1, reader.docFreq(t));
      DocsEnum td = _TestUtil.docs(random(), reader,
                                   "field",
                                   new BytesRef("a"),
                                   MultiFields.getLiveDocs(reader),
                                   null,
                                   DocsEnum.FLAG_FREQS);
      td.nextDoc();
      assertEquals(128*1024, td.freq());
View Full Code Here

    writer.addDocument(doc)
    writer.close();
    DirectoryReader reader = DirectoryReader.open(dir);
    AtomicReader subreader = getOnlySegmentReader(reader);
    TermsEnum te = subreader.fields().terms("").iterator(null);
    assertEquals(new BytesRef("a"), te.next());
    assertEquals(new BytesRef("b"), te.next());
    assertEquals(new BytesRef("c"), te.next());
    assertNull(te.next());
    reader.close();
    dir.close();
  }
View Full Code Here

    writer.addDocument(doc)
    writer.close();
    DirectoryReader reader = DirectoryReader.open(dir);
    AtomicReader subreader = getOnlySegmentReader(reader);
    TermsEnum te = subreader.fields().terms("").iterator(null);
    assertEquals(new BytesRef(""), te.next());
    assertEquals(new BytesRef("a"), te.next());
    assertEquals(new BytesRef("b"), te.next());
    assertEquals(new BytesRef("c"), te.next());
    assertNull(te.next());
    reader.close();
    dir.close();
  }
View Full Code Here

    assertEquals("value", ir.document(1).get("string"));
    assertEquals("value", ir.document(2).get("string"));


    // test that the terms were indexed.
    assertTrue(_TestUtil.docs(random(), ir, "binary", new BytesRef("doc1field1"), null, null, DocsEnum.FLAG_NONE).nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
    assertTrue(_TestUtil.docs(random(), ir, "binary", new BytesRef("doc2field1"), null, null, DocsEnum.FLAG_NONE).nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
    assertTrue(_TestUtil.docs(random(), ir, "binary", new BytesRef("doc3field1"), null, null, DocsEnum.FLAG_NONE).nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
    assertTrue(_TestUtil.docs(random(), ir, "string", new BytesRef("doc1field2"), null, null, DocsEnum.FLAG_NONE).nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
    assertTrue(_TestUtil.docs(random(), ir, "string", new BytesRef("doc2field2"), null, null, DocsEnum.FLAG_NONE).nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
    assertTrue(_TestUtil.docs(random(), ir, "string", new BytesRef("doc3field2"), null, null, DocsEnum.FLAG_NONE).nextDoc() != DocIdSetIterator.NO_MORE_DOCS);

    ir.close();
    dir.close();

  }
View Full Code Here

    char[] chars = new char[DocumentsWriterPerThread.MAX_TERM_LENGTH_UTF8];
    Arrays.fill(chars, 'x');
    Document doc = new Document();
    final String bigTerm = new String(chars);
    final BytesRef bigTermBytesRef = new BytesRef(bigTerm);

    // This contents produces a too-long term:
    String contents = "abc xyz x" + bigTerm + " another term";
    doc.add(new TextField("content", contents, Field.Store.NO));
    w.addDocument(doc);

    // Make sure we can add another normal document
    doc = new Document();
    doc.add(new TextField("content", "abc bbb ccc", Field.Store.NO));
    w.addDocument(doc);

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

    // Make sure all terms < max size were indexed
    assertEquals(2, reader.docFreq(new Term("content", "abc")));
    assertEquals(1, reader.docFreq(new Term("content", "bbb")));
    assertEquals(1, reader.docFreq(new Term("content", "term")));
    assertEquals(1, reader.docFreq(new Term("content", "another")));

    // Make sure position is still incremented when
    // massive term is skipped:
    DocsAndPositionsEnum tps = MultiFields.getTermPositionsEnum(reader, null, "content", new BytesRef("another"));
    assertEquals(0, tps.nextDoc());
    assertEquals(1, tps.freq());
    assertEquals(3, tps.nextPosition());

    // Make sure the doc that has the massive term is in
    // the index:
    assertEquals("document with wicked long term should is not in the index!", 2, reader.numDocs());

    reader.close();
    dir.close();
    dir = newDirectory();

    // Make sure we can add a document with exactly the
    // maximum length term, and search on that term:
    doc = new Document();
    FieldType customType = new FieldType(TextField.TYPE_NOT_STORED);
    customType.setTokenized(false);
    Field contentField = new Field("content", "", customType);
    doc.add(contentField);

    w = new RandomIndexWriter(random(), dir);

    contentField.setStringValue("other");
    w.addDocument(doc);

    contentField.setStringValue("term");
    w.addDocument(doc);

    contentField.setStringValue(bigTerm);
    w.addDocument(doc);

    contentField.setStringValue("zzz");
    w.addDocument(doc);

    reader = w.getReader();
    w.close();
    assertEquals(1, reader.docFreq(new Term("content", bigTerm)));

    SortedDocValues dti = FieldCache.DEFAULT.getTermsIndex(SlowCompositeReaderWrapper.wrap(reader), "content", random().nextFloat() * PackedInts.FAST);
    assertEquals(4, dti.getValueCount());
    BytesRef br = new BytesRef();
    dti.lookupOrd(2, br);
    assertEquals(bigTermBytesRef, br);
    reader.close();
    dir.close();
  }
View Full Code Here

      IndexWriter w = new IndexWriter(adder, conf);
      Document doc = new Document();
      doc.add(newStringField(random, "id", "500", Field.Store.NO));
      doc.add(newField(random, "field", "some prepackaged text contents", storedTextType));
      if (defaultCodecSupportsDocValues()) {
        doc.add(new BinaryDocValuesField("binarydv", new BytesRef("500")));
        doc.add(new NumericDocValuesField("numericdv", 500));
        doc.add(new SortedDocValuesField("sorteddv", new BytesRef("500")));
      }
      if (defaultCodecSupportsSortedSet()) {
        doc.add(new SortedSetDocValuesField("sortedsetdv", new BytesRef("one")));
        doc.add(new SortedSetDocValuesField("sortedsetdv", new BytesRef("two")));
      }
      w.addDocument(doc);
      doc = new Document();
      doc.add(newStringField(random, "id", "501", Field.Store.NO));
      doc.add(newField(random, "field", "some more contents", storedTextType));
      if (defaultCodecSupportsDocValues()) {
        doc.add(new BinaryDocValuesField("binarydv", new BytesRef("501")));
        doc.add(new NumericDocValuesField("numericdv", 501));
        doc.add(new SortedDocValuesField("sorteddv", new BytesRef("501")));
      }
      if (defaultCodecSupportsSortedSet()) {
        doc.add(new SortedSetDocValuesField("sortedsetdv", new BytesRef("two")));
        doc.add(new SortedSetDocValuesField("sortedsetdv", new BytesRef("three")));
      }
      w.addDocument(doc);
      w.deleteDocuments(new Term("id", "500"));
      w.close();
    }
View Full Code Here

            Document doc = new Document();
            Field idField = newStringField(random, "id", "", Field.Store.NO);
            Field binaryDVField = null;
            Field numericDVField = null;
            Field sortedDVField = null;
            Field sortedSetDVField = new SortedSetDocValuesField("sortedsetdv", new BytesRef());
            doc.add(idField);
            doc.add(newField(random, "field", "some text contents", storedTextType));
            if (defaultCodecSupportsDocValues()) {
              binaryDVField = new BinaryDocValuesField("binarydv", new BytesRef());
              numericDVField = new NumericDocValuesField("numericdv", 0);
              sortedDVField = new SortedDocValuesField("sorteddv", new BytesRef());
              doc.add(binaryDVField);
              doc.add(numericDVField);
              doc.add(sortedDVField);
            }
            if (defaultCodecSupportsSortedSet()) {
              doc.add(sortedSetDVField);
            }
            for(int i=0;i<100;i++) {
              idField.setStringValue(Integer.toString(i));
              if (defaultCodecSupportsDocValues()) {
                binaryDVField.setBytesValue(new BytesRef(idField.stringValue()));
                numericDVField.setLongValue(i);
                sortedDVField.setBytesValue(new BytesRef(idField.stringValue()));
              }
              sortedSetDVField.setBytesValue(new BytesRef(idField.stringValue()));
              int action = random.nextInt(100);
              if (action == 17) {
                w.addIndexes(adder);
              } else if (action%30 == 0) {
                w.deleteAll();
View Full Code Here

    int valId = 0;

    Terms terms = reader.terms(field);
    if (terms != null) {
      TermsEnum termsEnum = terms.iterator(null);
      BytesRef text;
      while ((text = termsEnum.next()) != null) {
        String strText = text.utf8ToString();
        String val = null;
        int weight = 0;
        String[] split = strText.split("\u0000");
        if (split.length > 1) {
          val = split[0];
View Full Code Here

TOP

Related Classes of org.apache.lucene.util.BytesRef

Copyright © 2018 www.massapicom. 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.