phpzend-lucene

PHP Zend Lucene Search Query with multiple criteria fail


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.


Solution

  • 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 :)