예제 #1
0
 public function testSearchQueryClass()
 {
     $searchQuery = new SearchQuery();
     $searchQuery->parseQuery($this->input);
     $this->assertEquals($this->query, $searchQuery->getQueryString());
     $this->assertEquals($this->tokens, $searchQuery->getQueryTokens());
 }
 public function checkQuery(SearchQuery $obj)
 {
     $queryTokens = $obj->getQueryTokens();
     // if we have some tokens, we check if they are correct or not.
     if ($queryTokens) {
         foreach ($queryTokens as $token => $parameters) {
             $key = array_search($token, $this->validTokens);
             if (is_numeric($key)) {
                 return TRUE;
             }
         }
         return FALSE;
     } else {
         if ($obj->getQueryString()) {
             return TRUE;
         }
     }
 }
 public function search(SearchQuery $obj)
 {
     if (AdvancedPathLib::getCurrentOS() == AdvancedPathLib::OS_WINDOWS) {
         return array(0, array());
     }
     $this->results = array();
     // setting the queryString to the variable.
     $searchArray = explode(' ', $obj->getQueryString());
     foreach ($searchArray as $word) {
         $this->searchQuery .= 'filename:' . $word . '* ';
     }
     // setting the queryTokens to the variable.
     $queryTokens = $obj->getQueryTokens();
     // for each valid token, we add the token and its parameters to the $searchQuery variable.
     if ($queryTokens) {
         foreach ($queryTokens as $token => $parameters) {
             if (in_array($token, $this->getValidTokens())) {
                 foreach ($parameters as $count => $value) {
                     $this->searchQuery .= $token . ':' . $value;
                     if ($count < count($parameters) - 1) {
                         $this->searchQuery .= ' OR ';
                     } else {
                         $this->searchQuery .= ' ';
                     }
                 }
                 $this->searchQuery .= 'AND ';
             }
         }
         // searching for an AND at the end of the searchQuery, if it's there we delete it
         // to conform the query to the recoll standards.
         // ( by the way, an AND at the end of a query does not make any sense, do it? :P )
         $pos = strpos($this->searchQuery, 'AND', strlen($this->searchQuery) - 4);
         $this->searchQuery = substr($this->searchQuery, 0, $pos - 1);
     }
     $user = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser()->getName();
     $recollDirPath = UMManager::getEyeosUserDirectory($user) . '/' . USERS_CONF_DIR . '/' . FRAMEWORK_SEARCH_RECOLL_DIR;
     $result = shell_exec(AdvancedPathLib::realpath(FRAMEWORK_SEARCH_UTILS_PATH) . '/XmlBuilder.pl ' . escapeshellarg(AdvancedPathLib::realpath($recollDirPath)) . ' ' . escapeshellarg($this->searchQuery));
     $xmlResult = simplexml_load_string($result);
     if ($xmlResult) {
         $path = realpath(UMManager::getEyeosUserDirectory($user)) . '/files/';
         foreach ($xmlResult as $node => $markup) {
             if ($node == 'file') {
                 $cleanPath = utf8_substr($markup->path, 7);
                 $cleanPath = 'home://~' . $user . '/' . utf8_substr($cleanPath, strlen($path));
                 $tempFile = array('type' => (string) $markup->type, 'path' => (string) $cleanPath, 'name' => (string) $markup->name, 'size' => (string) $markup->size);
                 $this->results[] = $tempFile;
             } else {
                 if ($node == 'files') {
                     $this->totalFiles = $markup;
                 }
             }
         }
     }
     return array($this->totalFiles, $this->results);
 }
예제 #4
0
 public function checkTokens(SearchQuery $obj)
 {
     // first, we need to retrive all the available tokens.
     $availableTokens = $this->getAvailableTokens();
     // once we did that, we can analyze each token we've received in
     // queryTokens, and try to find if it matches one of the availables
     // token's module we have.
     $queryTokens = $obj->getQueryTokens();
     if ($queryTokens) {
         foreach ($queryTokens as $token => $parameters) {
             if (array_key_exists($token, $availableTokens)) {
                 $tokenObj = new $availableTokens[$token]($queryTokens[$token]);
                 $tokenObj->checkToken($parameters);
                 if (!$tokenObj->getIsValid()) {
                     unset($queryTokens[$token]);
                 }
             } else {
                 unset($queryTokens[$token]);
             }
         }
         $obj->setQueryTokens($queryTokens);
     }
 }