Example #1
0
 /**
  * Lazy load config object
  * 
  * @return Config
  */
 public function config()
 {
     if (!$this->config instanceof Config) {
         $this->config = Config::getInstance();
     }
     return $this->config;
 }
Example #2
0
 /**
  * Check spelling
  * 
  * @param array of QueryTerms $query_terms
  */
 public function checkSpelling(array $query_terms)
 {
     $config = Config::getInstance();
     $id = $config->getConfig("SUMMON_ID", false);
     $key = $config->getConfig("SUMMON_KEY", false);
     $suggestion = new Suggestion();
     if ($id != null && $key != null) {
         $client = new SummonClient($id, $key, Factory::getHttpClient());
         // @todo: see if we can't collapse multiple terms into a single spellcheck query
         foreach ($query_terms as $term_original) {
             $term = clone $term_original;
             $query = $term->phrase;
             $query = urlencode(trim($query));
             $correction = null;
             // get spell suggestion
             try {
                 $correction = $client->checkSpelling($query);
             } catch (\Exception $e) {
                 throw $e;
                 // @todo: remove after testing
                 trigger_error('Could not process spelling suggestion: ' . $e->getTraceAsString(), E_USER_WARNING);
             }
             // got one
             if ($correction != null) {
                 $term->phrase = $correction;
                 $suggestion->addTerm($term);
             }
         }
     }
     return $suggestion;
 }
Example #3
0
 /**
  * @return Config
  */
 public function getConfig()
 {
     return Config::getInstance();
 }