diff --git a/app/Http/Controllers/Frontend/SolariumController.php b/app/Http/Controllers/Frontend/SolariumController.php index 14ef8d7..4cf7312 100644 --- a/app/Http/Controllers/Frontend/SolariumController.php +++ b/app/Http/Controllers/Frontend/SolariumController.php @@ -4,8 +4,8 @@ namespace App\Http\Controllers\Frontend; use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use Illuminate\View\View; use Illuminate\Support\Facades\Input; +use Illuminate\View\View; class SolariumController extends Controller { @@ -21,26 +21,54 @@ class SolariumController extends Controller */ public function index(Request $request): View { - if (Input::has('q')) { + if (Input::has('q') && Input::get('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); + + // if (Input::get('q') != "") { + // // $query->setQuery(Input::get('q')); + // //better use placeholder to escape the search phrase: + // $query->setQuery('%P1%', array(Input::get('q'))); + // } else { + // $query = $this->client->createQuery($this->client::QUERY_SELECT); + // } + + //Set the query string + //$query->setQuery(Input::get('q')); + $query->setQuery('%P1%', array(Input::get('q'))); + + + // Create a DisMax query + $dismax = $query->getDisMax(); + // Set the fields to query, and their relative weights + $dismax->setQueryFields('title^3 abstract^2 subject^1'); + + $facetSet = $query->getFacetSet(); + $facetSet->createFacetField('year')->setField('year'); + $facetSet->createFacetField('language')->setField('language'); + $facetSet->createFacetField('datatype')->setField('doctype'); + + + if (Input::has('year')) { + $query->createFilterQuery('year')->setQuery(sprintf('year:%s', Input::get('year'))); } - + if (Input::has('language')) { + $query->createFilterQuery('language')->setQuery(sprintf('language:%s', Input::get('language'))); + } + if (Input::has('datatype')) { + $query->createFilterQuery('datatype')->setQuery(sprintf('doctype:%s', Input::get('datatype'))); + } + // 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, )); } + // No query to execute, just return the search form. return view('frontend.search.index'); } @@ -66,7 +94,7 @@ class SolariumController extends Controller $query = $this->client->createSelect(); // $query = $this->client->createSelect(); - $query->setQuery('title:'. $filter); + $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 @@ -78,11 +106,11 @@ class SolariumController extends Controller $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 . '
'; + $response = $response . '
'; + $response = $response . ''; + $response = $response . ''; + $response = $response . ''; + $response = $response . '
id' . $document->id . '
title' . $document->title_output . '
abstract' . $document->abstract_output . '
'; } echo $response; } diff --git a/database/seeds/MimetypeTableSeeder.php b/database/seeds/MimetypeTableSeeder.php index e39f693..d250a87 100644 --- a/database/seeds/MimetypeTableSeeder.php +++ b/database/seeds/MimetypeTableSeeder.php @@ -4,7 +4,6 @@ use Carbon\Carbon; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; - class MimetypeTableSeeder extends Seeder { public function run() diff --git a/resources/views/frontend/search/index.blade.php b/resources/views/frontend/search/index.blade.php index 7970e08..8a5b4e0 100644 --- a/resources/views/frontend/search/index.blade.php +++ b/resources/views/frontend/search/index.blade.php @@ -11,75 +11,141 @@

SEARCH

-
+ +
+ @if (isset($resultset)) -
-

Your search yielded {{ $resultset->getNumFound() }} results:

-
-
-
-
    - @foreach ($resultset as $document) +
    +
    +

    Refine by

    + getFacetSet()->getFacet('language'); ?> +
    -
  • -
    -
    -

    - - {{ $document->title_output }} - -

    -
    -
    - {{ date('D, m M, Y', $document->server_date_modified) }} -
    + {{--

    Language

    --}} +

    Language

    - -
    - - @if (is_array($document->author)) - Author: {{ implode(', ', $document->author) }} +
      + @foreach ($facet as $value => $count) + @if ($count) +
    • + {{ $value }} + {{ $count }} +
    • @endif - -

      - Abstract: {{ $document->abstract_output }} -

      -
    - - + @endforeach +
- - @endforeach - + getFacetSet()->getFacet('datatype'); ?> +
+ {{--

Datatype

--}} +

Data Type

+
    + @foreach ($facet as $value => $count) + @if ($count) +
  • + {{ $value }} + {{ $count }} +
  • + @endif + @endforeach +
+
+ + getFacetSet()->getFacet('year'); ?> +
+

Year

+ +
    + @foreach ($facet as $value => $count) + @if ($count) +
  • + {{ $value }} + {{ $count }} +
  • + @endif + @endforeach +
+
+
+
+ +
+ @if (isset($resultset)) +
+

Your search yielded {{ $resultset->getNumFound() }} results:

+
+
+ +
+ +
+ @endif +
@endif - @@ -89,6 +155,132 @@ @section('head') -@endsection - +@endsection \ No newline at end of file