Reputation: 21
Zend Lucene Search Document
Lucene Document pk:Keyword category_id:Keyword title:UnStored description:UnStored
This is my string query "java lucene AND +category_id:7". Result here:
Array ( [0] => Array ( [pk] => 209 [category_id] => 7 [id] => 0 [score] => 0.40750848701418 ) [1] => Array ( [pk] => 225 [category_id] => 7 [id] => 3 [score] => 0.30750848701619 ) [2] => Array ( [pk] => 211 [category_id] => 8 ====>>> WRONG!!! [id] => 2 [score] => 0.37152213415004 ) )
Can you do a Query search on the category_id = 7 only?? Thanks in advance.
Upvotes: 0
Views: 744
Reputation: 21
I had solved this problem by using Zend Query Parsing
$strQuery = Zend_Search_Lucene_Search_QueryParser::parse('java lucene');
$cateTerm = new Zend_Search_Lucene_Index_Term(7 , 'category_id');
$cateQuery = new Zend_Search_Lucene_Search_Query_Term($cateTerm);
$query = new Zend_Search_Lucene_Search_Query_Boolean();
$query->addSubquery($strQuery, true /* required */);
$query->addSubquery($cateQuery, true /* required */);
Results will be only in category_id = 7 :)
Upvotes: 2
Reputation: 992
You can remove the AND +category_id:7
from you query, what you want is a filter since +category_id:7
is not needed as a ranked value.
I don't know how to implement it with Zend_Lucene
but in solr I used to pass fq parameter, this may give you a hint :)
Filtering is a process that constrains the search space and allows only a subset of documents to be considered for search hits. You can use this feature to implement search-within-search results. Lucene comes with various built-in filters such as BooleanFilter, CachingWrapperFilter, ChainedFilter, DuplicateFilter, PrefixFilter, QueryWrapperFilter, RangeFilter, RemoteCachingWrapperFilter, SpanFilter, etc.(THE NATIVE JAVA VERSION) Filter can be passed to IndexSearcher's search method to filter documents that match the filter criteria.
Upvotes: 0