client = $client; } /** * Displays simple search form. */ public function index(Request $request): View { if (Input::has('q')) { // Create a search query $query = $this->client->createSelect(); // Set the query string if (Input::get('q') != "") { $query->setQuery('%P1%', array(Input::get('q'))); } else { $query = $this->client->createQuery($this->client::QUERY_SELECT); } // Execute the query and return the result $resultset = $this->client->select($query); // Pass the resultset to the view and return. return view('frontend.search.index', array( 'q' => Input::get('q'), 'resultset' => $resultset, )); } return view('frontend.search.index'); } public function ping() { // create a ping query $ping = $this->client->createPing(); // execute the ping query try { $this->client->ping($ping); return response()->json('OK'); } catch (\Solarium\Exception $e) { return response()->json('ERROR', 500); } } public function search() { $filter = "test"; //$request->input('query'); // get a select query instance $query = $this->client->createSelect(); // $query = $this->client->createSelect(); $query->setQuery('title:'. $filter); // set a query (all prices starting from 12) // $query->setQuery('price:[12 TO *]'); // set start and rows param (comparable to SQL limit) using fluent interface //$query->setStart(2)->setRows(20); // this executes the query and returns the result $resultset = $this->client->select($query); // display the total number of documents found by solr $response = 'NumFound: ' . $resultset->getNumFound(); // show documents using the resultset iterator foreach ($resultset as $document) { $response = $response . '
'; $response = $response . ''; $response = $response . ''; $response = $response . ''; $response = $response . '
id' . $document->id . '
title' . $document->title_output . '
abstract' . $document->abstract_output . '
'; } echo $response; } }