you might try something like this:
if ($this->getRequest()->isPost()) {
if ($form->isValid($this->getRequest()->getPost)) {
//get filtered and valid values from search form.
//filter the array for set values
$data = array_filter($form->getValues());
//extract key => vaules as $variable = values
extract($data);
$query1 = new Zend_Search_Lucene_Search_Query_MultiTerm();
//test for variable isset and add term to query
if (isset($search_title)){
$query1->addTerm(new Zend_Search_Lucene_Index_Term($search_title, 'title'));
}
if (isset($search_skill)){
$query1->addTerm(new Zend_Search_Lucene_Index_Term($search_skill, 'skill'));
}
if (isset($search_city)){
$query1->addTerm(new Zend_Search_Lucene_Index_Term($search_city, 'city'));
}
if (isset($search_country_id)){
$query1->addTerm(new Zend_Search_Lucene_Index_Term($search_country_id, 'country_id'));
}
//This should give the AND you are looking for...I hope
$query= new Zend_Search_Lucene_Search_Query_Boolean(array($query1), array(TRUE));
//get result set from query
$hits = $index->find($query);
}
}
if you use the StringTrim
filter in your forms you won't need to use the trim()
function on your data. The $_POST array is dangerous with user supplied data, ZF provides the getValues()
series of methods to provide data from the Request Object (POST and GET) the have had filters and validators you specify applied.
I used the extract()
function in this instance because I used getValues()
so the data has been filtered and validated. There are of course other valid ways to assign key => value
pairs to variables. Use your favorite.