Hi, Oh, how I wish it was as simple as that! :-) The tricky ingredient in the use case is to exclude all documents (from any 'saledate') if there's a "recent" 'product' match (e.g. last month). So, essentially you have to somehow build a query that looks at 2 different criteria for the same field ('saledate'). This requires the criteria to be applied at the DocSet level, rather than on each Document (or, do them sequentially like in SOLR-2026).
I've been having a look at Karl's SOLR-2026, which looks very interesting, but I've not got it working on trunk as yet. The only other way I can see is to do multiple client-side round-trip queries - using the results of the initial search as a filter for the second. It's a bit messy, and not a performance winner (esp w/ distributed searches on large indexes), so hopefully a server-side solution is out there. Thanks! Peter On Fri, Mar 4, 2011 at 2:14 PM, Savvas-Andreas Moysidis < savvas.andreas.moysi...@googlemail.com> wrote: > Can you not calculate on the fly when the date which is one month before > the > current is and use that as your upper limit? > > e.g. taking today as an example your upper limit would be > 20011-02-04T00:00:00Z > and so your query would be something like: > q=products:Dog AND saledate:[* TO 20011-02-04T00:00:00Z] > > > On 4 March 2011 11:40, Peter Sturge <peter.stu...@gmail.com> wrote: > > > Hello, > > > > I've been wrestling with a query use case, perhaps someone has done this > > already? > > Is it possible to write a query that excludes results based on another > > query? > > > > Scenario: > > I have an index that holds: > > 'customer' (textgen) > > 'product' (textgen) > > 'saledate' (date) > > > > I'm looking to return documents for 'customer' entries who have bought a > > 'product' in the past, but haven't bought in, say, the last month. > > (i.e. need to exclude *all* 'customer' documents who have bought > 'product' > > in the last month, as well as those who have never bought 'product') > > > > A very simple query like this: > > q=products:Dog AND -(products:Dog AND saledate:[2011-01-01T00:00:00Z > TO > > *]) > > returns 'Dog' documents prior to 1 Jan, but these need to be excluded if > > there are matches after 1 Jan. > > I wasn't expecting the above query to do the extra exclusion - it's just > to > > illustrate the general problem that it operates at document level, not > > query > > level (like a SQL subquery). > > If I could could pipe the results of the above to another query, that > would > > likely do the trick. > > I've tried negative boosts, magic _query_, query() and such, but with no > > luck. > > > > Is this possible? > > Any insight into how to write such a query would be much appreciated! > > > > Thanks, > > Peter > > >