1
votes

I have an implementation of the Zend Search (Lucene) framework on my website that contains an index of products with prices.

I am trying to allow customers to search for something, while contsraining the prices. Eg. Search for "dog food" between $5-$10 dollars.

My search index looks like this:
Keyword('name')
Keyword('price')

Lets say there's 2 items in the database (name and price)
'dog food' 10
'dot treats' 11

If I do the following search, I receive both results.
price[1 TO 15] name:dog
This is exactly what I want.

However, If I change the range to price[5 TO 15] I get no results back. Can anyone help me understand how to debug this? This behaviour occurs both in my web implementation, and in Luke.

1

1 Answers

2
votes

Here's the deal: These values in Lucene are represented as strings, and are sorted lexicographically. Therefore, you need to pad them with zeros. Say the maximal price is 999 dollars, you need to insert each price as a three-digit string: 001, 005, 015 etc. Then, your query will be:

price:[005 TO 015] name:dog

Which should work.