Getting multi-values to use in filter?

2014-04-23 Thread Rob Audenaerde
Hi all, I'm looking for a way to use multi-values in a filter. I want to be able to search on sum(field)=100, where field has values in one documents: field=60 field=40 In this case 'field' is a LongField. I examined the code in the FieldCache, but that seems to focus on single-valued fields o

Re: Getting multi-values to use in filter?

2014-04-23 Thread Michael Sokolov
This isn't really a good use case for an index like Lucene. The most essential property of an index is that it lets you look up documents very quickly based on *precomputed* values. -Mike On 04/23/2014 06:56 AM, Rob Audenaerde wrote: Hi all, I'm looking for a way to use multi-values in a f

Re: Getting multi-values to use in filter?

2014-04-23 Thread Rob Audenaerde
Hi Mike, Thanks for your reply. I think it is not-so-much an invalid use case for Lucene. Lucene already has (experimental) support for Dynamic Range Facets, expressions (javascript expressions, geospatial haversin etc. etc). There are all computed on the fly; and work really well. They just depe

Re: Getting multi-values to use in filter?

2014-04-23 Thread Shai Erera
You can do that by writing a Filter which returns matching documents based on a sum of the field's value. However I suspect that is going to be slow, unless you know that you will need several such filters and can cache them. Another approach would be to write a Collector which serves as a Filter,

Re: Getting multi-values to use in filter?

2014-04-23 Thread Rob Audenaerde
Hi Shai, all, I am trying to write that Filter :). But I'm a bit at loss as how to efficiently grab the multi-values. I can access the context.reader().document() that accesses the storedfields, but that seems slow. For single-value fields I use a compiled JavaScript Expression with simplebinding

Re: Getting multi-values to use in filter?

2014-04-23 Thread Shai Erera
A NumericDocValues field can only hold one value. Have you thought about encoding the values in a BinaryDocValues field? Or are you talking about multiple fields (different names), each has its own single value, and at search time you sum the values from a different set of fields? If it's one fiel

Re: Getting multi-values to use in filter?

2014-04-23 Thread Rob Audenaerde
Thanks for all the questions, gives me an opportunity to clarify it :) I want the user to be able to give a (simple) formula (so I don't know it on beforehand) and use that formula in the search. The Javascript expressions are really powerful in this use case, but have the single-value limitation.

Re: Getting multi-values to use in filter?

2014-04-24 Thread Shai Erera
I don't think that you should use the facet module. If all you want is to encode a bunch of numbers under a 'foo' field, you can encode them into a byte[] and index them as a BDV. Then at search time you get the BDV and decode the numbers back. The facet module adds complexity here: yes, you get th

Re: Getting multi-values to use in filter?

2014-04-27 Thread Shai Erera
Hi Rob, Your question got me interested, so I wrote a quick prototype of what I think solves your problem (and if not, I hope it solves someone else's! :)). The idea is to write a special ValueSource, e.g. MaxValueSource which reads a BinadyDocValues, decodes the values and returns the maximum one

Re: Getting multi-values to use in filter?

2014-04-29 Thread Rob Audenaerde
Hi Shai, I read the article on your blog, thanks for it! It seems to be a natural fit to do multi-values like this, and it is helpful indeed. For my specific problem, I have multiple values that do not have a fixed number, so it can be either 0 or 10 values. I think the best way to solve this i

Re: Getting multi-values to use in filter?

2014-04-29 Thread Shai Erera
Hi Rob, While the demo code uses a fixed number of 3 values, you don't need to encode the number of values up front. Since your read the byte[] of a document up front, you can read in a while loop as long as in.position() < in.length(). Shai On Tue, Apr 29, 2014 at 10:04 AM, Rob Audenaerde wrot