Zend_Search_Lucene will automatically optimize the search index as new documents are added. You can
also force optimization by calling the optimize() function if required though. Now that we have created an
index file, we can now perform searches on the index. As you would expect, Zend_Search_Lucene provides a
variety of powerful mechanisms for building queries that produce the desired results and we shall explore them
next
8.2.2 Powerful queries
Searching a Zend_Search_Lucene index is as simple as:
$index = Zend_Search_Lucene::open('path/to/index');
$index->find($query);
The $query parameter may be either a string or you can build a query using Zend_Search_Lucene objects
and pass in an instance of Zend_Search_Lucene_Search_Query. Clearly passing in a string is the easiest, but
for maximum flexibility, using the Zend_Search_Lucene_Search_Query object can be very useful. The String
is converted to a search query object using a query parser and a good rule of thumb is that you should use the
query parser for data from users and the query objects directly when programmatically creating queries. This
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.
Pages:
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217