How to exclude the search for specified fields using Zend Search (Lucene)

I built a search index using the PHP Zend Framework Search (based on Lucene). Search is a site for buying / selling.

My search index contains the following fields:

item-id (UnIndexed)
item-title (Text)
item-description (UnStored)
item-tags (Text)
item-price (keyword)
seller-id (UnIndexed)
seller-name (text)

I want the user to search for the index, filtering out their search, or just searching for items, or searching for sellers by name.

If I searched using Lucene’s default search settings, I’ll search for all 5 fields and the seller’s name field. This is not what I want. I would like for the user to perform the search that I want them to be needed from the drop-down menu if they are looking for an item or seller’s name.

How can I specify a search query when searching for items to ignore the seller name field? And when searching for a seller’s name, how can I tell a search query not to search for any of the item’s fields? Or is it better to create a separate index for seller names?

+4
source share
1 answer

There is currently no way to explicitly not search for a field in the Lucene query language or the Zend_Search_Lucene query designer API.

However, you can explicitly specify which fields you want to search in the query. An example is:

 seller-name: Joe McBob 

If you use this approach, you will need to explicitly indicate which fields you want to request and what to look for in them. Therefore, if you also need to search for the same text in the item-title field, you will have to duplicate the above, but with a different field name. An example is:

 seller-name: Joe McBob OR item-title: JoeMcBob 

You can, of course, do all this through the query building API that Zend_Search_Lucene provides. manual has some good examples.

It is worth noting here that, as you have discovered, Zend_Search_Lucene will search ALL fields by default. This is one of the ways it differs from Java Lucene. However, you can set the default field for the query using the static setDefaultSearchField method of the setDefaultSearchField class.

+6
source

All Articles