2012-07-14 62 views
1

我有桌上白衣4字段女巫我想搜索。这样 我索引字段:Symfony lucene独立搜索字段

$doc->addField(Zend_Search_Lucene_Field::Keyword('pk', $this->getId())); 
    $doc->addField(Zend_Search_Lucene_Field::UnStored('username', $this->getUsername(), 'utf-8')); 
    $doc->addField(Zend_Search_Lucene_Field::UnStored('firstName', $this->getFirstName(), 'utf-8')); 
    $doc->addField(Zend_Search_Lucene_Field::UnStored('lastName', $this->getLastName(), 'utf-8')); 
    $doc->addField(Zend_Search_Lucene_Field::UnStored('city', $this->getCity(), 'utf-8')); 

我想在这个领域蒙山窗体选项单独的搜索。

<select name="contact[subject]" id="contact_subject"> 
    <option value="0">Username</option> 
    <option value="1">First Name</option> 
    <option value="2">Last Name</option> 
    <option value="3">City</option> 
</select> 

如何告诉Lucene只在需要的字段中搜索结果? 我读了许多问题和explenations,但我不明白:(

回答

1

您需要与外地的名字前缀搜索词:

$results = $li->find('username:"foobar"'); 

其中$li是你的Lucene索引

+0

如果我$ query ='username:“user5”'; $ this-> query = Doctrine_Core :: getTable('sfGuardUser') - > getAutocompleteQuery($ query);如果是这样的话,我想用* sumbol来搜索不完整的serach结果吗?我试过了,但是没有显示结果 – plamen 2012-07-15 17:54:36

+0

Zend_Se arch_Lucene [支持通配符](http://framework.zend.com/manual/en/zend.search.lucene.query-language.html#zend.search.lucene.query-language.wildcard)。 – Maerlyn 2012-07-15 18:02:43

+0

是的,我alredy读这个,但是当我尝试$ results = $ li-> find('username:“foobar *”');通配符不工作。我也试过$ results = $ li-> find('username:“foobar”*');和$ results = $ li-> find('username:“foobar”'。'*'); – plamen 2012-07-15 18:17:29