Package org.apache.lucene.search.suggest

Examples of org.apache.lucene.search.suggest.BytesRefList


    }
  }

  /** Sort a single partition in-memory. */
  protected File sortPartition(int len) throws IOException {
    BytesRefList data = this.buffer;
    File tempFile = File.createTempFile("sort", "partition", tempDirectory);

    long start = System.currentTimeMillis();
    sortInfo.sortTime += (System.currentTimeMillis() - start);
   
    final ByteSequencesWriter out = new ByteSequencesWriter(tempFile);
    BytesRef spare;
    try {
      BytesRefIterator iter = buffer.iterator(comparator);
      while((spare = iter.next()) != null) {
        assert spare.length <= Short.MAX_VALUE;
        out.write(spare);
      }
     
      out.close();

      // Clean up the buffer for the next partition.
      data.clear();
      return tempFile;
    } finally {
      IOUtils.close(out);
    }
  }
View Full Code Here


import org.apache.lucene.util._TestUtil;

public class TestBytesRefList extends LuceneTestCase {
 
  public void testAppend() throws IOException {
    BytesRefList list = new BytesRefList();
    List<String> stringList = new ArrayList<String>();
    for (int j = 0; j < 2; j++) {
      if (j > 0 && random.nextBoolean()) {
        list.clear();
        stringList.clear();
      }
      int entries = atLeast(500);
      BytesRef spare = new BytesRef();
      for (int i = 0; i < entries; i++) {
        String randomRealisticUnicodeString = _TestUtil
            .randomRealisticUnicodeString(random);
        spare.copyChars(randomRealisticUnicodeString);
        list.append(spare);
        stringList.add(randomRealisticUnicodeString);
      }
      for (int i = 0; i < entries; i++) {
        assertNotNull(list.get(spare, i));
        assertEquals("entry " + i + " doesn't match", stringList.get(i),
            spare.utf8ToString());
      }
     
      // check random
      for (int i = 0; i < entries; i++) {
        int e = random.nextInt(entries);
        assertNotNull(list.get(spare, e));
        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

      }
    }
  }
 
  public void testSort() throws IOException {
    BytesRefList list = new BytesRefList();
    List<String> stringList = new ArrayList<String>();

    for (int j = 0; j < 2; j++) {
      if (j > 0 && random.nextBoolean()) {
        list.clear();
        stringList.clear();
      }
      int entries = atLeast(500);
      BytesRef spare = new BytesRef();
      for (int i = 0; i < entries; i++) {
        String randomRealisticUnicodeString = _TestUtil
            .randomRealisticUnicodeString(random);
        spare.copyChars(randomRealisticUnicodeString);
        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());
View Full Code Here

    }
  }

  /** Sort a single partition in-memory. */
  protected File sortPartition(int len) throws IOException {
    BytesRefList data = this.buffer;
    File tempFile = File.createTempFile("sort", "partition", tempDirectory);

    long start = System.currentTimeMillis();
    sortInfo.sortTime += (System.currentTimeMillis() - start);
   
    final ByteSequencesWriter out = new ByteSequencesWriter(tempFile);
    BytesRef spare;
    try {
      BytesRefIterator iter = buffer.iterator(comparator);
      while((spare = iter.next()) != null) {
        assert spare.length <= Short.MAX_VALUE;
        out.write(spare);
      }
     
      out.close();

      // Clean up the buffer for the next partition.
      data.clear();
      return tempFile;
    } finally {
      IOUtils.close(out);
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.suggest.BytesRefList

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.