Symfony lucene分开搜索字段

时间:2012-07-14 23:43:56

标签: search symfony1 lucene

我有想要搜索的表格4野外女巫。 我像这样索引字段:

$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仅在我想要的字段中搜索结果? 我读了很多问题和解释,但我没理解:(

1 个答案:

答案 0 :(得分:1)

您需要在搜索字词前加上字段名称:

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

其中$li是你的lucene索引。