Search code examples
solrlucenesolrj

Searching on solr with word having dot(.)


The words which ends with a . are giving me problem on solr. when i search for query l.l.* i get result as l.l.p , l.l.a etc... but i do not get result l.l.

i have set the analyzer as follows

   <field name="C" type="text_general" multiValued="false" indexed="true" stored="true">
   <analyzer>
   <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
   </analyzer>
   </field>

I want every word starting with words like l.l. and a exact match should also appear.


Solution

  • It is not clear in your question what query parser are you using, I assume edismax.

    So, the star character * used in query parser matches one or more characters.

    If you want match also 1.1. you should add OR clause:

    ("1.1." OR 1.1.*)
    

    in SolrJ you would translate it in:

    solrQuery.setQuery("(\"1.1.\" OR 1.1.*)");
    

    Another way you have is add a regular expression directly your Solr query.

    In your case is something like this:

    field:/1\.1\..*/
    

    in SolrJ you would translate it in:

    solrQuery.setQuery("field:/1\\.1\\..*/");
    

    Solr 4.0 added regular expression support, which means that '/' is now a special character and must be escaped if searching for literal forward slash.

    Have a look at SolrQuerySyntax and Solr Regex Query Tutorial