2011-02-15 6 views
1

내가 원하는 것은 반환 된 결과를 특정 type_id로 필터링 할 수 있습니다.Zend_Search_Lucene, 지정한 type_id를 기반으로 결과를 반환하십시오.

먼저 검색 가능한 모든 기사의 색인을 생성합니다. 젠드의> 찾기() 명령 - 나는 검색을 수행 할 때 나는 TYPE_ID을 기준으로 결과를 필터링 할 경우

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(); 

지금, 내가 얼마나 그것은을 사용하고 계십니까?

$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. 

내가 지정한 type_id를 기반으로 한 결과 만 반환하도록 zend-search-lucene을 원합니다.

+0

AND 연산자는 어떻게 사용합니까? 예 : '+ type_id : 2 AND'. $ search_term. '*' – Marcin

답변

0

인덱싱되지 않은 용어 (예 : type_id)를 검색 할 수 없습니다.

인덱싱되지 않은 필드, 검색 할 수 없습니다 그러나 그들은 반환과 같습니다 manual에서

$this->doc->addField(Zend_Search_Lucene_Field::Keyword('type_id', $value['type_id'])); 

: 당신이 필드를 검색하지만, tokenised하지하길 원한다면, 당신은 키워드로 추가 할 검색 안타. 데이터베이스 타임 스탬프, 기본 키, 파일 시스템 경로 및 기타 외부 식별자는 인덱스가없는 필드의 경우 후보가 좋습니다.

관련 문제