manning-sandbox.com/forum.jspa?forumID=329
In order to use data provided by a user, we first have to ensure that it is safe to do so. The
Zend_Filter_Input component provides both filtering and validation functionality. We use filtering (#1)
to remove any whitespace padding on the search term and also to remove any HTML with the StripTags
filter. The only validation we do on the search term is to ensure that the user has provided it (#2) as searching
for an empty string will not return useful results! Zend_Filter_Input??™s isValid() function (#3) filters the data
and then checks that the validation passes. On success, we collect the search query and reassign to the view to
display.
Having checked that the data provided by the user is okay to use, we can now perform the search. As
usual, with Zend_Search_Lucene, firstly we open the index (#4) and then call the find() function to do the
work. In this case, we can use the built in string query parser as the user can provide a very simple search
query (such as ???zoo??? to find all zoos, or a more complicated one such as ???warwickshire -zoo??? to find all
attractions in Warwickshire except zoos.
If the validation fails, we collect the reason from Zend_Filter_Input using getMessages() (#7)
and assign to the view.
Pages:
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240