Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend\u搜索\u Lucene帮助_Php_Zend Framework_Lucene_Search Engine - Fatal编程技术网

Php Zend\u搜索\u Lucene帮助

Php Zend\u搜索\u Lucene帮助,php,zend-framework,lucene,search-engine,Php,Zend Framework,Lucene,Search Engine,编辑: 我已通过以下方法解决了该问题: +"lorem ipsum" +type:photo +"lorem ipsum" +type:video 但另一个问题是索引返回的结果正确,但id错误(id是主键)。更具体地说,返回的id字段比我用来构建索引的数据库中的真实id(id-1)少1个 真奇怪 这些搜索查询有什么问题: "lorem ipsum" AND +type:photo "lorem ipsum" AND +type:video 第一个查询应该只查找type=photo的结果,第

编辑:

我已通过以下方法解决了该问题:

+"lorem ipsum" +type:photo
+"lorem ipsum" +type:video
但另一个问题是索引返回的结果正确,但id错误(id是主键)。更具体地说,返回的id字段比我用来构建索引的数据库中的真实id(id-1)少1个

真奇怪


这些搜索查询有什么问题:

"lorem ipsum" AND +type:photo
"lorem ipsum" AND +type:video
第一个查询应该只查找type=photo的结果,第二个查询只搜索视频。但他们都在归还照片和视频

以下是我如何构建索引:

    // create media index
    $index = Zend_Search_Lucene::create('/data/media_index');
    // get all media
    $media = $this->_getTable('Media')->get();
    // iterate through media and build index
    foreach ($media as $m) {

        $doc = new Zend_Search_Lucene_Document();

        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('id',
                                                           $m->id));
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('thumb_path',
                                                           $m->thumb_path));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('title',
                                                         $m->title));
        $doc->addField(Zend_Search_Lucene_Field::UnStored('description',
                                                          $m->description));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('type',
                                                         $m->type));

        $index->addDocument($doc);

    }
    // commit the index
    $index->commit();
下面是我如何搜索它的:

    $index = Zend_Search_Lucene::open('/data/media_index');
    $this->view->photos = $index->find('"lorem ipsum" AND +type:photo');
    $this->view->videos = $index->find('"lorem ipsum" AND +type:video');

有什么想法吗?

我刚刚对自己的搜索索引进行了一些测试,问题似乎出在查询本身,而不是代码。查询中的“AND”是运算符,“+”也是运算符。查询解析器似乎被双运算符逻辑弄糊涂了,因为它们之间没有任何术语。这是我在他们的文档中找到的一个整体报价:

如果使用AND/OR/NOT样式,则所有查询词之间必须存在AND或OR运算符。每个术语前面也可以有NOT运算符。AND运算符的优先级高于OR运算符。这与Java Lucene行为不同

现在,通过解析器运行您的查询,这是Search_query对象:

string '"lorem ipsum" AND +type:photo' (length=29)

object(Zend_Search_Lucene_Search_Query_MultiTerm)[230]
  private '_terms' => 
    array
      0 => 
        object(Zend_Search_Lucene_Index_Term)[236]
          public 'field' => null
          public 'text' => string 'lorem' (length=5)
      1 => 
        object(Zend_Search_Lucene_Index_Term)[237]
          public 'field' => null
          public 'text' => string 'ipsum' (length=5)
      2 => 
        object(Zend_Search_Lucene_Index_Term)[238]
          public 'field' => null
          public 'text' => string 'and' (length=3)
      3 => 
        object(Zend_Search_Lucene_Index_Term)[239]
          public 'field' => null
          public 'text' => string 'type' (length=4)
      4 => 
        object(Zend_Search_Lucene_Index_Term)[240]
          public 'field' => null
          public 'text' => string 'photo' (length=5)
稍微向上更改查询,删除
或删除
+
,并且仅使用1

string '"lorem ipsum" +type:photo' (length=25)
string '"lorem ipsum" AND type:photo' (length=28)

object(Zend_Search_Lucene_Search_Query_Boolean)[227]
  private '_subqueries' => 
    array
      0 => 
        object(Zend_Search_Lucene_Search_Query_Phrase)[230]
          private '_terms' => 
            array
              0 => 
                object(Zend_Search_Lucene_Index_Term)[233]
                  public 'field' => null
                  public 'text' => string 'lorem' (length=5)
              1 => 
                object(Zend_Search_Lucene_Index_Term)[234]
                  public 'field' => null
                  public 'text' => string 'ipsum' (length=5)
      1 => 
        object(Zend_Search_Lucene_Search_Query_Term)[235]
          private '_term' => 
            object(Zend_Search_Lucene_Index_Term)[232]
              public 'field' => string 'type' (length=4)
              public 'text' => string 'photo' (length=5)
唯一的区别是:

  private '_signs' => 
    array
      0 => boolean true
      1 => boolean true
+

  private '_signs' => 
    array
      0 => null
      1 => boolean true
运算符要求结果中的两个搜索查询都是必需的,而
+
只要求右侧的值是必需的

因此,只需将查询更改为

“lorem ipsum”和类型:photo


你应该得到你想要的结果。

关于“id问题”,我想“id”是用来访问每个结果的内部变量。因此,我建议将字段重命名为“entryId”,然后使用
$resultItem->entryId

,我认为这样做了。不过还有一个问题,搜索返回的结果以id=0(id是主键)开始,数据库中的id以1开始。似乎索引返回id-1。为什么?就我所能看到的而言,我正在正确地创建索引。查看这篇文章:我也没有意识到这一点,但ID似乎是lucene的保留字。在我的链接生成器中,我使用slug链接到它们,这是标题的URL编码版本。因此,正如下面的帖子所说,lucene索引必须已经使用ID,请尝试将索引中的关键字重命名为
media\u ID
或类似的内容。