List of usage examples for org.apache.lucene.util Counter newCounter
public static Counter newCounter()
From source file:com.meltwater.elasticsearch.index.BatchPercolatorService.java
License:Apache License
private SearchContext createSearchContext(BatchPercolateShardRequest request, IndexService percolateIndexService, IndexShard indexShard, Directory directory) throws IOException { SearchShardTarget searchShardTarget = new SearchShardTarget(clusterService.localNode().id(), request.shardId().getIndex(), request.shardId().id()); return new DefaultSearchContext(0, new ShardSearchLocalRequest(new ShardId("local_index", 0), 0, SearchType.QUERY_AND_FETCH, null, null, false),/*from w w w . ja v a2 s. c o m*/ searchShardTarget, new DocSearcher(new IndexSearcher(DirectoryReader.open(directory))), percolateIndexService, indexShard, scriptService, cacheRecycler, pageCacheRecycler, bigArrays, Counter.newCounter()); }
From source file:org.alfresco.solr.query.MimetypeGroupingCollector.java
License:Open Source License
@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;//from w ww . j a v a 2 s .c o m } Counter counter = counters.get(group); if (counter == null) { counter = Counter.newCounter(); counters.put(group, counter); } counter.addAndGet(1); } } leafDelegate.collect(doc); }
From source file:org.elasticsearch.common.util.CollectionUtilsTests.java
License:Apache License
@Test 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)); }/* w w w .j ava 2s. c o m*/ if (randomBoolean()) { Collections.shuffle(tmpList, getRandom()); 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())); } }
From source file:org.elasticsearch.common.util.CollectionUtilsTests.java
License:Apache License
@Test 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)); }//from w w w .jav a2 s. c o m if (randomBoolean()) { Collections.shuffle(values, getRandom()); } 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())); } }
From source file:solutions.siren.join.action.terms.collector.BytesRefTermsSet.java
License:Open Source License
public BytesRefTermsSet(final CircuitBreaker breaker) { super(breaker); this.bytesUsed = Counter.newCounter(); this.pool = new ByteBlockPool(new ByteBlockPool.DirectTrackingAllocator(bytesUsed)); this.set = new BytesRefHash(pool); }
From source file:solutions.siren.join.action.terms.collector.BytesRefTermsSet.java
License:Open Source License
@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());/*from w w w. j a va2s . co m*/ } }
From source file:solutions.siren.join.action.terms.collector.BytesRefTermsSet.java
License:Open Source License
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);//w ww .j a v a2 s . c om } }