English 中文(简体)
solr php client search method: use to search word1 OR word2?
原标题:

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>
最佳回答

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_4_0/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);
问题回答

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.





相关问题
Acronyms with Sphinx search engine

how can i index acronyms like m.i.a. ? when i search for mia , i get results for mia and not m.i.a. . when i search for m.i.a. , i get nothing at all. edit: solution looks roughly like: ...

Querying multiple index in django-sphinx

The django-sphinx documentation shows that django-sphinx layer also supports some basic querying over multiple indexes. http://github.com/dcramer/django-sphinx/blob/master/README.rst from ...

Adding Search to Ruby on Rails - Easy Question

I am trying to figure out how to add search to my rails application. I am brand new so go slow. I have created a blog and done quite a bit of customizing including adding some AJAX, pretty proud of ...

Searching and ranking short phrases (e.g. movie titles)

I m trying to improve our search capabilities for short phrases (in our case movie titles) and am currently looking at SQL Server 2008 Full Text Search, which provides some of the functionality we ...

Will Full text search consider indexes?

Ok I have a full text search index created on my JobsToDo table, but what I m concerned about is if this is rendering my other indexes on the table useless. I have a normal nonclustered index on the ...

Lucene.NET on shared hosting

I m trying to get Lucene.NET to work on a shared hosting environment. Mascix over on codeproject outlines here how he got this to work on godaddy. I m attempting this on isqsolutions. Both ...

Hibernate Search or Compass

I can t seem to find any recent talk on the choice. Back in 06 there was criticism on Hibernate Search as being incomplete and not being ready to compete with Compass, is it now? Has anyone used both ...

热门标签