0

我正在尝试在我的网站中实现 Searchmachine。我为此使用 Zend_Search_Lucene。

索引是这样创建的:

public function  create($config, $create = true)
{
    $this->_config = $config;

    // create a new index
    if ($create) {
        Zend_Search_Lucene_Analysis_Analyzer::setDefault(
            new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive()
        );

        $this->_index = Zend_Search_Lucene::create(APPLICATION_PATH . $this->_config->index->path);
    } else {
        $this->_index = Zend_Search_Lucene::open(APPLICATION_PATH . $this->_config->index->path);
    }
}

{

public function addToIndex($data)   
   $i = 0;

    foreach ($data as $val) {
        $scriptObj = new Sl_Model_Script();
        $scriptObj->title = $val['title'];
        $scriptObj->description = $val['description'];
        $scriptObj->link = $val['link'];
        $scriptObj->tutorials = $val['tutorials'];
        $scriptObj->screenshot = $val['screenshot'];
        $scriptObj->download = $val['download'];
        $scriptObj->tags = $val['tags'];
        $scriptObj->version = $val['version'];
        $this->_dao->add($scriptObj);
        $i++;
    }

    return $i;
}


 /**
     * Add to Index
     *
     * @param Sl_Interface_Model $scriptObj
     */
    public function add(Sl_Interface_Model $scriptObj)
    {

        // UTF-8 for INDEX

        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::text('title', $scriptObj->title, 'utf-8'));
        $doc->addField(Zend_Search_Lucene_Field::text('tags', $scriptObj->tags, 'utf-8'));
        $doc->addField(Zend_Search_Lucene_Field::text('version', $scriptObj->version, 'utf-8'));
        $doc->addField(Zend_Search_Lucene_Field::text('download', $scriptObj->download, 'utf-8'));
        $doc->addField(Zend_Search_Lucene_Field::text('link', $scriptObj->link));
        $doc->addField(Zend_Search_Lucene_Field::text('description', $scriptObj->description, 'utf-8'));
        $doc->addField(Zend_Search_Lucene_Field::text('tutorials', $scriptObj->tutorials, 'utf-8'));
        $doc->addField(Zend_Search_Lucene_Field::text('screenshot', $scriptObj->screenshot));
        $this->_index->addDocument($doc);

    }

但是当我尝试使用以下命令查询索引时:

$index->​​find('Wordpress 2.8.1' . '*');

我收到以下错误:

“模式开头需要非通配符。”

任何想法如何查询像我这样的字符串?对“wordpress”的查询就像例外一样。

4

1 回答 1

1

Lucene 不能处理前导通配符,只能处理尾随通配符。也就是说,它不支持像“告诉我每个名字以'att'结尾的人”这样的查询,就像

名字:*att

它只支持尾随通配符。告诉我所有名字以“ma”开头的

名字:马*

请参阅此 Lucene 常见问题解答条目:

http://wiki.apache.org/lucene-java/LuceneFAQ#head-4d62118417eaef0dcb87f4370583f809848ea695

Lucene 2.1 有一个解决方法,但开发人员说它可能“昂贵”。

于 2009-08-19T17:18:09.863 回答