2

我有一个使用完全在 zend 上开发的 CMS 管理的网站。现在我也必须实现一个搜索功能。我没有做任何与zend搜索相关的事情。我收到的一些建议是实施蜘蛛。该站点将有很多链接(并且会不断添加)。我完全困惑,我不知道从哪里开始。zend_search_lucene 会成功吗?

4

3 回答 3

2

您可能不会为此找到完全交钥匙的东西。如果您的内容都是公开的,并且只使用爬虫就可以了,那么最容易实现的可能是 Google Site Search。

http://www.google.com/enterprise/search/products_gss.html

如果您需要从搜索中获得它不提供的不同功能,您可能会在编写一些代码时遇到困难。Alvar 发布的 Zend Lucene 链接很好。如果我没记错的话,关于 Zend_Lucene 的一个丑陋的事情是它依赖于基于文本的 lucene 索引而没有任何 Java。只是管理起来更慢更麻烦。

Solr 是一种更强大的基于 Lucene 的方法。它是基于 Java 的,并通过 API 在自己的服务上运行。它可以很好地扩展,现在有一个 PHP Pecl 可以帮助您与它进行通信。

http://php.net/manual/en/book.solr.php

另一种选择是狮身人面像。这个搜索引擎直接连接到您的数据库,因此索引可能更直观一些。

http://sphinxsearch.com/

祝你好运!

于 2012-10-26T17:33:20.917 回答
1

Lucene 很奇怪,我从来没有让它正常工作并开发了我自己的搜索逻辑,但也许这有帮助:

http://devzone.zend.com/397/roll-your-own-search-engine-with-zend_search_lucene/

于 2012-10-26T17:26:34.413 回答
0

因为您使用的是本土产品,所以至少在开始时,让事情尽可能简单,您可能会得到更好的服务。此外,因为您的产品是本土开发的,您应该对数据结构有一个很好的处理。

构建一个简单的基于查询的搜索可能适合初学者。

我从一个简单的搜索表单开始:

<?php

    class Application_Form_Search extends Zend_Form
    {

        public function init() {

            $this->setMethod('POST');
            $this->setDecorators(array(
                array('ViewScript', array(
                        'viewScript' => '_searchForm.phtml'
                ))
            ));

            // create new element
            $query = $this->createElement('text', 'query');
            // element options
            $query->setLabel('Search Keywords');
            $query->setAttribs(array('placeholder' => 'Title',
                'size' => 27,
            ));
            // add the element to the form
            $this->addElement($query);

            $submit = $this->createElement('submit', 'search');
            $submit->setLabel('Search Site');
            $submit->setDecorators(array('ViewHelper'));
            $this->addElement($submit);
        }
    }

然后我构建了一个简单的动作助手来显示和路由表单:

<?php

class Library_Controller_Action_Helper_Search extends Zend_Controller_Action_Helper_Abstract
{

    public function direct($action, $label = null, $placeHolder = null)
    {
        $form = new Application_Form_Search();
        $form->setAction($action);
        $form->search->setLabel($label);
        $form->query->setAttribs(array('placeholder' => $placeHolder,
            'size' => 27,
        ));

        return $form;
    }
}

然后我在 layout.phtml 中为搜索表单添加了一个占位符

<?php echo $this->layout()->search ?>

然后在需要使用搜索功能的控制器中,我将助手添加到 predispatch():

public function preDispatch()
    {
        //assign search action helper to view placeholder
        $this->_helper->layout()->search = $this->_helper->search(
                'url_for_action', 'Submit button label', 'placeholder text'
        );
    }

然后我使用一个简单的映射器方法来执行适当的查询,我通常返回一个分页器适配器:

 public function fetchPagedMoviesByTitle($title)
    {

        $select = $this->getGateway()->select();
        $select->where(new Zend_Db_Expr("title LIKE '%$title%'"));
        $select->order('title', 'ASC');

        //create a new instance of the paginator adapter and return it
        $adapter = new Video_Model_Paginator_Video($select);

        return $adapter;
    }

这是实现搜索功能的简单方法,适用于大多数类型的查询。我发现一个 switch 语句和几个简单的数据库查询以及我需要的几乎所有信息都是可用的。

祝你好运。

于 2012-10-27T14:27:54.443 回答