views:

386

answers:

2

i use solr php client.

but when i use the search method:

$params = array('qf' => 'threads.title posts.body', 'defType' => dismax);

$results = $solr->search($query, $offset, $limit, $params);

when i use defType = dismax it searches $query = 'Peter Jakob' as the whole string instead of Peter OR Jakob. it works fine when i dont use the $params. But main problem is i have to use dismax to be able to search in multiple fields.

How can i make solr php client to know that i have to search in multiple fields and for multiple values (OR)?

Here is my search handler im using:

<requestHandler name="standard" class="solr.SearchHandler" default="true">
    <!-- default values for query parameters -->
     <lst name="defaults">
       <str name="echoParams">explicit</str>
       <!--
       <int name="rows">10</int>
       <str name="fl">*</str>
       <str name="version">2.1</str>
        -->
     </lst>
  </requestHandler>
+2  A: 

Solr has the interface that let's you see how it processes your query. Maybe you can get some hints there? It's in ANALYSIS link (http://ora.ouls.ox.ac.uk:8080/solr/admin/analysis.jsp?highlight=on ) in solr admin page (http://ora.ouls.ox.ac.uk:8080/solr/admin/ ) although it doesn't seem to work in this instance of solr. Please check it out in your own instance.

Maybe you should read this: http://wiki.apache.org/solr/SolrQuerySyntax and this: http://lucene.apache.org/java/2%5F4%5F0/queryparsersyntax.html

In documentation of schema.xml http://wiki.apache.org/solr/SchemaXml it is stated that

The default operator used by Solr's query parser (SolrQueryParser) can be configured with

<solrQueryParser defaultOperator="AND|OR"/>

The default operator is "OR" if unspecified.

So it should work for you without doing anything specific.

If you want to convert $query = "Peter Jakob" to Peter OR Jakob just do the following:

$query = preg_replace('`(\\s)(\\w|"[^"]+")`', '\\1OR \\2', $query);
Kamil Szot
could you elaborate? what interface and how do i use it?
weng
I'm sorry I can't help you more. I don't use solr on daily basis anymore and I got bit rusty.
Kamil Szot
Maybe just searching for Peter OR Jacob would give you what you want?
Kamil Szot
i cant because i am making a website where the user enter a text in a box and jquery picks it up, send it to php. so the text will be $query. read my updated question
weng
Im sure if you are using JQuery that before posting you can do the parsing. Kamil's regex should work for you.
Eric Pugh
A: 

It's not exactly what you're after, but FYI you can search in multiple fields without using dismax and without writing complicated queries. One simple approach is to use the copyField system to copy the default search fields into one and then set that as your default search field, e.g. this example with a "title" and "description" field.

Have fields like this:

   <field name="title" type="string" indexed="false" stored="true" />
   <field name="description" type="string" indexed="false" stored="true" />
   <field name="combined" type="string" indexed="true" stored="false" multiValued="true" />

Set up copyfields like this:

 <copyField source="title" dest="combined" />
 <copyField source="description" dest="combined" />

And set your default search like this:

 <defaultSearchField>combined</defaultSearchField>

This will result in searches running against the "combined" field by default, which contains both the title and description.

El Yobo