Zend framework Zend_搜索\u Lucene数组中的搜索

Zend framework Zend_搜索\u Lucene数组中的搜索,zend-framework,zend-search-lucene,Zend Framework,Zend Search Lucene,是否有方法将数组存储为文档字段,然后查询该数组 我收集了一些物品,它们都贴上了标签。我希望能够搜索所有匹配的项目,例如标签55和67 如何实现这一点?首先,您必须使用数组中的数据创建索引文件。文档介绍了如何创建一个 所以想象你的阵列看起来像 $data = array( array( 'tag' => '55 67', 'content' => 'Lorem Ipsu 1', 'url' => 'http://foobar.net/conten

是否有方法将数组存储为文档字段,然后查询该数组

我收集了一些物品,它们都贴上了标签。我希望能够搜索所有匹配的项目,例如标签55和67


如何实现这一点?

首先,您必须使用数组中的数据创建索引文件。文档介绍了如何创建一个

所以想象你的阵列看起来像

$data = array(
  array(
     'tag' => '55 67',
     'content' => 'Lorem Ipsu 1',
     'url' => 'http://foobar.net/content.php?id=1'
  ),
  array(
     'tag' => '32 67'
     'content' => 'Lorem Ipsu 2',
     'url' => 'http://foobar.net/content.php?id=2'
  )
);
它会给出类似的东西来创建索引

 // Create index
$index = Zend_Search_Lucene::create('/data/my-index');


foreach($data as $row){
  $doc = new Zend_Search_Lucene_Document();
  // Store document URL to identify it in the search results
  $doc->addField(Zend_Search_Lucene_Field::Text('url', $row['url']));

  // Store document TAGS 
  $doc->addField(Zend_Search_Lucene_Field::Text('tag', $row['tag']));

  // Index document contents
  $doc->addField(Zend_Search_Lucene_Field::UnStored('contents', $row['content']));

  // Add document to the index
  $index->addDocument($doc);
 }
最后,返回到您的索引文件

$index = Zend_Search_Lucene::open('/data/my_index');

$hits = $index->find('tag:55 AND tag:67');

foreach ($hits as $hit) {
    echo $hit->score;
    echo $hit->url;
    echo $hit->tag;
}

注 我真的不知道你为什么打算使用Lucene来做这样的工作,如果你只是想要一个匹配任何标签的文章列表,那么使用普通的
SQL
查询就更容易了


如果你想知道Zend_Search_Lucene的工作原理,那可能是一个完全不相关的例子。我问是否可以将实际数组存储为文档字段,然后搜索该字段。不过还是要谢谢你的长篇大论。@Apikot:哈,是的,就我所知,你不能在索引中存储数组。上面的解决方案对我也不起作用。我只是没有结果,Zend和Luke都没有。