Quantcast

Reverse range query

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Reverse range query

kenf_nc
This post was updated on .
I have data in a document where there is a defined minimum value and maximum value. I need to let a user query with a single value and I match the document if that value falls withing the minimum and maximum. So, kind of the opposite of a normal range query where the user does price:[x TO y].

For example:
Document 1:
field  product:flat screen computer monitor
field  min_price:100
field  max_price:500

Document 2:
field  product:flat screen television
field  min_price:300
field  max_price:500

The user enters a price of $250. I want to match Document 1 only, because $250 falls withing it's range.

I could create a query of (min_price:[* TO 250] AND max_price:[250 TO *]) and that should work.  However, if I have several fields like this and complex queries that include most of those fields, it becomes a very ugly query. Ideally I'd like to do something similar to what is done with the spatial values latitude and longitude. I believe the spatial add-ons to Solr treat it like a Point. If I had a min/max field, I could index it price(100, 500) or price(300,500) and just do a query of  price:250 and Solr would see if 250 was in the appropriate range.

Is there something out there already that does this? Does anyone else do something like this and have some suggestions?
Thanks,
Ken
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reverse range query

kenf_nc
I modified the text of this hopefully to make it clearer. I wasn't sure what I was asking was coming across well. And I'm adding this comment in a shameless attempt to boost my question back to the top for people to see. Before I write a messy work around, just wanted to check the community to see if this was already handled, it seems like a useful, common, data type.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reverse range search

Erick Erickson
In reply to this post by kenf_nc
I wonder if function queries might help you here (be aware that these aren't
my strong point though). See:
http://wiki.apache.org/solr/FunctionQuery

<http://wiki.apache.org/solr/FunctionQuery>Best
Erick

On Thu, Oct 28, 2010 at 5:24 PM, kenf_nc <[hidden email]> wrote:

>
> Doing a range search is straightforward. I have a fixed value in a document
> field, I search on [x TO y] and if the fixed value is in the range
> requested
> it gets a hit. But, what if I have data in a document where there is a min
> value and a max value and my query is a fixed value and I want to get a hit
> if the query value is in that range. For example:
>
> Solr Doc1:
> field  min_price:100
> field  max_price:500
>
> Solr Doc2:
> field  min_price:300
> field  max_price:500
>
> and my query is price:250. I could create a query of (min_price:[* TO 250]
> AND max_price:[250 TO *]) and that should work. It should find only doc 1.
> However, if I have several fields like this and complex queries that
> include
> most of those fields, it becomes a very ugly query. Ideally I'd like to do
> something similar to what the spatial contrib guys do where they make
> lat/long a single point. If I had a min/max field, I could call it Price
> (100, 500) or Price (300,500) and just do a query of  Price:250 and Solr
> would see if 250 was in the appropriate range.
>
> Looong question short...Is there something out there already that does
> this?
> Does anyone else do something like this and have some suggestions?
> Thanks,
> Ken
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Reverse-range-search-tp1789135p1789135.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reverse range search

Jan Høydahl / Cominvent
In reply to this post by kenf_nc
Hi,

I think I have seen a comment on the list from someone with the same need a few months ago.
He planned to make a new fieldType to support this, e.g. MinMaxRangeFieldType which would
be a polyField type holding both a min and max value, and then you could query it
q=myminmaxfield:123

I did not find it as a Jira issue however, but I can see how it would be useful for a lot of usecases. Perhaps you can create a Jira issue for it and supply a patch? :)

--
Jan Høydahl, search solution architect
Cominvent AS - www.cominvent.com

On 28. okt. 2010, at 23.24, kenf_nc wrote:

>
> Doing a range search is straightforward. I have a fixed value in a document
> field, I search on [x TO y] and if the fixed value is in the range requested
> it gets a hit. But, what if I have data in a document where there is a min
> value and a max value and my query is a fixed value and I want to get a hit
> if the query value is in that range. For example:
>
> Solr Doc1:
> field  min_price:100
> field  max_price:500
>
> Solr Doc2:
> field  min_price:300
> field  max_price:500
>
> and my query is price:250. I could create a query of (min_price:[* TO 250]
> AND max_price:[250 TO *]) and that should work. It should find only doc 1.
> However, if I have several fields like this and complex queries that include
> most of those fields, it becomes a very ugly query. Ideally I'd like to do
> something similar to what the spatial contrib guys do where they make
> lat/long a single point. If I had a min/max field, I could call it Price
> (100, 500) or Price (300,500) and just do a query of  Price:250 and Solr
> would see if 250 was in the appropriate range.
>
> Looong question short...Is there something out there already that does this?
> Does anyone else do something like this and have some suggestions?
> Thanks,
> Ken
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Reverse-range-search-tp1789135p1789135.html
> Sent from the Solr - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reverse range query

brian519
In reply to this post by kenf_nc
This post helped me solve my problem which I had posted on StackOverflow.  See my answer here:
http://stackoverflow.com/questions/8070742/solr-multivalued-field-how-can-i-return-documents-where-all-values-in-the-fiel

Would be great to see a feature in Solr for a "reverse query".  Ie, the value in your solr document is queried against your "query input", which would make problems like this a breeze.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reverse range query

ballusethuraman
Hi,
I have craeted new attribute(Year) in attribute dictionary and associated with different catentries with different values say 2000,2001,2002,2003,...2012.
Now I want to search with the Year attribute with min and max range. when 2000 to 2005 is given as search condition it should fetch the catentries which is between these two values.
This is the url I used to hit the solr server.
ads_f11001 is the logical name of the attribute "year" that i have created in management center. This value will be in "srchattrprop" table. 2000 and 2005 is min and max range.
http://localhost/solr/MC_10701_CatalogEntry_en_US/select?q=ads_f11001:{2000 2005}

when i try to hit this url i am getting 0 records found.
http://localhost/solr/MC_10701_CatalogEntry_en_US/select?q=ads_f11001:{2000 TO *}

and

http://localhost/solr/MC_10701_CatalogEntry_en_US/select?q=ads_f11001:{* TO 2005}

These above two urls ferching me some result but it s not the expected result. Plz help me to solve this issue.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reverse range query

Erick Erickson
Well, what does adding &debug=query show you for the parsed query? What
documents show up?

My first guess is that since you're using exclusive rather than inclusive
end points you're expectations aren't what you think.

Best
Erick


On Mon, Feb 11, 2013 at 10:57 PM, ballusethuraman <[hidden email]
> wrote:

> Hi,
> I have craeted new attribute(Year) in attribute dictionary and associated
> with different catentries with different values say
> 2000,2001,2002,2003,...2012.
> Now I want to search with the Year attribute with min and max range. when
> 2000 to 2005 is given as search condition it should fetch the catentries
> which is between these two values.
> This is the url I used to hit the solr server.
> ads_f11001 is the logical name of the attribute "year" that i have created
> in management center. This value will be in "srchattrprop" table. 2000 and
> 2005 is min and max range.
> http://localhost/solr/MC_10701_CatalogEntry_en_US/select?q=ads_f11001:{2000
> 2005}
>
> when i try to hit this url i am getting 0 records found.
> http://localhost/solr/MC_10701_CatalogEntry_en_US/select?q=ads_f11001:{2000
> TO *}
>
> and
>
> http://localhost/solr/MC_10701_CatalogEntry_en_US/select?q=ads_f11001:{*TO
> 2005}
>
> These above two urls ferching me some result but it s not the expected
> result. Plz help me to solve this issue.
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Reverse-range-query-tp1789135p4039860.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
Loading...