Package org.apache.lucene.facet.encoding

Examples of org.apache.lucene.facet.encoding.IntEncoder


  }
 
  /** Returns a {@link CategoryListParams} with random {@link IntEncoder}. */
  public static CategoryListParams randomCategoryListParams(String field) {
    Random random = random();
    final IntEncoder encoder = ENCODERS[random.nextInt(ENCODERS.length)];
    return new CategoryListParams(field) {
      @Override
      public IntEncoder createEncoder() {
        return encoder;
      }
View Full Code Here


      }
     
      HashMap<String,BytesRef> partitionBytes = new HashMap<String,BytesRef>();
      for (Entry<String,IntsRef> e : partitionOrdinals.entrySet()) {
        String name = e.getKey();
        final IntEncoder encoder = partitionEncoder.get(name);
        final BytesRef bytes = new BytesRef(128); // should be enough for most common applications       
        encoder.encode(e.getValue(), bytes);
        partitionBytes.put(name, bytes);
      }
      return partitionBytes;
    }
View Full Code Here

  public void testVInt8() throws Exception {
    encoderTest(new VInt8IntEncoder(), data, data);
   
    // cover negative numbers;
    BytesRef bytes = new BytesRef(5);
    IntEncoder enc = new VInt8IntEncoder();
    IntsRef values = new IntsRef(1);
    values.ints[values.length++] = -1;
    enc.encode(values, bytes);
   
    IntDecoder dec = enc.createMatchingDecoder();
    values.length = 0;
    dec.decode(bytes, values);
    assertEquals(1, values.length);
    assertEquals(-1, values.ints[0]);
  }
View Full Code Here

  @Test
  public void testDefaultSettings() {
    CategoryListParams clp = new CategoryListParams();
    assertEquals("wrong default field", "$facets", clp.field);
    IntEncoder encoder = new SortingIntEncoder(new UniqueValuesIntEncoder(new DGapVInt8IntEncoder()));
    IntDecoder decoder = encoder.createMatchingDecoder();
    assertEquals("unexpected default encoder", encoder.toString(), clp.createEncoder().toString());
    assertEquals("unexpected default decoder", decoder.toString(), clp.createEncoder().createMatchingDecoder().toString());
  }
View Full Code Here

  };

  @Test
  public void test() throws Exception {
    Directory dir = newDirectory();
    final IntEncoder encoder = randomCategoryListParams().createEncoder();
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir, newIndexWriterConfig(TEST_VERSION_CURRENT,
        new MockAnalyzer(random(), MockTokenizer.KEYWORD, false)).setMergePolicy(newLogMergePolicy()));
    BytesRef buf = new BytesRef();
    for (int i = 0; i < data.length; i++) {
      Document doc = new Document();
      encoder.encode(IntsRef.deepCopyOf(data[i]), buf);
      doc.add(new BinaryDocValuesField("f", buf));
      writer.addDocument(doc);
    }
    IndexReader reader = writer.getReader();
    writer.close();

    int totalCategories = 0;
    IntsRef ordinals = new IntsRef();
    CategoryListIterator cli = new DocValuesCategoryListIterator("f", encoder.createMatchingDecoder());
    for (AtomicReaderContext context : reader.leaves()) {
      assertTrue("failed to initalize iterator", cli.setNextReader(context));
      int maxDoc = context.reader().maxDoc();
      int dataIdx = context.docBase;
      for (int doc = 0; doc < maxDoc; doc++, dataIdx++) {
View Full Code Here

  }

  @Test
  public void testEmptyDocuments() throws Exception {
    Directory dir = newDirectory();
    final IntEncoder encoder = new SortingIntEncoder(new UniqueValuesIntEncoder(new DGapIntEncoder(new VInt8IntEncoder())));
    // NOTE: test is wired to LogMP... because test relies on certain docids having payloads
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir,
        newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
    for (int i = 0; i < data.length; i++) {
      Document doc = new Document();
      if (i == 0) {
        BytesRef buf = new BytesRef();
        encoder.encode(IntsRef.deepCopyOf(data[i]), buf );
        doc.add(new BinaryDocValuesField("f", buf));
      } else {
        doc.add(new BinaryDocValuesField("f", new BytesRef()));
      }
      writer.addDocument(doc);
      writer.commit();
    }

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

    int totalCategories = 0;
    IntsRef ordinals = new IntsRef();
    CategoryListIterator cli = new DocValuesCategoryListIterator("f", encoder.createMatchingDecoder());
    for (AtomicReaderContext context : reader.leaves()) {
      assertTrue("failed to initalize iterator", cli.setNextReader(context));
      int maxDoc = context.reader().maxDoc();
      int dataIdx = context.docBase;
      for (int doc = 0; doc < maxDoc; doc++, dataIdx++) {
View Full Code Here

      }
     
      HashMap<String,BytesRef> partitionBytes = new HashMap<String,BytesRef>();
      for (Entry<String,IntsRef> e : partitionOrdinals.entrySet()) {
        String name = e.getKey();
        final IntEncoder encoder = partitionEncoder.get(name);
        final BytesRef bytes = new BytesRef(128); // should be enough for most common applications       
        encoder.encode(e.getValue(), bytes);
        partitionBytes.put(name, bytes);
      }
      return partitionBytes;
    }
View Full Code Here

  }
 
  /** Returns a {@link CategoryListParams} with random {@link IntEncoder}. */
  public static CategoryListParams randomCategoryListParams(String field) {
    Random random = random();
    final IntEncoder encoder = ENCODERS[random.nextInt(ENCODERS.length)];
    return new CategoryListParams(field) {
      @Override
      public IntEncoder createEncoder() {
        return encoder;
      }
View Full Code Here

  }
 
  /** Returns a {@link CategoryListParams} with random {@link IntEncoder}. */
  public static CategoryListParams randomCategoryListParams(String field) {
    Random random = random();
    final IntEncoder encoder = ENCODERS[random.nextInt(ENCODERS.length)];
    return new CategoryListParams(field) {
      @Override
      public IntEncoder createEncoder() {
        return encoder;
      }
View Full Code Here

TOP

Related Classes of org.apache.lucene.facet.encoding.IntEncoder

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.