我在Lucene 5.0中对字符串字段进行排序时遇到问题.自Lucene 4改变以来你可以选择的方式.下面显示了我的文档索引的一些字段的片段.
@Override
public Document generateDocument(Process entity)
{
Document doc = new Document();
doc.add(new IntField(id, entity.getID(), Field.Store.YES));
doc.add(new TextField(title, entity.getProcessName(), Field.Store.YES));
doc.add(new IntField(organizationID, entity.getOrganizationID(), Field.Store.YES));
doc.add(new StringField(versionDate, DateTools.dateToString(entity.getVersionDate(), DateTools.Resolution.SECOND), Field.Store.YES));
doc.add(new LongField(entityDate, entity.getVersionDate().getTime(), Field.Store.YES));
return doc;
}
Run Code Online (Sandbox Code Playgroud)
我想首先考虑相关性,这很好.我遇到的问题是在标题字段上排序不起作用.我创建了一个sortfield,我试图在一系列方法调用之后使用TopFieldCollector.
public BaseSearchCore<Process, ProcessSearchResultScore>.SearchContainer search(String searchQuery, Filter filter, int page, int hitsPerPage) throws IOException, ParseException
{
SortField titleSort = new SortField(title, SortField.Type.STRING, true);
return super.search(searchQuery, filter, page, hitsPerPage, title);
}
Run Code Online (Sandbox Code Playgroud)
其中:
public SearchContainer search(String searchQuery, Filter filter, int page, int hitsPerPage, SortField... …Run Code Online (Sandbox Code Playgroud)