Return-Path: Delivered-To: apmail-lucene-solr-dev-archive@locus.apache.org Received: (qmail 61993 invoked from network); 22 Dec 2006 13:37:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Dec 2006 13:37:24 -0000 Received: (qmail 84206 invoked by uid 500); 22 Dec 2006 13:37:31 -0000 Delivered-To: apmail-lucene-solr-dev-archive@lucene.apache.org Received: (qmail 84172 invoked by uid 500); 22 Dec 2006 13:37:31 -0000 Mailing-List: contact solr-dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: solr-dev@lucene.apache.org Delivered-To: mailing list solr-dev@lucene.apache.org Received: (qmail 84084 invoked by uid 99); 22 Dec 2006 13:37:31 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Dec 2006 05:37:31 -0800 X-ASF-Spam-Status: No, hits=2.9 required=10.0 tests=HELO_DYNAMIC_SPLIT_IP,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of thorsten.scherler.ext@juntadeandalucia.es designates 217.12.18.114 as permitted sender) Received: from [217.12.18.114] (HELO 114.zone-217.12.18.juntadeandalucia.es) (217.12.18.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Dec 2006 05:37:21 -0800 Received: from [10.240.216.71] (helo=mail.juntadeandalucia.es) by guadix1.juntadeandalucia.es with esmtps (TLSv1:AES256-SHA:256) (Exim 4.60) (envelope-from ) id 1GxkZY-0004FM-Pg for solr-dev@lucene.apache.org; Fri, 22 Dec 2006 14:36:28 +0100 Received: from [10.240.216.71] (helo=[10.240.194.36]) by mail.juntadeandalucia.es with esmtpa (Exim 4.60) (envelope-from ) id 1GxkZp-0004HU-Jr for solr-dev@lucene.apache.org; Fri, 22 Dec 2006 14:36:45 +0100 Subject: Re: filter input from multiple fields From: Thorsten Scherler To: solr-dev@lucene.apache.org In-Reply-To: <1166790550.11122.27.camel@localhost> References: <1166790550.11122.27.camel@localhost> Content-Type: text/plain Date: Fri, 22 Dec 2006 14:37:02 +0100 Message-Id: <1166794622.15931.3.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Spam-Score: -1.4 (-) X-Virus-Checked: Checked by ClamAV on apache.org On Fri, 2006-12-22 at 13:29 +0100, Thorsten Scherler wrote: > Hi all, > > I am looking for some information about which is the best way to write a > MultipleFieldRequestHandler.java. I did a small hack and it works like a charm without the above mentioned handler. I only activated variable substitution for the FQ for testing if you think that is a nice feature I can activate it for the rest. Index: src/java/org/apache/solr/util/SolrPluginUtils.java =================================================================== --- src/java/org/apache/solr/util/SolrPluginUtils.java (revision 489649) +++ src/java/org/apache/solr/util/SolrPluginUtils.java (working copy) @@ -59,7 +59,10 @@ */ public class SolrPluginUtils { - /** + private static final String VARIABLE_DETERMINATOR_CLOSE = "}"; + private static final String VARIABLE_DETERMINATOR_OPEN = "${"; + +/** * Set defaults on a SolrQueryRequest. * * RequestHandlers can use this method to ensure their defaults are @@ -819,13 +822,24 @@ SolrQueryParser qp = new SolrQueryParser(s.getSchema(), null); for (String q : in) { if (null != q && 0 != q.trim().length()) { - out.add(qp.parse(q)); + out.add(qp.parse(substitute(q, req))); } } return out; } - /** + private static String substitute(String q, SolrQueryRequest req) { + if (q.contains(VARIABLE_DETERMINATOR_OPEN)){ + String beforeVariable =q.substring(0,q.indexOf(VARIABLE_DETERMINATOR_OPEN)) ; + String variable = q.substring(q.indexOf(VARIABLE_DETERMINATOR_OPEN)+VARIABLE_DETERMINATOR_OPEN.length(),q.indexOf(VARIABLE_DETERMINATOR_CLOSE)) ; + String afterVariable =q.substring(q.indexOf(VARIABLE_DETERMINATOR_CLOSE)+VARIABLE_DETERMINATOR_CLOSE.length()) ; + String variableValue= req.getParams().get(variable); + q = substitute(beforeVariable+variableValue+afterVariable, req); + } + return q; +} + +/** salu2 > > My use case is that I have a form (the next version of > http://andaluciajunta.es/portal/aj-bojaBuscador/0,22815,,00.html) where > you limit the query via a couple of different fields. > > Imaging I have a form like >
> > term: > >
> > > > > > > > > >
between dates:
> > y > >
>
> > Using the StandardRequestHandler without prior processing would result > that "startDate" and "endDate" would be ignored since they are not > within the query string and are not solr standard param that got > processed. > > Meaning I can either construct the query string (including this filter) > on the client side or with a request Handler, right? > > JavaScript on the client side is not a possibility for my client so here > I am to write my first RequestHandler. > > I could write a request handler special for my client, but I think a > more generic solution is more beneficial for all of us. > > So my idea is to define: > class="solr.MultipleFieldRequestHandler"> > > explicit > startDate endDate > * > * > date:[${startDate} TO ${endDate}] > > > > Where filterFields defines the array of fields that can be used to limit > the super set of docs. If this fields are null for the given request > then we use they defined standard e.g. * in > the fq. Within the fq ${...} has to be parsed with the actual value of > the variable. Since we defined default values that should work fine, > right? > > The only thing that a simpler more basic solution could be to just tweak > the standard handler to > a) get all params and store them in a hashmap (already done) > b) change SolrPluginUtils.parseFilterQueries to parse the fq string and > replace ${startDate} with the corresponding key="startDate" > req.getParam(key). General speaking implement a variable substitution > parser (which I would have to do as well for the MFRH). > > What do you think is the better approach write a RequestHandler or > extend the standard one or there even an easier way? > > TIA for any infos. > > salu2 >