Ejemplo n.º 1
0
 public function makemodel()
 {
     $query = Input::get('query', '');
     $make = '';
     $model = '';
     $suggestion = SearchSuggestion::where('suggestion', '=', strtoupper($query));
     if ($suggestion->count()) {
         $make = $suggestion->first()->make;
         if ($suggestion->first()->model > 0) {
             $model = $suggestion->first()->model;
         }
     }
     $zip_code = Session::get('zip_code', '');
     $distance = Session::get('distance', '50');
     $data = array("make" => $make, "model" => $model, "zip_code" => $zip_code, "distance" => $distance);
     return Response::json($data);
 }
Ejemplo n.º 2
0
 /**
  * Process completion search results.
  * Resolves the titles and rescores.
  * @param SearchSuggestionSet $suggestions
  * @return SearchSuggestionSet
  */
 protected function processCompletionResults($search, SearchSuggestionSet $suggestions)
 {
     $search = trim($search);
     // preload the titles with LinkBatch
     $titles = $suggestions->map(function (SearchSuggestion $sugg) {
         return $sugg->getSuggestedTitle();
     });
     $lb = new LinkBatch($titles);
     $lb->setCaller(__METHOD__);
     $lb->execute();
     $results = $suggestions->map(function (SearchSuggestion $sugg) {
         return $sugg->getSuggestedTitle()->getPrefixedText();
     });
     if ($this->offset === 0) {
         // Rescore results with an exact title match
         // NOTE: in some cases like cross-namespace redirects
         // (frequently used as shortcuts e.g. WP:WP on huwiki) some
         // backends like Cirrus will return no results. We should still
         // try an exact title match to workaround this limitation
         $rescorer = new SearchExactMatchRescorer();
         $rescoredResults = $rescorer->rescore($search, $this->namespaces, $results, $this->limit);
     } else {
         // No need to rescore if offset is not 0
         // The exact match must have been returned at position 0
         // if it existed.
         $rescoredResults = $results;
     }
     if (count($rescoredResults) > 0) {
         $found = array_search($rescoredResults[0], $results);
         if ($found === false) {
             // If the first result is not in the previous array it
             // means that we found a new exact match
             $exactMatch = SearchSuggestion::fromTitle(0, Title::newFromText($rescoredResults[0]));
             $suggestions->prepend($exactMatch);
             $suggestions->shrink($this->limit);
         } else {
             // if the first result is not the same we need to rescore
             if ($found > 0) {
                 $suggestions->rescore($found);
             }
         }
     }
     return $suggestions;
 }
Ejemplo n.º 3
0
 /**
  * Process completion search results.
  * Resolves the titles and rescores.
  * @param SearchSuggestionSet $suggestions
  * @return SearchSuggestionSet
  */
 protected function processCompletionResults($search, SearchSuggestionSet $suggestions)
 {
     if ($suggestions->getSize() == 0) {
         // If we don't have anything, don't bother
         return $suggestions;
     }
     $search = trim($search);
     // preload the titles with LinkBatch
     $titles = $suggestions->map(function (SearchSuggestion $sugg) {
         return $sugg->getSuggestedTitle();
     });
     $lb = new LinkBatch($titles);
     $lb->setCaller(__METHOD__);
     $lb->execute();
     $results = $suggestions->map(function (SearchSuggestion $sugg) {
         return $sugg->getSuggestedTitle()->getPrefixedText();
     });
     // Rescore results with an exact title match
     $rescorer = new SearchExactMatchRescorer();
     $rescoredResults = $rescorer->rescore($search, $this->namespaces, $results, $this->limit);
     if (count($rescoredResults) > 0) {
         $found = array_search($rescoredResults[0], $results);
         if ($found === false) {
             // If the first result is not in the previous array it
             // means that we found a new exact match
             $exactMatch = SearchSuggestion::fromTitle(0, Title::newFromText($rescoredResults[0]));
             $suggestions->prepend($exactMatch);
             $suggestions->shrink($this->limit);
         } else {
             // if the first result is not the same we need to rescore
             if ($found > 0) {
                 $suggestions->rescore($found);
             }
         }
     }
     return $suggestions;
 }
Ejemplo n.º 4
0
 public function setSuggestions($car, $make, $model)
 {
     if (strlen(trim($make)) > 0 && strlen(trim($model)) > 0) {
         $records = DB::select(DB::raw("SELECT * FROM search_suggestion WHERE suggestion = :record"), array('record' => $make));
         if (count($records) == 0) {
             $suggestion = new SearchSuggestion();
             $suggestion->suggestion = $make;
             $suggestion->make = $car->make;
             $suggestion->model = 0;
             $suggestion->rank = 1;
             $suggestion->save();
         }
         $make_model = $make . ' ' . $model;
         $records = DB::select(DB::raw("SELECT * FROM search_suggestion WHERE suggestion = :record"), array('record' => $make_model));
         if (count($records) == 0) {
             $suggestion = new SearchSuggestion();
             $suggestion->suggestion = $make_model;
             $suggestion->make = $car->make;
             $suggestion->model = $car->model;
             $suggestion->rank = 2;
             $suggestion->save();
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Builds a new set of suggestion based on a string array.
  *
  * NOTE: Suggestion scores will be generated.
  *
  * @param string[] $titles
  * @return SearchSuggestionSet
  */
 public static function fromStrings(array $titles)
 {
     $score = count($titles);
     $suggestions = array_map(function ($title) use(&$score) {
         return SearchSuggestion::fromText($score--, $title);
     }, $titles);
     return new SearchSuggestionSet($suggestions);
 }