diff --git a/solr/core/src/java/org/apache/solr/search/SwitchQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/SwitchQParserPlugin.java index 0056c2c01c6..7ef66801f4b 100644 --- a/solr/core/src/java/org/apache/solr/search/SwitchQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/SwitchQParserPlugin.java @@ -82,6 +82,57 @@ import org.apache.commons.lang.StringUtils; * v=$shipping}</str> * </lst> * </requestHandler> + * + *

+ * A slightly more interesting variant of the shipping 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: + *

+ *
+ * <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>
+ * + *

+ * With the above configuration a client that specifies shipping=any, or + * does not specify a shipping param at all, will not have the results + * filtered. But if a client specifies a numeric value (ie: shipping=10, + * shipping=5, etc..) then the results will be limited to documents whose + * shipping_cost field has a value less then that number. + *

+ * + *

+ * 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 location param containing a lat,lon pair to be used as + * the center of the bounding box: + *

+ *
+ * <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>
*/ public class SwitchQParserPlugin extends QParserPlugin { public static String NAME = "switch";