mirror of https://github.com/apache/lucene.git
additional examples of the switch parser inspired by a recent email thread
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1487166 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
02a14e43f6
commit
277c65f9b9
|
@ -82,6 +82,57 @@ import org.apache.commons.lang.StringUtils;
|
|||
* v=$shipping}</str>
|
||||
* </lst>
|
||||
* </requestHandler></pre>
|
||||
*
|
||||
* <p>
|
||||
* A slightly more interesting variant of the <code>shipping</code> example above, would be
|
||||
* to combine the switch parser with the frange parser, to allow the client to specify an
|
||||
* arbitrary "max shipping" amount that will be used to build a filter if and only if a
|
||||
* value is specified. Example:
|
||||
* </p>
|
||||
* <pre class="prettyprint">
|
||||
* <requestHandler name="/select" class="solr.SearchHandler">
|
||||
* <lst name="invariants">
|
||||
* <str name="shipping_fq">{!frange u=$shipping}shipping_cost</str>
|
||||
* </lst>
|
||||
* <lst name="defaults">
|
||||
* <str name="shipping">any</str>
|
||||
* </lst>
|
||||
* <lst name="appends">
|
||||
* <str name="fq">{!switch case='*:*'
|
||||
* case.any='*:*'
|
||||
* default=$shipping_fq
|
||||
* v=$shipping}</str>
|
||||
* </lst>
|
||||
* </requestHandler></pre>
|
||||
*
|
||||
* <p>
|
||||
* With the above configuration a client that specifies <code>shipping=any</code>, or
|
||||
* does not specify a <code>shipping</code> param at all, will not have the results
|
||||
* filtered. But if a client specifies a numeric value (ie: <code>shipping=10</code>,
|
||||
* <code>shipping=5</code>, etc..) then the results will be limited to documents whose
|
||||
* <code>shipping_cost</code> field has a value less then that number.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* A similar use case would be to combine the switch parser with the bbox parser to
|
||||
* support an optional geographic filter that is applied if and only if the client
|
||||
* specifies a <code>location</code> param containing a lat,lon pair to be used as
|
||||
* the center of the bounding box:
|
||||
* </p>
|
||||
* <pre class="prettyprint">
|
||||
* <requestHandler name="/select" class="solr.SearchHandler">
|
||||
* <lst name="invariants">
|
||||
* <str name="bbox_fq">{!bbox pt=$location sfield=geo d=$dist}</str>
|
||||
* </lst>
|
||||
* <lst name="defaults">
|
||||
* <str name="dist">100</str>
|
||||
* </lst>
|
||||
* <lst name="appends">
|
||||
* <str name="fq">{!switch case='*:*'
|
||||
* default=$bbox_fq
|
||||
* v=$location}</str>
|
||||
* </lst>
|
||||
* </requestHandler></pre>
|
||||
*/
|
||||
public class SwitchQParserPlugin extends QParserPlugin {
|
||||
public static String NAME = "switch";
|
||||
|
|
Loading…
Reference in New Issue