sorry if this is a very simple question, but I am stuck (and online searches
for this info havent been fruitful).

Lets say that, in certain circumstances, I want to change the field names
and/or field query values being passed to SOLR.

For example, lets say my unmodified query is
"http://localhost:8994/solr/select?q=xxx:[* TO 3] AND yyy:[3 TO
*]&defType=myQParser" and (JUST for the sake of argument) lets say I want to
rewrite it as "http://localhost:8994/solr/select?q=aaa:[1 TO 2] AND bbb:[3
TO 10]&defType=myQParser". 

I think I can do it by extending QParserPlugin, and overriding the
createParser method (see my code snippet below). The qstr parameter contains
the parts I want to examine and/or modify.

now to my questions:
1. is that the correct location to do this?
2. is there an existing method for parsing out the fields and their
parameters? i.e. to break a qstr of "xxx:[* TO 3] AND yyy:[3 TO *]" into an
array something like  x[0][0] = "xxx", x[0][1]="1 TO 3", x[1][0] = "xxx",
x[1][1]="3 TO *".  Or possibly even finer than that.  I could write it
myself but its nicer not to have to.=^D

thanks in advance for any help.
--------------------------------------------------------
package com.topproducer.rentals.solr.search;

import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.Query;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.QParser;
import org.apache.solr.search.QParserPlugin;

public class myQParserPlugin extends QParserPlugin {

        @Override
        public QParser createParser(String qstr, SolrParams localParams, 
SolrParams
params, SolrQueryRequest req) 
        {
                return new QParser(qstr, localParams, params, req) {
                  QParser baseParser;

                  public Query parse() throws ParseException {
                        StringBuilder queryBuilder = new StringBuilder();

                        // extract and/or view and/or change qstr content here
                        // ..
                        // is there an existing function/method to parse qstr 
into its component
parts?
                        // i.e. to break "?q=xxx:[1 TO 3] AND yyy:[3 TO *]" 
into something like:
                        // x[0][0] = "xxx", x[0][1]="1 TO 3"
                        // x[1][0] = "xxx", x[1][1]="3 TO *"

                        // after modifying qstr, store it into queryBuilder here
                        queryBuild.append(new_qstr);


                        // prepare queryBuilder for any additional solr handling
                        baseParser = subQuery(queryBuilder.toString(), null);
                        Query q = baseParser.parse();
                        return q;
                  }


                  public String[] getDefaultHighlightFields() {
                        return baseParser.getDefaultHighlightFields();
                  }
                                                                                
           
                  public Query getHighlightQuery() throws ParseException {
                        return baseParser.getHighlightQuery();
                  }

                  public void addDebugInfo(NamedList debugInfo) {
                        baseParser.addDebugInfo(debugInfo);
                  }
                };
          }

        @Override
        public void init(NamedList arg0) {
                
                // TODO Auto-generated method stub
                
        }
}

-- 
View this message in context: 
http://www.nabble.com/examining-modifying-qstr-in-QParserPlugin-tp25722065p25722065.html
Sent from the Solr - Dev mailing list archive at Nabble.com.

Reply via email to