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

末尾のワイルドカードのみがサポートされています。「ま」で終わる名前の人全員教えて

名: ま*

この Lucene FAQ エントリを参照してください。

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

Lucene 2.1 には回避策がありますが、開発者は「高価」になる可能性があると述べています。

于 2009-08-19T17:18:09.863 に答える