2012-07-14 100 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