i use symfony 1.4.11. added search project, in jobeet tutorial. need make advanced search. example, user can іудусе "county" , "category". make form , read this tutorial. found this. not separate query several parts.
my class
public function updateluceneindex() { $index = $this->gettable()->getluceneindex(); // remove existing entry if ($hit = $index->find('pk:'.$this->getadid())) { $index->delete($hit->adid); } // don't index expired , non-activated if (!$this->getactive()) { return; } $doc = new zend_search_lucene_document(); // store primary key url identify in search results $doc->addfield(zend_search_lucene_field::unindexed('pk', $this->getadid())); $doc->addfield(zend_search_lucene_field::unstored('address', $this->getaddress(), 'utf-8')); $doc->addfield(zend_search_lucene_field::unstored('company', $this->getcompany(), 'utf-8')); $doc->addfield(zend_search_lucene_field::unstored('country', $this->getcountry(), 'utf-8')); $doc->addfield(zend_search_lucene_field::unstored('contact_person', $this->getcontactperson(), 'utf-8')); $doc->addfield(zend_search_lucene_field::unstored('phone', $this->getphone(), 'utf-8')); $doc->addfield(zend_search_lucene_field::unstored('email', $this->getemail(), 'utf-8')); $doc->addfield(zend_search_lucene_field::unstored('title', $this->gettitle(), 'utf-8')); $doc->addfield(zend_search_lucene_field::unstored('content', $this->getcontent(), 'utf-8')); $doc->addfield(zend_search_lucene_field::unstored('category_id', $this->getcategoryid(), 'utf-8')); $index->adddocument($doc); $index->commit(); } table class
public function getadslucenequery($query) { projectconfiguration::registerzend(); $query = zend_search_lucene_search_queryparser::parse($query); $hits = self::getluceneindex()->find($query); $pks = array(); foreach ($hits $hit) { $pks[] = $hit->pk; } if (empty($pks)) { return array(); } $q = $this->createquery('a') ->wherein('a.adid', $pks) ->limit(20); $q = $this->createquery('a') ->andwhere('a.active = ?',1) ->leftjoin('a.owner o') ->leftjoin('o.profile p') ->andwhere('p.payed_until > now()') ->andwhere('a.expires_at > now()') ->addorderby ('created_at desc'); return $q->execute(); } public function getluceneindex() { projectconfiguration::registerzend(); if (file_exists($index = $this->getluceneindexfile())) { return zend_search_lucene::open($index); } else { return zend_search_lucene::create($index); } } static public function getluceneindexfile() { return sfconfig::get('sf_data_dir').'/ads.'.sfconfig::get('sf_environment').'.index'; }
in lucene query can tell field in value, see the relevant part of documentation.
it works like:
title:"the right way" , text:go
Comments
Post a Comment