: I've created a custom ValueSourceParser and ValueSource that retrieve the : availability information from a MySQL database. An example query is as : follows. : : http://localhost:8983/solr/collection1/select?q=restaurant_id:*&fl=*,available:availability(2013-05-23, : 2, 1700, 2359) : : This results in a psuedo (boolean) field "available" per document result and : this works as expected. But my problem is that I also need the total number : of available restaurants.
1) "restaurant_id:*" is not doing what you think it is doing, use "*:*" or add an "is_restaurant" boolean field and query on that instead and you will probably discover that your queries for all are docs (or all restaurants) get much much faster. 2) if you've already built a custom ValueSourceParser that you're really happy with, and you just want to filter your Solr results based on the output of that custom ValueSource, you can do so by leveraging the frange QParser. If your custom value source returns a boolean, then you just have to me a bit tricky with the function range you ask for... fq={!frange cache=false cost=1000 l=1}if(availability(2013-05-23,2,1700,2359),5,0) A few things to note in this example: a) i'm using the if() function to map true to "5" (arbitray) and false to "0" (also arbitrary) and then filtering to only match documents whose value is "1" (arbitrary) or higher ... you can pick any values you want b) unlike using your custom value source in the "fl" when used in an fq, your ValueSouce function will be called for a *lot* of documents -- so you probably ant to batch request the availability when the ValueSourceParser is called, for fast lookup on each individual document. c) i've specified cache=false and a high cost param on the frange to ensure that the custom ValueSource is only ever asked about the availability of documents that already match our main query and any other filter queries. 3) if you don't want to filter or otherwise modify the result set by the results of your custom ValueSource, you just need the count of available documents matching your main query (independent of the numFound count of docs matching your main query), you can use the same technique in a "facet.query". -Hoss