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


Java ArrayUtil.timSort方法代码示例

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


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

示例1: finishTerm

import org.apache.lucene.util.ArrayUtil; //导入方法依赖的package包/类
public void finishTerm(long defaultWeight) throws IOException {
    ArrayUtil.timSort(surfaceFormsAndPayload, 0, count);
    int deduplicator = 0;
    analyzed.append((byte) 0);
    analyzed.setLength(analyzed.length() + 1);
    analyzed.grow(analyzed.length());
    for (int i = 0; i < count; i++) {
        analyzed.setByteAt(analyzed.length() - 1, (byte) deduplicator++);
        Util.toIntsRef(analyzed.get(), scratchInts);
        SurfaceFormAndPayload candiate = surfaceFormsAndPayload[i];
        long cost = candiate.weight == -1 ? encodeWeight(Math.min(Integer.MAX_VALUE, defaultWeight)) : candiate.weight;
        builder.add(scratchInts.get(), outputs.newPair(cost, candiate.payload));
    }
    seenSurfaceForms.clear();
    count = 0;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:XAnalyzingSuggester.java

示例2: ConjunctionScorer

import org.apache.lucene.util.ArrayUtil; //导入方法依赖的package包/类
ConjunctionScorer(Weight weight, Scorer[] scorers, float coord) {
  super(weight);
  this.coord = coord;
  this.docsAndFreqs = new DocsAndFreqs[scorers.length];
  for (int i = 0; i < scorers.length; i++) {
    docsAndFreqs[i] = new DocsAndFreqs(scorers[i]);
  }
  // Sort the array the first time to allow the least frequent DocsEnum to
  // lead the matching.
  ArrayUtil.timSort(docsAndFreqs, new Comparator<DocsAndFreqs>() {
    @Override
    public int compare(DocsAndFreqs o1, DocsAndFreqs o2) {
      return Long.compare(o1.cost, o2.cost);
    }
  });

  lead = docsAndFreqs[0]; // least frequent DocsEnum leads the intersection
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:ConjunctionScorer.java

示例3: ConjunctionScorer

import org.apache.lucene.util.ArrayUtil; //导入方法依赖的package包/类
ConjunctionScorer(final Weight weight, final Scorer[] scorers,
		final float coord, final LearnToRankClause[] ltrclauses,
		final int docBase) {
	super(weight);
	this.coord = coord;
	this.docBase = docBase;
	clauses = ltrclauses;
	docsAndFreqs = new DocsAndFreqs[scorers.length];
	for (int i = 0; i < scorers.length; i++) {
		docsAndFreqs[i] = new DocsAndFreqs(scorers[i]);
	}
	// Sort the array the first time to allow the least frequent DocsEnum to
	// lead the matching.
	ArrayUtil.timSort(docsAndFreqs, new Comparator<DocsAndFreqs>() {
		@Override
		public int compare(final DocsAndFreqs obj1, final DocsAndFreqs obj2) {
			return Long.signum(obj1.cost - obj2.cost);
		}
	});

	lead = docsAndFreqs[0]; // least frequent DocsEnum leads the
							// intersection
}
 
开发者ID:quhfus,项目名称:DoSeR-Disambiguation,代码行数:24,代码来源:ConjunctionScorer.java

示例4: equalsTerms

import org.apache.lucene.util.ArrayUtil; //导入方法依赖的package包/类
private Term[] equalsTerms() {
    if (terms.length == 1) {
        return terms;
    }
    if (equalTerms == null) {
        // sort the terms to make sure equals and hashCode are consistent
        // this should be a very small cost and equivalent to a HashSet but less object creation
        final Term[] t = new Term[terms.length];
        System.arraycopy(terms, 0, t, 0, terms.length);
        ArrayUtil.timSort(t);
        equalTerms = t;
    }
    return equalTerms;

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

示例5: sendFiles

import org.apache.lucene.util.ArrayUtil; //导入方法依赖的package包/类
void sendFiles(Store store, StoreFileMetaData[] files, Function<StoreFileMetaData, OutputStream> outputStreamFactory) throws Exception {
    store.incRef();
    try {
        ArrayUtil.timSort(files, (a, b) -> Long.compare(a.length(), b.length())); // send smallest first
        for (int i = 0; i < files.length; i++) {
            final StoreFileMetaData md = files[i];
            try (IndexInput indexInput = store.directory().openInput(md.name(), IOContext.READONCE)) {
                // it's fine that we are only having the indexInput in the try/with block. The copy methods handles
                // exceptions during close correctly and doesn't hide the original exception.
                Streams.copy(new InputStreamIndexInput(indexInput, md.length()), outputStreamFactory.apply(md));
            } catch (Exception e) {
                final IOException corruptIndexException;
                if ((corruptIndexException = ExceptionsHelper.unwrapCorruption(e)) != null) {
                    if (store.checkIntegrityNoException(md) == false) { // we are corrupted on the primary -- fail!
                        logger.warn("{} Corrupted file detected {} checksum mismatch", shardId, md);
                        failEngine(corruptIndexException);
                        throw corruptIndexException;
                    } else { // corruption has happened on the way to replica
                        RemoteTransportException exception = new RemoteTransportException("File corruption occurred on recovery but " +
                                "checksums are ok", null);
                        exception.addSuppressed(e);
                        logger.warn(
                            (org.apache.logging.log4j.util.Supplier<?>) () -> new ParameterizedMessage(
                                "{} Remote file corruption on node {}, recovering {}. local checksum OK",
                                shardId,
                                request.targetNode(),
                                md),
                            corruptIndexException);
                        throw exception;
                    }
                } else {
                    throw e;
                }
            }
        }
    } finally {
        store.decRef();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:RecoverySourceHandler.java

示例6: testConsistentHitsWithSameSeed

import org.apache.lucene.util.ArrayUtil; //导入方法依赖的package包/类
public void testConsistentHitsWithSameSeed() throws Exception {
    createIndex("test");
    ensureGreen(); // make sure we are done otherwise preference could change?
    int docCount = randomIntBetween(100, 200);
    for (int i = 0; i < docCount; i++) {
        index("test", "type", "" + i, jsonBuilder().startObject().endObject());
    }
    flush();
    refresh();
    int outerIters = scaledRandomIntBetween(10, 20);
    for (int o = 0; o < outerIters; o++) {
        final int seed = randomInt();
        String preference = randomRealisticUnicodeOfLengthBetween(1, 10); // at least one char!!
        // randomPreference should not start with '_' (reserved for known preference types (e.g. _shards, _primary)
        while (preference.startsWith("_")) {
            preference = randomRealisticUnicodeOfLengthBetween(1, 10);
        }
        int innerIters = scaledRandomIntBetween(2, 5);
        SearchHit[] hits = null;
        for (int i = 0; i < innerIters; i++) {
            SearchResponse searchResponse = client().prepareSearch()
                    .setSize(docCount) // get all docs otherwise we are prone to tie-breaking
                    .setPreference(preference)
                    .setQuery(functionScoreQuery(matchAllQuery(), randomFunction(seed)))
                    .execute().actionGet();
            assertThat("Failures " + Arrays.toString(searchResponse.getShardFailures()),
                    searchResponse.getShardFailures().length, CoreMatchers.equalTo(0));
            final int hitCount = searchResponse.getHits().getHits().length;
            final SearchHit[] currentHits = searchResponse.getHits().getHits();
            ArrayUtil.timSort(currentHits, (o1, o2) -> {
                // for tie-breaking we have to resort here since if the score is
                // identical we rely on collection order which might change.
                int cmp = Float.compare(o1.getScore(), o2.getScore());
                return cmp == 0 ? o1.getId().compareTo(o2.getId()) : cmp;
            });
            if (i == 0) {
                assertThat(hits, nullValue());
                hits = currentHits;
            } else {
                assertThat(hits.length, equalTo(searchResponse.getHits().getHits().length));
                for (int j = 0; j < hitCount; j++) {
                    assertThat("" + j, currentHits[j].getScore(), equalTo(hits[j].getScore()));
                    assertThat("" + j, currentHits[j].getId(), equalTo(hits[j].getId()));
                }
            }

            // randomly change some docs to get them in different segments
            int numDocsToChange = randomIntBetween(20, 50);
            while (numDocsToChange > 0) {
                int doc = randomInt(docCount-1);// watch out this is inclusive the max values!
                index("test", "type", "" + doc, jsonBuilder().startObject().endObject());
                --numDocsToChange;
            }
            flush();
            refresh();
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:59,代码来源:RandomScoreFunctionIT.java

示例7: sort

import org.apache.lucene.util.ArrayUtil; //导入方法依赖的package包/类
public void sort() {
  // Tim sort performs well on already sorted arrays:
  if (count > 1) ArrayUtil.timSort(points, 0, count);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:Operations.java


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