Sorting search result in Lucene based on a numeric field

前端 未结 3 922
粉色の甜心
粉色の甜心 2020-12-15 10:53

I have some docs with two fields: text, count.

I\'ve used Lucene to index docs and now I want to search in text and get the result sorted by count in de

3条回答
  •  余生分开走
    2020-12-15 11:50

    first:

    Fieldable count = new NumericField("count", Store.YES, true);
    

    second:

    SortField field = new SortField("count", SortField.INT);
    Sort sort = new Sort(field);
    

    third:

    TopFieldDocs docs = searcher.search(query, 20, sort);
    ScoreDoc[] sds = docs.scoreDocs;
    

    Like this is OK !

提交回复
热议问题