You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2013/05/29 01:42:48 UTC

svn commit: r1487166 - /lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SwitchQParserPlugin.java

Author: hossman
Date: Tue May 28 23:42:48 2013
New Revision: 1487166

URL: http://svn.apache.org/r1487166
Log:
additional examples of the switch parser inspired by a recent email thread

Modified:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SwitchQParserPlugin.java

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SwitchQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SwitchQParserPlugin.java?rev=1487166&r1=1487165&r2=1487166&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SwitchQParserPlugin.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SwitchQParserPlugin.java Tue May 28 23:42:48 2013
@@ -82,6 +82,57 @@ import org.apache.commons.lang.StringUti
  *                             v=$shipping}</str>
  *   </lst>
  * &lt;/requestHandler&gt;</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">
+ * &lt;requestHandler name="/select" class="solr.SearchHandler"&gt;
+ *   &lt;lst name="invariants"&gt;
+ *     &lt;str name="shipping_fq"&gt;{!frange u=$shipping}shipping_cost&lt;/str&gt;
+ *   &lt;/lst&gt;
+ *   &lt;lst name="defaults"&gt;
+ *     &lt;str name="shipping"&gt;any&lt;/str&gt;
+ *   &lt;/lst&gt;
+ *   &lt;lst name="appends"&gt;
+ *     &lt;str name="fq"&gt;{!switch case='*:*'
+ *                             case.any='*:*'
+ *                             default=$shipping_fq
+ *                             v=$shipping}&lt;/str&gt;
+ *   &lt;/lst&gt;
+ * &lt;/requestHandler&gt;</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">
+ * &lt;requestHandler name="/select" class="solr.SearchHandler"&gt;
+ *   &lt;lst name="invariants"&gt;
+ *     &lt;str name="bbox_fq"&gt;{!bbox pt=$location sfield=geo d=$dist}&lt;/str&gt;
+ *   &lt;/lst&gt;
+ *   &lt;lst name="defaults"&gt;
+ *     &lt;str name="dist"&gt;100&lt;/str&gt;
+ *   &lt;/lst&gt;
+ *   &lt;lst name="appends"&gt;
+ *     &lt;str name="fq"&gt;{!switch case='*:*' 
+ *                             default=$bbox_fq 
+ *                             v=$location}&lt;/str&gt;
+ *   &lt;/lst&gt;
+ * &lt;/requestHandler&gt;</pre>
  */
 public class SwitchQParserPlugin extends QParserPlugin {
   public static String NAME = "switch";