Hello All,
IAM using hibernate search (Oracle +elastic search ) in my application , everything is working fine but sorting for I’d field and localdatetime field is not working along with pagination .please guide me on this it is very critical one in production .
Hello,
You’re going to have to give more details than this.
In particular:
- What is the code of your entities (annotations)
- What is the code of your query
- What do you expect as a result (give an example)
- What are you getting instead, that you consider "no working’. If there is an exception, give the full stack trace.
Hello Yrodiere,
Thanks for Your reply ,
Iam not getting any exception ,only thing which is wrong is documents are not coming in sorted manner when records are 9 , it provides me details in sorted manner like below
doc 9
doc 8
doc7
doc6
doc 5
doc 4
doc 3
doc 2
doc 1
This is perfect
But as I have kept window size or max results as 10 , when i am inserting 10th document , it is not showing like this
doc5
doc4
doc9
doc10
doc1
Bug type:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@SortableField
private int bugId;
Report type:
@Field( analyze = Analyze.NO,store = Store.YES)
@SortableField
@Column(name = “crash_date”, nullable = false)
private LocalDateTime crashDate;
Below is my java code for get query by crashDate for Report table
Sort sort = qb
.sort()
.byField(“crashDate”).desc()// Descending order
.createSort();
final FullTextQuery query = fullTextEntityManager
.createFullTextQuery(getFullTextQueryForReportDetails( reportDetailsRequest, qb ).createQuery(),Report.class)
.setProjection( “installationId”, “crashDate”,ANDROID_VERSION,ANDROID_SDK_VERSION,PHONE_MODEL,“stacktrace.stacktraceinfo”,VERSION_CODE,CATEGORY,“userName”,“userEmail”,REPORT_ID)
.setSort(sort)
.setFirstResult((reportDetailsRequest.getPageNo() - 1) * reportDetailsRequest.getWindowSize() )
.setMaxResults(reportDetailsRequest.getWindowSize())
.setResultTransformer(
new ResultTransformer() {
@Override
public Object transformTuple(Object[] tuple, String[] aliases) {
return new ReportDetailsView(
new ReportDetails( (String) tuple[0],(String) tuple[2],(String) tuple[3], (String) tuple[4], (String) tuple[7], (String) tuple[8], (String) tuple[9] ),
((LocalDateTime) tuple[1] )+offsetProperties.getOffset(),
(String) tuple[5],
(int) tuple[6],
(int)tuple[10]
);
}
@Override
public List transformList(List list) {
return list;
}
});
Below is my java code for get query by Id for bug table
Sort sort = qb
.sort()
.byField(“bugId”).desc()// Descending order
.createSort();
final FullTextQuery query =getFullTextQuery(bugDetailsRequest,fullTextEntityManager,qb)
.setSort(sort)
.setFirstResult((bugDetailsRequest.getPageNo() - 1) * bugDetailsRequest.getWindowSize() )
.setMaxResults(bugDetailsRequest.getWindowSize())
.setResultTransformer( new ResultTransformer() {
@Override
public Object transformTuple(Object[] tuples, String[] strings) {
return tuples[0];
}
@Override
public List transformList(List list) {
return list;
}
} );
return query.getResultList();
Let me know what is wrong in this
You should not sort directly on the document ID. The document ID is always stored as a string, which will lead to the behavior you’re experiencing.
Instead, create a separate, dedicated field for sorts.
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Field(name = "bugId_sort")
@SortableField(forField = "bugId_sort")
private int bugId;
Sort sort = qb
.sort()
.byField(“bugId_sort”).desc()// Descending order
.createSort();
Hi yrodiere,
thanks for your reply your solution worked like a charm , do i have to follow the same for the crash_date localdatetime field or it will be okay with @sortablefield only
For actual fields (not identifiers), just adding @SortableField(forField = ...)
should be enough.