/**
  * Update the search and request objects
  *
  * @param $command
  */
 public function handle(SaveSearchRequestCommand $command)
 {
     $search = $this->searchRepository->findByQuery($command->queryString());
     if (!$search) {
         // Create a new search object
         $search = new Search();
         $search->setQuery($command->queryString());
     }
     $search->increase();
     // Create the new search request
     $searchRequest = new Request();
     $searchRequest->setSearch($search);
     // Save the changes to the database
     $this->searchRepository->save($search);
     $this->requestRepository->save($searchRequest);
     // Raise the SearchRequestWasPosted event
     $event = new SearchRequestWasPosted($searchRequest);
     $this->eventRecorder->record($event);
 }
Ejemplo n.º 2
0
 /**
  * Retrieve information about a search action
  *
  * @ApiDoc(
  * requirements={
  *      {
  *          "name"="_format",
  *          "dataType"="string",
  *          "requirement"="json|xml",
  *          "description"="Response format"
  *      },
  *      {
  *          "name"="queryString",
  *          "dataType"="string",
  *          "requirement"="double urlencoded base64 string (urlencode(urlencode(base64_encode($queryString)))",
  *          "description"="Search string"
  *      },
  *  },
  * )
  *
  * @param $queryString
  * @return array
  * @View()
  */
 public function getSearchAction($queryString)
 {
     // Get information about searches with this queryString
     $about = $this->searchRepository->findByQuery($queryString);
     if (!$about) {
         // There is never been a search request with this string
         // So create an empty Search object and return that
         $about = new Search();
         $about->setQuery($queryString);
     }
     return ['result' => $about];
 }