0

According to the documentation, Zend Lucene is supposed to sort lexicographically. I am finding this is not the case. If I have a query 'avg:[050 TO 300]', yes it will return all values in that range, but it will sort them according to the document id, not the value.

I have found that the find() function can accept additional parameters, allowing me to sort by a specific column (eg $hits = $index->find($query, 'avg', SORT_NUMERIC, SORT_ASC);). However, I am creating $query dynamically and do not want to sort every search by 'avg'.

How do I force Lucene to sort the results automatically, lexicographically, when I do a range search? And if that's not possible, how do I dynamically add a sort field to the find function?

Charles
  • 50,943
  • 13
  • 104
  • 142
Richard Parnaby-King
  • 14,703
  • 11
  • 69
  • 129

1 Answers1

1

Why don't you sort $hits by yourself after getting the result from $index->find(...)? Ok this looks like a workaround and will be time-consuming for very large resultsets, but I guess that this is the easiest way in most cases.

derphil
  • 385
  • 6
  • 25
  • As I'm only sorting for a select number of queries, I set a flag whenever I do THOSE queries and when it comes to finding I do an if/else to find with/without sort. (eg: `if($flag){$hits = $index->find($query, 'avg', SORT_NUMERIC, SORT_ASC);}else{$hits = $index->find($query);}`) – Richard Parnaby-King Feb 28 '11 at 09:57