You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Michael <sa...@gmail.com> on 2014/09/30 15:02:29 UTC

How can I pass in query request parameter at search time and know of it in my query analyzer/tokenizer?

Hi all,

I'm using Solr 4.7.2 to implement multilingual search in my application.

I have a need to pass in query locale on search request and to choose
between custom tokenizers dynamically based on provided locale value.

In Solr In Action - Chapter 14 (Multilingual Search), Listing 14.9 -
*Indexing and querying multiple languages within the same field*
MultiFieldTextTokenizer allow specifying query language as a prefix to the
terms that goes into the analyzer. For example: q=en,fr,es|abandon AND
en,fr,es|understanding AND en,fr,es|sagess.

>From one side I have only one language per query, and from the other side I
allow users to use Lucene query syntax in queries including multi-term
queries. Therefore it seems that I have to do the nontrivial work of
parsing the user query according to the query parser rules and add the
prefix everywhere it's needed.
For example consider this user entered query: *one AND (two OR
field2:three)*
This will need to be non-trivially translated into:

*en:one AND (en:two OR field2:en|three). *
Is there other conventional way to pass in language string (one per search
request) to query analyzer/tokenizer ?

Thanks in advance,
Michael

Re: How can I pass in query request parameter at search time and know of it in my query analyzer/tokenizer?

Posted by Ilia Sretenskii <sr...@multivi.ru>.
You can implement your own kind of SeachHandler to pass your custom request
parameters to keep the common parameters clean.
http://svn.apache.org/repos/asf/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java

As you can see, the SearchHandler.handleRequestBody() method just takes
expected parameters from the SolrQueryRequest request.
Your own handler can expect more parameters than those defined in the
CommonParams interface.
https://svn.apache.org/repos/asf/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java

These are the base classes whose extensions might be useful for the
development.
http://svn.apache.org/repos/asf/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java
http://svn.apache.org/repos/asf/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/SearchComponent.java

You can find more information about the request handlers and the search
components in the guide.
https://cwiki.apache.org/confluence/display/solr/RequestHandlers+and+SearchComponents+in+SolrConfig