Example usage for org.apache.lucene.search SortedNumericSortField SortedNumericSortField

List of usage examples for org.apache.lucene.search SortedNumericSortField SortedNumericSortField

Introduction

In this page you can find the example usage for org.apache.lucene.search SortedNumericSortField SortedNumericSortField.

Prototype

public SortedNumericSortField(String field, SortField.Type type) 

Source Link

Document

Creates a sort, by the minimum value in the set for the document.

Usage

From source file:ntu.searchengine.Searcher.java

public ArrayList<SearchResultModel> search(String queryString) throws ParseException, IOException {
    parser.prepare(queryString);//from  w w  w. j  a  va  2 s  .co  m
    Query query = parser.parse(queryString);
    TopDocs hits = null;
    if (Main.sortResultByDocId) { //If we sort the documents the score field will be NaN
        //Sort by doc number
        final Sort sort = new Sort(new SortedNumericSortField(FieldConstants.DOCNAME, SortField.Type.INT));
        hits = is.search(query, Main.topNResult, sort);
    } else {
        hits = is.search(query, Main.topNResult);
    }

    System.out.println("Result for query: " + queryString);
    ArrayList<SearchResultModel> result = getResult(hits, query);
    return ScoringFiltering.filterScores(result);
}

From source file:org.elasticsearch.search.searchafter.SearchAfterBuilderTests.java

License:Apache License

public void testExtractSortType() throws Exception {
    SortField.Type type = extractSortType(LatLonDocValuesField.newDistanceSort("field", 0.0, 180.0));
    assertThat(type, equalTo(SortField.Type.DOUBLE));
    IndexFieldData.XFieldComparatorSource source = new IndexFieldData.XFieldComparatorSource(null,
            MultiValueMode.MIN, null) {//  www.j a v  a 2  s. c  o  m
        @Override
        public SortField.Type reducedType() {
            return SortField.Type.STRING;
        }

        @Override
        public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) {
            return null;
        }
    };

    type = extractSortType(new SortField("field", source));
    assertThat(type, equalTo(SortField.Type.STRING));

    type = extractSortType(new SortedNumericSortField("field", SortField.Type.DOUBLE));
    assertThat(type, equalTo(SortField.Type.DOUBLE));

    type = extractSortType(new SortedSetSortField("field", false));
    assertThat(type, equalTo(SortField.Type.STRING));
}

From source file:org.hibernate.search.demos.tweets.ServiceImpl.java

License:LGPL

/**
 * To search for all tweets, sorted in creation order (assuming the timestamp is correct).
 * @return//from  w w w . ja  v  a 2  s .  co m
 */
public FullTextQuery allTweetsSortedByTime() {
    Query query = getQueryBuilder().all().createQuery();
    FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(query);
    fullTextQuery.setSort(new Sort(new SortedNumericSortField("timestamp", SortField.Type.LONG)));
    return fullTextQuery;
}