当前位置: 首页>>代码示例>>Java>>正文


Java Counter.newCounter方法代码示例

本文整理汇总了Java中org.apache.lucene.util.Counter.newCounter方法的典型用法代码示例。如果您正苦于以下问题:Java Counter.newCounter方法的具体用法?Java Counter.newCounter怎么用?Java Counter.newCounter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.util.Counter的用法示例。


在下文中一共展示了Counter.newCounter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readFromBytes

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
private void readFromBytes(BytesRef bytes) {
  // Read pruned flag
  this.setIsPruned(bytes.bytes[bytes.offset++] == 1 ? true : false);

  // Read size fo the set
  int size = Bytes.readInt(bytes);

  // Read terms
  bytesUsed = Counter.newCounter();
  pool = new ByteBlockPool(new ByteBlockPool.DirectTrackingAllocator(bytesUsed));
  set = new BytesRefHash(pool);

  BytesRef reusable = new BytesRef();
  for (int i = 0; i < size; i++) {
    Bytes.readBytesRef(bytes, reusable);
    set.add(reusable);
  }
}
 
开发者ID:sirensolutions,项目名称:siren-join,代码行数:19,代码来源:BytesRefTermsSet.java

示例2: TermsHash

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
public TermsHash(final DocumentsWriterPerThread docWriter, final TermsHashConsumer consumer, boolean trackAllocations, final TermsHash nextTermsHash) {
  this.docState = docWriter.docState;
  this.consumer = consumer;
  this.trackAllocations = trackAllocations; 
  this.nextTermsHash = nextTermsHash;
  this.bytesUsed = trackAllocations ? docWriter.bytesUsed : Counter.newCounter();
  intPool = new IntBlockPool(docWriter.intBlockAllocator);
  bytePool = new ByteBlockPool(docWriter.byteBlockAllocator);

  if (nextTermsHash != null) {
    // We are primary
    primary = true;
    termBytePool = bytePool;
    nextTermsHash.termBytePool = bytePool;
  } else {
    primary = false;
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:19,代码来源:TermsHash.java

示例3: DocumentsWriterPerThread

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
public DocumentsWriterPerThread(Directory directory, DocumentsWriter parent,
    FieldInfos.Builder fieldInfos, IndexingChain indexingChain) {
  this.directoryOrig = directory;
  this.directory = new TrackingDirectoryWrapper(directory);
  this.parent = parent;
  this.fieldInfos = fieldInfos;
  this.writer = parent.indexWriter;
  this.infoStream = parent.infoStream;
  this.codec = parent.codec;
  this.docState = new DocState(this, infoStream);
  this.docState.similarity = parent.indexWriter.getConfig().getSimilarity();
  bytesUsed = Counter.newCounter();
  byteBlockAllocator = new DirectTrackingAllocator(bytesUsed);
  pendingDeletes = new BufferedDeletes();
  intBlockAllocator = new IntBlockAllocator(bytesUsed);
  initialize();
  // this should be the last call in the ctor 
  // it really sucks that we need to pull this within the ctor and pass this ref to the chain!
  consumer = indexingChain.getChain(this);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:21,代码来源:DocumentsWriterPerThread.java

示例4: testSortAndDedupByteRefArray

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
public void testSortAndDedupByteRefArray() {
    SortedSet<BytesRef> set = new TreeSet<>();
    final int numValues = scaledRandomIntBetween(0, 10000);
    List<BytesRef> tmpList = new ArrayList<>();
    BytesRefArray array = new BytesRefArray(Counter.newCounter());
    for (int i = 0; i < numValues; i++) {
        String s = randomRealisticUnicodeOfCodepointLengthBetween(1, 100);
        set.add(new BytesRef(s));
        tmpList.add(new BytesRef(s));
        array.append(new BytesRef(s));
    }
    if (randomBoolean()) {
        Collections.shuffle(tmpList, random());
        for (BytesRef ref : tmpList) {
            array.append(ref);
        }
    }
    int[] indices = new int[array.size()];
    for (int i = 0; i < indices.length; i++) {
        indices[i] = i;
    }
    int numUnique = CollectionUtils.sortAndDedup(array, indices);
    assertThat(numUnique, equalTo(set.size()));
    Iterator<BytesRef> iterator = set.iterator();

    BytesRefBuilder spare = new BytesRefBuilder();
    for (int i = 0; i < numUnique; i++) {
        assertThat(iterator.hasNext(), is(true));
        assertThat(array.get(spare, indices[i]), equalTo(iterator.next()));
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:CollectionUtilsTests.java

示例5: testSortByteRefArray

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
public void testSortByteRefArray() {
    List<BytesRef> values = new ArrayList<>();
    final int numValues = scaledRandomIntBetween(0, 10000);
    BytesRefArray array = new BytesRefArray(Counter.newCounter());
    for (int i = 0; i < numValues; i++) {
        String s = randomRealisticUnicodeOfCodepointLengthBetween(1, 100);
        values.add(new BytesRef(s));
        array.append(new BytesRef(s));
    }
    if (randomBoolean()) {
        Collections.shuffle(values, random());
    }
    int[] indices = new int[array.size()];
    for (int i = 0; i < indices.length; i++) {
        indices[i] = i;
    }
    CollectionUtils.sort(array, indices);
    Collections.sort(values);
    Iterator<BytesRef> iterator = values.iterator();

    BytesRefBuilder spare = new BytesRefBuilder();
    for (int i = 0; i < values.size(); i++) {
        assertThat(iterator.hasNext(), is(true));
        assertThat(array.get(spare, indices[i]), equalTo(iterator.next()));
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:CollectionUtilsTests.java

示例6: TermsHash

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
TermsHash(final DocumentsWriterPerThread docWriter, boolean trackAllocations, TermsHash nextTermsHash) {
  this.docState = docWriter.docState;
  this.trackAllocations = trackAllocations; 
  this.nextTermsHash = nextTermsHash;
  this.bytesUsed = trackAllocations ? docWriter.bytesUsed : Counter.newCounter();
  intPool = new IntBlockPool(docWriter.intBlockAllocator);
  bytePool = new ByteBlockPool(docWriter.byteBlockAllocator);

  if (nextTermsHash != null) {
    // We are primary
    termBytePool = bytePool;
    nextTermsHash.termBytePool = bytePool;
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:TermsHash.java

示例7: readFrom

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
  this.setIsPruned(in.readBoolean());
  int size = in.readInt();

  bytesUsed = Counter.newCounter();
  pool = new ByteBlockPool(new ByteBlockPool.DirectTrackingAllocator(bytesUsed));
  set = new BytesRefHash(pool);

  for (long i = 0; i < size; i++) {
    set.add(in.readBytesRef());
  }
}
 
开发者ID:sirensolutions,项目名称:siren-join,代码行数:14,代码来源:BytesRefTermsSet.java

示例8: testSingleWriterReader

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
public void testSingleWriterReader() {
  Counter bytesUsed = Counter.newCounter();
  IntBlockPool pool = new IntBlockPool(new ByteTrackingAllocator(bytesUsed));
  
  for (int j = 0; j < 2; j++) {
    IntBlockPool.SliceWriter writer = new IntBlockPool.SliceWriter(pool);
    int start = writer.startNewSlice();
    int num = atLeast(100);
    for (int i = 0; i < num; i++) {
      writer.writeInt(i);
    }
    
    int upto = writer.getCurrentOffset();
    IntBlockPool.SliceReader reader = new IntBlockPool.SliceReader(pool);
    reader.reset(start, upto);
    for (int i = 0; i < num; i++) {
      assertEquals(i, reader.readInt());
    }
    assertTrue(reader.endOfSlice());
    if (random().nextBoolean()) {
      pool.reset(true, false);
      assertEquals(0, bytesUsed.get());
    } else {
      pool.reset(true, true);
      assertEquals(IntBlockPool.INT_BLOCK_SIZE
          * RamUsageEstimator.NUM_BYTES_INT, bytesUsed.get());
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:30,代码来源:TestIntBlockPool.java

示例9: collect

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
@Override
public void collect(int doc) throws IOException 
{
    if(sortedDocValues != null)
    {
        int ordinal = sortedDocValues.getOrd(doc);
        if(ordinal > -1)
        {
            String value = (String)schemaField.getType().toObject(schemaField, sortedDocValues.lookupOrd(ordinal));
            String group = doGroup ? mappings.get(value) : value;
            if(group == null)
            {
                group = value;
            }

            Counter counter = counters.get(group);
            if(counter == null)
            {
                counter = Counter.newCounter();
                counters.put(group, counter);
            }
            counter.addAndGet(1);
        }
    }


    delegate.collect(doc);
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:29,代码来源:MimetypeGroupingCollector.java

示例10: newCollector

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
@Override
public AccessibleTimeLimitingCollector newCollector() throws IOException {
    return new AccessibleTimeLimitingCollector(
            TopScoreDocCollector.create(perPage, lastEntry), Counter.newCounter(false), searchTimeoutMs
    );
}
 
开发者ID:yahoo,项目名称:fili,代码行数:7,代码来源:TimeLimitingCollectorManager.java

示例11: TimeOutThread

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
public TimeOutThread () {
    super("TimeOutThread");
    counter = Counter.newCounter(true);
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:5,代码来源:TimeOutThread.java

示例12: BytesRefTermsSet

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
public BytesRefTermsSet(final CircuitBreaker breaker) {
  super(breaker);
  this.bytesUsed = Counter.newCounter();
  this.pool = new ByteBlockPool(new ByteBlockPool.DirectTrackingAllocator(bytesUsed));
  this.set = new BytesRefHash(pool);
}
 
开发者ID:sirensolutions,项目名称:siren-join,代码行数:7,代码来源:BytesRefTermsSet.java

示例13: setUp

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
/**
 * initializes searcher with a document set
 */
@Override
public void setUp() throws Exception {
  super.setUp();
  counter = Counter.newCounter(true);
  counterThread = new TimerThread(counter);
  counterThread.start();
  final String docText[] = {
      "docThatNeverMatchesSoWeCanRequireLastDocCollectedToBeGreaterThanZero",
      "one blah three",
      "one foo three multiOne",
      "one foobar three multiThree",
      "blueberry pancakes",
      "blueberry pie",
      "blueberry strudel",
      "blueberry pizza",
  };
  directory = newDirectory();
  RandomIndexWriter iw = new RandomIndexWriter(random(), directory, newIndexWriterConfig(new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
  
  for (int i=0; i<N_DOCS; i++) {
    add(docText[i%docText.length], iw);
  }
  reader = iw.getReader();
  iw.close();
  searcher = newSearcher(reader);

  BooleanQuery booleanQuery = new BooleanQuery();
  booleanQuery.add(new TermQuery(new Term(FIELD_NAME, "one")), BooleanClause.Occur.SHOULD);
  // start from 1, so that the 0th doc never matches
  for (int i = 1; i < docText.length; i++) {
    String[] docTextParts = docText[i].split("\\s+");
    for (String docTextPart : docTextParts) { // large query so that search will be longer
      booleanQuery.add(new TermQuery(new Term(FIELD_NAME, docTextPart)), BooleanClause.Occur.SHOULD);
    }
  }

  query = booleanQuery;
  
  // warm the searcher
  searcher.search(query, null, 1000);
}
 
开发者ID:europeana,项目名称:search,代码行数:45,代码来源:TestTimeLimitingCollector.java

示例14: testAppend

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
public void testAppend() throws IOException {
  Random random = random();
  BytesRefArray list = new BytesRefArray(Counter.newCounter());
  List<String> stringList = new ArrayList<>();
  for (int j = 0; j < 2; j++) {
    if (j > 0 && random.nextBoolean()) {
      list.clear();
      stringList.clear();
    }
    int entries = atLeast(500);
    BytesRefBuilder spare = new BytesRefBuilder();
    int initSize = list.size();
    for (int i = 0; i < entries; i++) {
      String randomRealisticUnicodeString = TestUtil
          .randomRealisticUnicodeString(random);
      spare.copyChars(randomRealisticUnicodeString);
      assertEquals(i+initSize, list.append(spare.get()));
      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.get().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.get().utf8ToString());
    }
    for (int i = 0; i < 2; i++) {
      
      BytesRefIterator iterator = list.iterator();
      for (String string : stringList) {
        assertEquals(string, iterator.next().utf8ToString());
      }
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:42,代码来源:TestBytesRefArray.java

示例15: testAppend

import org.apache.lucene.util.Counter; //导入方法依赖的package包/类
public void testAppend() throws IOException {
  Random random = random();
  BytesRefArray list = new BytesRefArray(Counter.newCounter());
  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();
    int initSize = list.size();
    for (int i = 0; i < entries; i++) {
      String randomRealisticUnicodeString = _TestUtil
          .randomRealisticUnicodeString(random);
      spare.copyChars(randomRealisticUnicodeString);
      assertEquals(i+initSize, 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());
      }
    }
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:42,代码来源:TestBytesRefArray.java


注:本文中的org.apache.lucene.util.Counter.newCounter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。