dongyan7876 2015-03-03 11:57
浏览 43

Zend Lucene指数

Hello I am trying to build Lucene index. I have problem building index interrupt on server, on localhost works. I found somewhere maybe it's a problem because large number of data I cant figure why. On server I change max_execution time, and time_limit. I am calling this method

static public function indexSearchJedinice($params = null)      
{       
    $debug_file_path = 'c:/wamp/www/linkdl/debug/element.txt';
    $debug_file = fopen($debug_file_path, 'w');
    fwrite($debug_file, 'uso' ."
");
        Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
    // Create index.  Will delete any existing index.
    $index = Zend_Search_Lucene::open('c:/wamp/www/linkdl/lucene/jedinice/');

    $sql = "
            SELECT DISTINCT KNJ.ID, KNJ.Naziv, KNJ.Opis, KNJ.UID
            FROM Kurs as K 
            LEFT JOIN KursPodaci as KP on K.ID = KP.IDKurs
            INNER JOIN KursPripadaGrupi as KPG ON K.ID = KPG.IDKurs
            INNER JOIN PodGrupa ON PodGrupa.ID = KPG.IDPodgrupa
            INNER JOIN KursSadrziNastavneModule ON KursSadrziNastavneModule.IDKurs = K.ID
            INNER JOIN KursModulSadrziJedinicu on KursModulSadrziJedinicu.IDKursNastavniModul = KursSadrziNastavneModule.IDKursNastavniModul
            INNER JOIN KursNastavnaJedinica as KNJ ON KNJ.ID = KursModulSadrziJedinicu.IDKursNastavnaJedinica

            WHERE K.ProdajniStatus IN (0,1) 
            AND KPG.IDCenovnikTip = 2 
            AND KNJ.JeZaPrikazivanje = 0
            ";



    //fwrite($debug_file, $sql ."
");
    if ($jedinice =  Db::getResult($sql))
    {
        foreach ($jedinice as $jedinica)
        {
            //fwrite($debug_file, $jedinica['Naziv'] ."
");
            $doc = new Zend_Search_Lucene_Document();
            $doc->addField(Zend_Search_Lucene_Field::UnIndexed('ID', $jedinica['ID']));
            $doc->addField(Zend_Search_Lucene_Field::Text('Naziv', $jedinica['Naziv'], 'utf-8'));
            $doc->addField(Zend_Search_Lucene_Field::UnStored('Opis', $jedinica['Opis'], 'utf-8'));
            //$doc->addField(Zend_Search_Lucene_Field::UnStored('Opis', '', 'utf-8'));
            $doc->addField(Zend_Search_Lucene_Field::UnIndexed('UID', $jedinica['UID']));
            $doc->addField(Zend_Search_Lucene_Field::UnIndexed('Type', 'jedinica'));

            $kratki_tekst = str_replace(' ', '',  str_replace('U izradi', '', strip_tags($jedinica['Opis'])));
            $kratki_tekst = create_short_text($kratki_tekst, 475);

            $doc->addField(Zend_Search_Lucene_Field::UnIndexed('KratkiOpis', $kratki_tekst, 'utf-8'));

            $index->addDocument($doc);

            /**
             * Optimizacija indeksiranja
            */
            unset($doc);


        }
    }
    fwrite($debug_file, 'Optimizacija pocinje' ."
");
    $index->commit();
    $index->optimize();
    fwrite($debug_file, 'Optimizacija zabrsena' ."
");
    return true;
}

Can someone help me to understand diffrence between open/and create. And this options UnIndexed, UnStored,Text

  • 写回答

1条回答 默认 最新

  • dongwen7423 2015-03-03 12:25
    关注

    Create will build new Zend Lucene index for the first time and after creating the index if you need to reopen existing index to manipulate data into it, use open. Refer

    I have used following code in my implementation and it works fine: It will first tries to open an index, if index will not be available then it will create a new index.

    try {
        $index = Zend_Search_Lucene::open("indexName");
    } catch(Exception $e) {
        $index = Zend_Search_Lucene::create("indexName");
    } 
    

    Regarding field types refer this

    And yes, there is a limit to store data into an index. For 32 bit platforms it is 2 GB. Use 64-bit platforms for larger indices. Source

    评论

报告相同问题?

悬赏问题

  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了