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


Java SortField类代码示例

本文整理汇总了Java中org.apache.lucene.search.SortField的典型用法代码示例。如果您正苦于以下问题:Java SortField类的具体用法?Java SortField怎么用?Java SortField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: assertAvgScoreMode

import org.apache.lucene.search.SortField; //导入依赖的package包/类
@Override
protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher) throws IOException {
    MultiValueMode sortMode = MultiValueMode.AVG;
    Query childFilter = Queries.not(parentFilter);
    XFieldComparatorSource nestedComparatorSource = createFieldComparator("field2", sortMode, -127, createNested(searcher, parentFilter, childFilter));
    Query query = new ToParentBlockJoinQuery(new ConstantScoreQuery(childFilter), new QueryBitSetProducer(parentFilter), ScoreMode.None);
    Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
    TopDocs topDocs = searcher.search(query, 5, sort);
    assertThat(topDocs.totalHits, equalTo(7));
    assertThat(topDocs.scoreDocs.length, equalTo(5));
    assertThat(topDocs.scoreDocs[0].doc, equalTo(11));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[1].doc, equalTo(7));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[1]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[2].doc, equalTo(3));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[2]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[3].doc, equalTo(15));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[3]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[4].doc, equalTo(19));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).intValue(), equalTo(3));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DoubleNestedSortingTests.java

示例2: assertAvgScoreMode

import org.apache.lucene.search.SortField; //导入依赖的package包/类
protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher, IndexFieldData.XFieldComparatorSource innerFieldComparator) throws IOException {
    MultiValueMode sortMode = MultiValueMode.AVG;
    Query childFilter = Queries.not(parentFilter);
    XFieldComparatorSource nestedComparatorSource = createFieldComparator("field2", sortMode, -127, createNested(searcher, parentFilter, childFilter));
    Query query = new ToParentBlockJoinQuery(new ConstantScoreQuery(childFilter), new QueryBitSetProducer(parentFilter), ScoreMode.None);
    Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
    TopDocs topDocs = searcher.search(query, 5, sort);
    assertThat(topDocs.totalHits, equalTo(7));
    assertThat(topDocs.scoreDocs.length, equalTo(5));
    assertThat(topDocs.scoreDocs[0].doc, equalTo(11));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[1].doc, equalTo(7));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[1]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[2].doc, equalTo(3));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[2]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[3].doc, equalTo(15));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[3]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[4].doc, equalTo(19));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).intValue(), equalTo(3));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:FloatNestedSortingTests.java

示例3: assertAvgScoreMode

import org.apache.lucene.search.SortField; //导入依赖的package包/类
protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher) throws IOException {
    MultiValueMode sortMode = MultiValueMode.AVG;
    Query childFilter = Queries.not(parentFilter);
    XFieldComparatorSource nestedComparatorSource = createFieldComparator("field2", sortMode, -127, createNested(searcher, parentFilter, childFilter));
    Query query = new ToParentBlockJoinQuery(new ConstantScoreQuery(childFilter), new QueryBitSetProducer(parentFilter), ScoreMode.None);
    Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
    TopDocs topDocs = searcher.search(query, 5, sort);
    assertThat(topDocs.totalHits, equalTo(7));
    assertThat(topDocs.scoreDocs.length, equalTo(5));
    assertThat(topDocs.scoreDocs[0].doc, equalTo(11));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[1].doc, equalTo(3));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[1]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[2].doc, equalTo(7));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[2]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[3].doc, equalTo(15));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[3]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[4].doc, equalTo(19));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).intValue(), equalTo(4));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:AbstractNumberNestedSortingTestCase.java

示例4: randomOfType

import org.apache.lucene.search.SortField; //导入依赖的package包/类
private Object randomOfType(SortField.Type type) {
    switch (type) {
    case CUSTOM:
        throw new UnsupportedOperationException();
    case DOC:
        return between(0, IndexWriter.MAX_DOCS);
    case DOUBLE:
        return randomDouble();
    case FLOAT:
        return randomFloat();
    case INT:
        return randomInt();
    case LONG:
        return randomLong();
    case REWRITEABLE:
        throw new UnsupportedOperationException();
    case SCORE:
        return randomFloat();
    case STRING:
        return new BytesRef(randomAsciiOfLength(5));
    case STRING_VAL:
        return new BytesRef(randomAsciiOfLength(5));
    default:
        throw new UnsupportedOperationException("Unkown SortField.Type: " + type);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:InternalTopHitsTests.java

示例5: testSortValues

import org.apache.lucene.search.SortField; //导入依赖的package包/类
public void testSortValues() throws Exception {
    Directory dir = new RAMDirectory();
    IndexWriter indexWriter = new IndexWriter(dir, new IndexWriterConfig(Lucene.STANDARD_ANALYZER));
    for (int i = 0; i < 10; i++) {
        Document document = new Document();
        String text = new String(new char[]{(char) (97 + i), (char) (97 + i)});
        document.add(new TextField("str", text, Field.Store.YES));
        document.add(new SortedDocValuesField("str", new BytesRef(text)));
        indexWriter.addDocument(document);
    }
    IndexReader reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(indexWriter));
    IndexSearcher searcher = new IndexSearcher(reader);
    TopFieldDocs docs = searcher.search(new MatchAllDocsQuery(), 10, new Sort(new SortField("str", SortField.Type.STRING)));
    for (int i = 0; i < 10; i++) {
        FieldDoc fieldDoc = (FieldDoc) docs.scoreDocs[i];
        assertThat((BytesRef) fieldDoc.fields[0], equalTo(new BytesRef(new String(new char[]{(char) (97 + i), (char) (97 + i)}))));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:SimpleLuceneTests.java

示例6: missingValue

import org.apache.lucene.search.SortField; //导入依赖的package包/类
/** Calculates the missing Values as in {@link org.elasticsearch.index.fielddata.IndexFieldData}
 * The results in the {@link org.apache.lucene.search.ScoreDoc} contains this missingValues instead of nulls. Because we
 * need nulls in the result, it's necessary to check if a value is a missingValue.
 */
public static Object missingValue(boolean reverseFlag, Boolean nullFirst, SortField.Type type) {
    boolean min = reverseFlag ^ (nullFirst != null ? nullFirst : reverseFlag);
    switch (type) {
        case INT:
        case LONG:
            return min ? Long.MIN_VALUE : Long.MAX_VALUE;
        case FLOAT:
            return min ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY;
        case DOUBLE:
            return min ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
        case STRING:
        case STRING_VAL:
            return min ? null : MAX_TERM;
        default:
            throw new UnsupportedOperationException("Unsupported reduced type: " + type);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:LuceneMissingValue.java

示例7: generateLuceneSort

import org.apache.lucene.search.SortField; //导入依赖的package包/类
@Nullable
public static Sort generateLuceneSort(CollectorContext context,
                                      OrderBy orderBy,
                                      CollectInputSymbolVisitor<?> inputSymbolVisitor) {
    if (orderBy.orderBySymbols().isEmpty()) {
        return null;
    }
    SortSymbolVisitor sortSymbolVisitor = new SortSymbolVisitor(inputSymbolVisitor);
    SortField[] sortFields = sortSymbolVisitor.generateSortFields(
            orderBy.orderBySymbols(),
            context,
            orderBy.reverseFlags(),
            orderBy.nullsFirst()
    );
    return new Sort(sortFields);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:LuceneSortGenerator.java

示例8: run

import org.apache.lucene.search.SortField; //导入依赖的package包/类
@Override
public void run() {
  int i = 0;
  while (i < 10000) {
    try {
      if (data.size() <= i) {
        sleep(1);
        continue;
      }
      final String key = "key" + i;
      final String val = "value" + i;
      final List<Document> documents = index.searchForDocuments(new TermQuery(new Term(key, val)), 10, new Sort(new SortField(key, SortField.Type.STRING)));
      if (documents.size() != 1) {
        throw new RuntimeException("Invalid number of matching documents for " + key + ", found " + documents);
      }
      ++i;
    } catch (IOException ioe) {
      error = ioe;
      break;
    } catch (InterruptedException e) {
    } catch (AlreadyClosedException ace) {
      error = ace;
      break;
    }
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:27,代码来源:TestLuceneIndexer.java

示例9: prefixSearch

import org.apache.lucene.search.SortField; //导入依赖的package包/类
@Override
public ScoreDoc[] prefixSearch(String keywords) throws IOException {
    if (StringUtils.isEmpty(keywords) || keywords.length() > appConfig.getKeywordMaxLength()) {
        logger.error("empty keywords or over-length! {}", keywords);
        return null;
    }
    Sort sort = new Sort(new SortField("downloadRank", SortField.INT, true));

    Term nameFldTerm = new Term(fieldName, keywords);
    PrefixQuery nameFldQuery = new PrefixQuery(nameFldTerm);

    NumericRangeQuery<Integer> catalogQuery = NumericRangeQuery.newIntRange("catalog",
            (int) EnumCatalog.SOFT.getCatalog(), (int) EnumCatalog.GAME.getCatalog(), true, true);
    BooleanQuery booleanQuery = new BooleanQuery();
    booleanQuery.add(catalogQuery, Occur.MUST);
    booleanQuery.add(nameFldQuery, Occur.MUST);

    TopDocs topDocs = quickTipsSearcher.search(booleanQuery, appConfig.getQuickTipsNum() * 2, sort);
    ScoreDoc[] docs = topDocs.scoreDocs;
    return docs;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:22,代码来源:QuickTipsServiceImpl.java

示例10: getInstance

import org.apache.lucene.search.SortField; //导入依赖的package包/类
@Override
public MergePolicy getInstance(Map<String, String> params) throws IOException {
  String field = params.get(SORT_FIELD);
  SortField.Type sortFieldType = SortField.Type.DOC;
  if (params.containsKey(SORT_FIELD_TYPE)) {
    sortFieldType = SortField.Type.valueOf(params.get(SORT_FIELD_TYPE).toUpperCase());
  }

  if (sortFieldType == SortField.Type.DOC) {
    throw new IOException(
        "Relying on internal lucene DocIDs is not guaranteed to work, this is only an implementation detail.");
  }

  boolean desc = true;
  if (params.containsKey(SORT_DESC)) {
    try {
      desc = Boolean.valueOf(params.get(SORT_DESC));
    } catch (Exception e) {
      desc = true;
    }
  }
  SortField sortField = new SortField(field, sortFieldType, desc);
  Sort sort = new Sort(sortField);
  return new SortingMergePolicyDecorator(new TieredMergePolicy(), sort);
}
 
开发者ID:XiaoMi,项目名称:linden,代码行数:26,代码来源:SortingMergePolicyFactory.java

示例11: sortField

import org.apache.lucene.search.SortField; //导入依赖的package包/类
/**
 * Returns a Lucene {@link SortField} for sorting documents/rows according
 * to the partition key.
 *
 * @return a sort field for sorting by partition key
 */
public SortField sortField() {
	return new SortField(FIELD_NAME, new FieldComparatorSource() {
		@Override
		public FieldComparator<?> newComparator(String field, int hits, int sort, boolean reversed)
				throws IOException {
			return new FieldComparator.TermValComparator(hits, field, false) {
				@Override
				public int compareValues(BytesRef val1, BytesRef val2) {
					ByteBuffer bb1 = ByteBufferUtils.byteBuffer(val1);
					ByteBuffer bb2 = ByteBufferUtils.byteBuffer(val2);
					return ByteBufferUtil.compareUnsigned(bb1, bb2);
				}
			};
		}
	});
}
 
开发者ID:jmiddleton,项目名称:cassandra-fhir-index,代码行数:23,代码来源:PartitionMapper.java

示例12: searchByTag

import org.apache.lucene.search.SortField; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public List<PostPO> searchByTag(Paging paigng, String tag) {
	FullTextSession fullTextSession = Search.getFullTextSession(super.session());
    SearchFactory sf = fullTextSession.getSearchFactory();
    QueryBuilder qb = sf.buildQueryBuilder().forEntity(PostPO.class).get();
    org.apache.lucene.search.Query luceneQuery  = qb.phrase().onField("tags").sentence(tag).createQuery();

    FullTextQuery query = fullTextSession.createFullTextQuery(luceneQuery);
    query.setFirstResult(paigng.getFirstResult());
    query.setMaxResults(paigng.getMaxResults());

	Sort sort = new Sort(new SortField("id", SortField.Type.LONG, true));
	query.setSort(sort);
	
	paigng.setTotalCount(query.getResultSize());
	
	return query.list();
}
 
开发者ID:ThomasYangZi,项目名称:mblog,代码行数:20,代码来源:PostDaoImpl.java

示例13: getGroupByField

import org.apache.lucene.search.SortField; //导入依赖的package包/类
private String getGroupByField(List<VcfFile> files, String groupBy) throws IOException {
    IndexSortField sortField = IndexSortField.getByName(groupBy);
    if (sortField == null) {
        VcfFilterInfo info = vcfManager.getFiltersInfo(
                files.stream().map(BaseEntity::getId).collect(Collectors.toList()));

        InfoItem infoItem = info.getInfoItemMap().get(groupBy);
        Assert.notNull(infoItem, "Unknown sort field: " + groupBy);

        if (infoItem.getType() == VCFHeaderLineType.Integer || infoItem.getType() == VCFHeaderLineType.Float) {
            return FeatureIndexFields.getGroupName(infoItem.getName().toLowerCase());
        } else {
            return infoItem.getName().toLowerCase();
        }
    } else {
        if (sortField.getType() == SortField.Type.INT || sortField.getType() == SortField.Type.FLOAT) {
            return sortField.getField().getGroupName();
        } else {
            return sortField.getField().fieldName;
        }
    }
}
 
开发者ID:epam,项目名称:NGB,代码行数:23,代码来源:FeatureIndexDao.java

示例14: getStringSortField

import org.apache.lucene.search.SortField; //导入依赖的package包/类
/**
 * Comes from Sorting of Solr
 * 
 * Returns a {@link SortField} for a string field.
 *  If nullLast and nullFirst are both false, then default lucene string sorting is used where
 *  null strings sort first in an ascending sort, and last in a descending sort.
 *
 * @param fieldName   the name of the field to sort on
 * @param reverse     true for a reverse (desc) sort
 * @param nullLast    true if null should come last, regardless of sort order
 * @param nullFirst   true if null should come first, regardless of sort order
 * @return SortField
 */
public static SortField getStringSortField(String fieldName, boolean reverse, boolean nullLast, boolean nullFirst) {
	if (nullFirst && nullLast) {
		throw new IllegalArgumentException("Cannot specify missing values as both first and last");
	}

	SortField sortField = new SortField(fieldName, SortField.Type.STRING, reverse);

	// 4 cases:
	// missingFirst / forward: default lucene behavior
	// missingFirst / reverse: set sortMissingLast
	// missingLast / forward: set sortMissingLast
	// missingLast / reverse: default lucene behavior

	if (nullFirst && reverse) {
		sortField.setMissingValue(SortField.STRING_LAST);
	} else if (nullLast && !reverse) {
		sortField.setMissingValue(SortField.STRING_LAST);
	}

	return sortField;
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:35,代码来源:SortUtils.java

示例15: getLongSortField

import org.apache.lucene.search.SortField; //导入依赖的package包/类
public static SortField getLongSortField(String fieldName, boolean reverse, boolean nullLast, boolean nullFirst) {
	if (nullFirst && nullLast) {
		throw new IllegalArgumentException("Cannot specify missing values as both first and last");
	}

	SortField sortField = new SortField(fieldName, SortField.Type.LONG, reverse);

	// 4 cases:
	// missingFirst / forward: default lucene behavior
	// missingFirst / reverse: set sortMissingLast
	// missingLast / forward: set sortMissingLast
	// missingLast / reverse: default lucene behavior

	if (nullFirst && reverse) {
		sortField.setMissingValue(Long.MAX_VALUE);
	} else if (nullLast && !reverse) {
		sortField.setMissingValue(Long.MAX_VALUE);
	}

	return sortField;
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:22,代码来源:SortUtils.java


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