What I want to do is be able to filter the returned results to a specific type_id.
First I index all the articles I want to be searchable.
SELECT
article_id, article_name, article_body, type_id
FROM
articles
WHERE
active = 1;
$this->index = Zend_Search_Lucene::create($this->directory);
foreach ($result as $key => $value)
{
$this->doc = new Zend_Search_Lucene_Document();
//Indexed
$this->doc->addField(Zend_Search_Lucene_Field::Text('article_name',$value['article_name']));
$this->doc->addField(Zend_Search_Lucene_Field::Text('article_body', $value['article_body']));
//Indexed
//Unindexd
$this->doc->addField(Zend_Search_Lucene_Field::UnIndexed('article_id', $value['article_id']));
$this->doc->addField(Zend_Search_Lucene_Field::UnIndexed('type_id', $value['type_id']));
//Unindexd
$this->index->addDocument($this->doc);
}
$this->index->commit();
$this->index->optimize();
Now when I perform a search, if I want to filter the results by the type_id, how would I do it using the ->find() command of Zend?
$this->index = Zend_Search_Lucene::open($this->directory);
//Based on the type_id, I only want the indexed articles that match the type_id to be returned.
$results = $this->index->find('+type_id:2 '.$search_term.'*');
//Cycle through the results.
I want zend-search-lucene to only returns results based on the type_id that I specify.
You cannot search for unindexed terms (such as type_id). If you want the field to be searchable, but not tokenised, you want to add it as keyword:
From the manual: