You could collect Countries into a string and store them in a special field:
---------------------------------
$countries = implode(' ', $countriesArray);
$doc->addField(Zend_Search_Lucene_Field::UnStored($countries), 'Country');
...
---------
It can be specified in a query:
--------------
$hts = $index->find("($queryString) AND Country:(France OR German)");
------
or through the query construction API:
--------------
$userQuery = Zend_Search_Lucene_Search_QueryParser::parse($queryString);
$countrySubquery = new Zend_Search_Lucene_Search_Query_MultiTerm();
$countryTerm1 = new Zend_Search_Lucene_Index_Term('france', 'Country');
$countryTerm2 = new Zend_Search_Lucene_Index_Term('german', 'Country');
$countrySubquery->addTerm($countryTerm1); // second parameter is omitted, term
is optional
$countrySubquery->addTerm($countryTerm2); // second parameter is omitted, term
is optional
$query = new Zend_Search_Lucene_Search_Query_Boolean();
$query->addSubquery($userQuery, true /* required */ );
$query->addSubquery($countrySubquery, true /* required */ );
$hts = $index->find($query);
------
PS Please be careful with such fields.
Country, language, sex and many other fields like this have _very_ low
selectivity. That means you can get ex. half of indexed data in result set.
That's enough if you have ex. 1-2 millions indexed documents.
It also makes search process slower even final result set is small enough (it's
necessary to construct two result sets and then intersect them).
Possible option to resolve this problem is to combine Lucene full-text index
with relational database. You could find what you need using full-text search
and then filter result using relational data.
With best regards,
Alexander Veremyev.
_____
From: Charles Harley [mailto:[EMAIL PROTECTED]
Sent: Monday, September 17, 2007 3:31 PM
To: [email protected]
Subject: [fw-general] Searching variable options
Hi,
I’m building a search engine using the Zend_Search_Lucene module but have come
across a little problem. The data I am searching is stored in a database and
consists of member profiles. As part of their profile members can select 0 or
more countries, which are stored in their profile. The search engine I am
creating will have the ability to search for members who have selected at least
one of the searched for countries.
What is the best way to add the selected countries to the search index and then
search that index from 0 or more selected countries in the search form?
Many thanks,
Charles
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.487 / Virus Database: 269.13.21/1012 - Release Date: 16.09.2007
18:32
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.487 / Virus Database: 269.13.22/1015 - Release Date: 18.09.2007
11:53