Range queries in phrases/spans?

Hi –

I’m developing a system that lets users associate arbitrary [key,
numeric value] pairs (among other forms of data) with “documents”.
Question: is there any reasonable way to get Ferret to index and do
range queries over such beasts?

Since the keys are arbitrary and there are potentially more of them than
there are documents, I’d assume that adding a specific “field” to Ferret
for each key isn’t going to work. Therefore, it seems like I’d need to
somehow encode all the [key, numeric value] pairs for a given document
inside, say, a single “numeric attributes” field. But then I’m not sure
how I’d form a query to search for a specific range of values for a
specific key. I don’t see any way to construct a phrase query that
says, for example, “the word ‘weight’ followed immediately by a number
between 160 and 180”…range queries don’t seem to be allowed as
components of a phrase (or span) query. Meanwhile, boolean queries
obviously have problems with false positives coming up where the right
key is present but it’s actually some other [key, value] pair that’s
providing the value in the right numeric range. (I suppose it’s
possible I could post-process the results with a filter of some sort to
weed out the false positives, but that seems just a wee bit hacky and
potentially very inefficient.)

Is there actually no way in Ferret to construct a query that will work
properly here, or am I missing something?

(Yes, I could try encoding the key and the numeric value in a single
token and use a range query like (:lower=>“weight_160”,
:upper=>“weight_180”), but that would cause problems with multi-word
keys (e.g. “my weight”) that the user might want to be able to find with
only some subset of the key’s words (e.g. “weight”). And yes, I’m aware
that there are tricks involved in indexing numeric values so that they
work properly in range queries, but I have that part figured out, so no
worries there…)

Thanks,

– Scott