Thanks, Piete, Yes, that's how I imagine I would do it now. Only that on a second thought, I think i need to issue a second query for the faceting params, since the original query would be paginated (with start and row params); while for faceting, we should only append to the original query without the pagination params in order to get the correct faceting results. Right?
regards, -Hui On 8/8/07, Pieter Berkel <[EMAIL PROTECTED]> wrote: > > You could probably achieve this using faceting, however it would not be a > very efficient solution (although your multi-query idea isn't very > efficient > either). Since facets return result sets in field sort order if you > specify > facet.sort=false (setting that to try sorts the field by count), so you > could use query parameters like the following: > > > facet=true&facet.sort=false&facet.missing=false&facet.limit=-1&facet.mincount=1&facet.field=price&facet.field=publish_date > > And simply extract the first and last values of the facet which should > give > you the minumum and maximum values. > > I'm pretty certain there is currently no option to simply return the > minimum > / maximum facet values but it might be and idea for a future enhancement. > > cheers, > Piete > > > On 08/08/2007, Yu-Hui Jin <[EMAIL PROTECTED]> wrote: > > > > Piete, > > > > Thanks for the pointers and detailed info. Actually I'm aware of the > > faceting feature. Faceting provides the ability to categorize the > results > > with the count for each category. However,I don't think that solves my > > problem. > > > > Let me give a more detailed example for my requirement: > > > > Let's say we indexed 100 documents representing books with the following > > fields: > > > > (id, title, price, publish_date, description) > > > > Suppose a query "title:art history" ( We are using Solr 1.1, will use > > "sort" param when migrating to 1.2.) which returns 5 results: > > > > (25, "The History of Art", 56.0, 07-10-1995, "blah blah blah") > > (54, "Art History", 38.0, 02-13-1997, "blah blah blah") > > (13, "Art", 45.0, 10-05-1980, "blah blah blah") > > (3, "The Art of War", 40.0, 12-12-2000, "blah blah blah") > > (38, "History of Everything", 15.0, 12-31-2001, "blah blah blah") > > > > Now my requirement is that along with these five results, I also want > Solr > > to return the following: > > > > The [min, max] range for the 'price' field, in this case: [15.0, 56.0] > > The [min, max] range for the 'publish_date' field, in this case: > > [10-05-1980, 12-31-2001] > > > > I don't think faceting would give me these ranges, it can only give me > > counts of ranges/values, for example if I specified facet.query of > > different > > price ranges. > > > > So all I can think of now is that I have to > > 1) make 'price' and 'publish_date' sortable in the schema; > > 2) after each query (which returns non-empty result set), issue two more > > queries, one adding sort on 'price' to the original query, the other > > adding > > sort on 'publish_date'. (the sort order doesn't matter). > > 3) get the respective min, max values of these two fields from the first > > and > > last document returned for each of the two subsequent queries. > > > > Is there any better way to accomplish this? > > > > > > Thanks, > > > > -Hui > > > > > > > > On 8/7/07, Pieter Berkel <[EMAIL PROTECTED]> wrote: > > > > > > The functionality you are describing is called "Faceting" in Solr and > > can > > > be > > > achieved with a single query, take a look at the following wiki pages > > for > > > more info: > > > > > > http://wiki.apache.org/solr/SolrFacetingOverview > > > http://wiki.apache.org/solr/SimpleFacetParameters > > > > > > In regards to faceting date fields such as publish_date, take a look > at > > > https://issues.apache.org/jira/browse/SOLR-258 which was recently > > commited > > > to the svn trunk (although not much documentation on that yet). > > > > > > Just a note about your query, specifying the sort order in the q > > parameter > > > is depricated syntax, you are better to use the sort parameter for > that, > > > again refer to the wiki: > > > > > > http://wiki.apache.org/solr/CommonQueryParameters > > > > > > Hope this helps, > > > Piete > > > > > > > > > On 07/08/07, Yu-Hui Jin <[EMAIL PROTECTED]> wrote: > > > > > > > > Hi, there, > > > > > > > > We used Solr to index a set of documents and provide free-text > search > > > > functionality with sorting options on a number of fields. We have a > > > > requirement that along with each search result we want to obtain the > > > > ranges > > > > of a few fields for the resulting documents. Here's an example: > > > > > > > > Let's say we indexed documents representing books with the following > > > > fields: > > > > > > > > title, price, publish_date, description > > > > > > > > All of these fields are stored in the index (that can be returned); > > and > > > > "price" and "publish_date" are sortable as well. > > > > > > > > Now suppose we post a query for example "title:art history;price > asc", > > > we > > > > want to the following results: > > > > > > > > 1. the documents satisfying the query (which by default are returned > > by > > > > solr); > > > > 2. the range of the price field of the results. > > > > 3. the range of the publish_date of the results. > > > > > > > > My question is -- can solr return all of the above data within one > > > > response? If not, all I can think of is to issue one more query > that > > > > "title:art history;publish_date asc" (or desc) so that I can use the > > > first > > > > and last result of this query to get the range for > publish_date. (Due > > > to > > > > the original query already asking to sort by price, we are lucky in > > this > > > > case that we don't have to issue another query to get the range of > > > price. > > > > But then this does not apply in the general case.) > > > > > > > > Any idea is appreciated! > > > > > > > > -- > > > > Regards, > > > > > > > > -Hui > > > > > > > > > > > > > > > -- > > Regards, > > > > -Hui > > > -- Regards, -Hui