Example #1
0
 public function saveIndex()
 {
     $this->checkBtreeIsLoaded();
     BTree::save($this->_btree, $this->_btreeDir);
 }
Example #2
0
 /**
  *@param string $word
  *@param BTree $btree
  *@param bool $includeAllDocs
  */
 public static function searchDocuments($word, $btree, $includeAllDocs)
 {
     $ComAcento = self::$COM_ACENTO;
     $ValidChar = self::VALID_CHAR;
     $wordValue = strtolower($word);
     $searchFor = explode(" ", $wordValue);
     $resultAux = array();
     for ($i = 0, $lengthSearch = count($searchFor); $i < $lengthSearch; $i++) {
         $aux = "";
         for ($j = 0, $strlen = strlen($searchFor[$i]); $j < $strlen; $j++) {
             $Letra = substr($searchFor[$i], $j, 1);
             if (ord($Letra) == 195 || ord($Letra) == 227) {
                 $j++;
                 $jj = ord(substr($searchFor[$i], $j, 1));
                 $Letra = $ComAcento[$jj];
             }
             $aux = $aux . $Letra;
         }
         $searchFor[$i] = $aux;
         $bnode = BTree::containsNode(new BTreeNode($searchFor[$i], null), $btree);
         // Se nao existir o no e nao for para incluir tudo, entao houve insucesso na busca
         if ($bnode == null) {
             if (!$includeAllDocs) {
                 return null;
             }
         } else {
             foreach ($bnode->values() as $s) {
                 $resultAux[$s] = isset($resultAux[$s]) ? intval($resultAux[$s]) + 1 : 1;
             }
         }
     }
     // Verificar se os elementos podem ser incluidos na resposta.
     // No caso de incluir todos os elementos, sao todos os nos localizados.
     // Ja no caso de obter apenas os elementos procurados, deve-se verificar se a quantidade
     // de elementos inseridos é igual a quantidade de palavras encontradas.
     $result = array();
     //$Coll = new Collection($result);
     foreach ($resultAux as $s => $value) {
         if (intval($value) == count($searchFor) || $includeAllDocs) {
             $result[] = $s;
         }
     }
     if (count($result) == 0) {
         $result = null;
     }
     return $result;
 }