Solr queryparser for lucene indices?

781 Views Asked by At

I've created an index (using Lucene 2.9) which stores text messages. (the documents also contain some other meta data which are not indexed, just stored) I use the StandardAnalyzer for parsing these messages. I'm trying to run some tests on this index using Solr (I replaced the example app index with my index) to see what kind of results I get from various queries.

When I tried the following query , I got 0 results

"text:happiness"

However, changing that to "text:happiness*" gives me some results. All of them contain terms like "happiness,", "happiness." etc. So I thought that it was a tokenization issue during index creation, however, when I used Luke (a lucene index debugging tool) to run the same query (text:happiness), I got the exact same results that I get for happiness* from Solr, which led me to believe that the problem is not while indexing, but in the way that I'm specifying my Solr query. I looked at the solrconfig.xml, and noticed that it has the following line (commented), I tried uncommenting it, and then modified my query to use "defType=lucene" in addition to the original query, but got the same results.

  <queryParser name="lucene" class="org.apache.solr.search.LuceneQParserPlugin"/>

I have very little experience with Solr, so any help is greatly appreciated :)

1

There are 1 best solutions below

0
On BEST ANSWER

The field that I was querying on was defined as type "text" in the solr schema.xml (not solrconfig.xml as I incorrectly mentioned in my earlier comment). Here's a relevant snippet from the schema.xml

<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <!-- in this example, we will only use synonyms at query time
        <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
        -->
        <!-- Case insensitive stop word removal.
          add enablePositionIncrements=true in both the index and query
          analyzers to leave a 'gap' for more accurate phrase queries.
        -->

I replaced it with the following,

<fieldType name = "text" class="solr.TextField">
      <analyzer class="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
    </fieldType>

Which gives me the required behavior.