Package org.apache.lucene.util

Examples of org.apache.lucene.util.BytesRefIterator


      random().nextBytes(current);
      sorter.add(new BytesRef(current));
    }

    // Create two iterators and check that they're aligned with each other.
    BytesRefIterator i1 = sorter.iterator();
    BytesRefIterator i2 = sorter.iterator();
   
    // Verify sorter contract.
    try {
      sorter.add(new BytesRef(new byte [1]));
      fail("expected contract violation.");
    } catch (IllegalStateException e) {
      // Expected.
    }
    BytesRef spare1;
    BytesRef spare2;
    while ((spare1 = i1.next()) != null && (spare2 = i2.next()) != null) {
      assertEquals(spare1, spare2);
    }
    assertNull(i1.next());
    assertNull(i2.next());
 
View Full Code Here


   */
  public BytesRefIterator iterator(final Comparator<BytesRef> comp) {
    final BytesRef spare = new BytesRef();
    final int size = size();
    final int[] indices = comp == null ? null : sort(comp);
    return new BytesRefIterator() {
      int pos = 0;
     
      @Override
      public BytesRef next() {
        if (pos < size) {
View Full Code Here

   * or unsorted keys from the dictionary's iterator - use
   * {@link SortedInputIterator} or
   * {@link UnsortedInputIterator} in such case.
   */
  public void build(Dictionary dict) throws IOException {
    BytesRefIterator it = dict.getWordsIterator();
    InputIterator tfit;
    if (it instanceof InputIterator) {
      tfit = (InputIterator)it;
    } else {
      tfit = new InputIterator.InputIteratorWrapper(it);
View Full Code Here

    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
    writer.commit();
    writer.close();
    IndexReader ir = DirectoryReader.open(dir);
    Dictionary dictionary = new HighFrequencyDictionary(ir, "bogus", 0.1f);
    BytesRefIterator tf = dictionary.getWordsIterator();
    assertNull(tf.getComparator());
    assertNull(tf.next());
    dir.close();
  }
View Full Code Here

      }
     
      boolean isEmpty = termsEnums.isEmpty();

      try {
        BytesRefIterator iter = dict.getWordsIterator();
        BytesRef currentTerm;
       
        terms: while ((currentTerm = iter.next()) != null) {
 
          String word = currentTerm.utf8ToString();
          int len = word.length();
          if (len < 3) {
            continue; // too short we bail but "too long" is fine...
View Full Code Here

        assertEquals("entry " + i + " doesn't match", stringList.get(e),
            spare.utf8ToString());
      }
      for (int i = 0; i < 2; i++) {
       
        BytesRefIterator iterator = list.iterator();
        for (String string : stringList) {
          assertEquals(string, iterator.next().utf8ToString());
        }
      }
    }
  }
View Full Code Here

        assertEquals(initSize + i, list.append(spare));
        stringList.add(randomRealisticUnicodeString);
      }
     
      Collections.sort(stringList);
      BytesRefIterator iter = list.iterator(BytesRef
          .getUTF8SortedAsUTF16Comparator());
      int i = 0;
      while ((spare = iter.next()) != null) {
        assertEquals("entry " + i + " doesn't match", stringList.get(i),
            spare.utf8ToString());
        i++;
      }
      assertNull(iter.next());
      assertEquals(i, stringList.size());
    }
   
  }
View Full Code Here

   
    BytesRef scratch = new BytesRef();
    BytesRef entry;
    final IntsRef scratchIntsRef = new IntsRef();
    int count = 0;
    BytesRefIterator iter = sorter.iterator();
    while((entry = iter.next()) != null) {
      count++;
      if (scratch.compareTo(entry) != 0) {
        builder.add(Util.toIntsRef(entry, scratchIntsRef), empty);
        scratch.copyBytes(entry);
      }
View Full Code Here

      }
     
      boolean isEmpty = termsEnums.isEmpty();

      try {
        BytesRefIterator iter = dict.getEntryIterator();
        BytesRef currentTerm;
       
        terms: while ((currentTerm = iter.next()) != null) {
 
          String word = currentTerm.utf8ToString();
          int len = word.length();
          if (len < 3) {
            continue; // too short we bail but "too long" is fine...
View Full Code Here

   * or unsorted keys from the dictionary's iterator - use
   * {@link SortedTermFreqIteratorWrapper} or
   * {@link UnsortedTermFreqIteratorWrapper} in such case.
   */
  public void build(Dictionary dict) throws IOException {
    BytesRefIterator it = dict.getWordsIterator();
    TermFreqIterator tfit;
    if (it instanceof TermFreqIterator) {
      tfit = (TermFreqIterator)it;
    } else {
      tfit = new TermFreqIterator.TermFreqIteratorWrapper(it);
View Full Code Here

TOP

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

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.