I have a problem and I've been struggling for several days now. I just don't understand why Hibernate Search works fast enough for one query, but slow for another. I've read a lot of related posts on stackoverflow, hibernate search documentation, etc, but I can't find what's wrong.
I'm using the latest version of Hibernate Search (5.5.2.Final), and the latest versions of Hibernate ORM and PostgreSQL.
I'm only going to copy the important code (the one where you can see the changes between the queries), everything else is exactly the same (it's the same code, in the same function, ...)
if(latitude != null && longitude != null){
//Distance sort works very fast, no problems here
Sort distanceSort = new Sort(
new DistanceSortField(latitude,
longitude,
"location"));
jpaQuery.setSort(distanceSort);
} else {
//THIS IS SLOW, i have no idea why
Sort valueSort = new Sort(
new SortField("documentValue", SortField.Type.DOUBLE, true)); //reverse, highest values first
jpaQuery.setSort(valueSort);
}
Those fields are defined in the Business.java file (important code follows).
@Spatial(spatialMode = SpatialMode.HASH)
@Transient
public Coordinates getLocation() {
.... //latitude and longitude coordinates are stored in DB
}
@Field
@NumericField
@SortableField
public Double getDocumentValue() {
return documentValue; //this number is stored in DB
}
I have around 10 000 000 records. The distance sort query takes < 1 second, the documentValue (a numeric field, even marked as a SortableField) sort query takes > 30 seconds.
Thank you.