2015-03-03 256 views
0

你好,我正在嘗試構建Lucene索引。我有問題在服務器上建立索引中斷,在本地主機上工作。我發現某處可能是一個問題,因爲大量的數據我不知道爲什麼。在服務器上,我更改max_execution時間和time_limit。我打電話給這個方法Zend Lucene索引

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' ."\n"); 
     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 ."\n"); 
    if ($jedinice = Db::getResult($sql)) 
    { 
     foreach ($jedinice as $jedinica) 
     { 
      //fwrite($debug_file, $jedinica['Naziv'] ."\n"); 
      $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' ."\n"); 
    $index->commit(); 
    $index->optimize(); 
    fwrite($debug_file, 'Optimizacija zabrsena' ."\n"); 
    return true; 
} 

有人可以幫助我瞭解open /和create之間的區別。 而這個選項不索引,不保存,文字

回答

0

Create將建立首次創建索引,如果你需要重新打開現有的索引和處理數據之後新的Zend Lucene索引,使用openRefer

我在我的實現中使用了下面的代碼,它工作正常: 它將首先嚐試打開一個索引,如果索引不可用,那麼它將創建一個新的索引。

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

關於字段類型是指this

是的,是有限制的數據存儲到一個索引。對於32位平臺它是2 GB。爲更大的索引使用64位平臺。 Source