solraium faceted search

This commit is contained in:
Arno Kaimbacher 2019-09-25 18:51:36 +02:00
parent 024002eded
commit 9855c235b7
3 changed files with 289 additions and 71 deletions

View File

@ -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,15 +21,42 @@ 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
@ -41,6 +68,7 @@ class SolariumController extends Controller
'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 . '<hr/><table>';
$response = $response . '<tr><th>id</th><td>' . $document->id . '</td></tr>';
$response = $response . '<tr><th>title</th><td>' . $document->title_output . '</td></tr>';
$response = $response . '<tr><th>abstract</th><td>' . $document->abstract_output . '</td></tr>';
$response = $response . '</table>';
$response = $response . '<hr/><table>';
$response = $response . '<tr><th>id</th><td>' . $document->id . '</td></tr>';
$response = $response . '<tr><th>title</th><td>' . $document->title_output . '</td></tr>';
$response = $response . '<tr><th>abstract</th><td>' . $document->abstract_output . '</td></tr>';
$response = $response . '</table>';
}
echo $response;
}

View File

@ -4,7 +4,6 @@ use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class MimetypeTableSeeder extends Seeder
{
public function run()

View File

@ -11,75 +11,141 @@
<h3 class="separator">SEARCH</h3>
</div>
</div>
<div class="row">
<!-- SEARCH RESULTS GO HERE, EXACTLY AS BEFORE -->
<div class="content">
<div class="sidebar-simplesearch">
{{ Form::open(array('method' => 'GET')) }}
<div class="twelve columns">
<div class="content">
<div class="sidebar-simplesearch">
{{ Form::open(array('method' => 'GET')) }}
{!! Form::text('q', Input::get('q'), array('class'=>'u-full-width',
'placeholder'=>'Enter your search term')) !!}
<span class="input-group-btn">
{{-- {{ Form::submit('Search', array('class' => 'btn btn-primary btn-lg')) }} --}}
<button type="submit">
<i class="fa fa-search"></i>
</button>
</span>
{!! Form::text('q', Input::get('q'), array('class'=>'u-full-width',
'placeholder'=>'Enter your search term')) !!}
<span class="input-group-btn">
{{-- {{ Form::submit('Search', array('class' => 'btn btn-primary btn-lg')) }} --}}
<button type="submit">
<i class="fa fa-search"></i>
</button>
</span>
{{ Form::close() }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
@if (isset($resultset))
<header>
<p>Your search yielded <strong>{{ $resultset->getNumFound() }}</strong> results:</p>
<hr />
</header>
<div class="row">
<ul class="search-items isotope js-isotope u-cf">
@foreach ($resultset as $document)
<div class="four columns">
<div id="left-bar">
<h3 class="indexheader">Refine by</h3>
<?php $facet = $resultset->getFacetSet()->getFacet('language'); ?>
<div class="panel panel-primary">
<li>
<div class="post">
<header class="post-header">
<h3 class="post-title">
<a href="{{ URL::route('frontend.dataset.show',['id' =>$document->id]) }}">
{{ $document->title_output }}
</a>
</h3>
</header>
<div class="blog-meta">
{{ date('D, m M, Y', $document->server_date_modified) }}
</div>
{{-- <h3 class="panel-title">Language</h3> --}}
<h3 class="filterViewModelName">Language</h3>
<div class="post-description">
@if (is_array($document->author))
<em>Author: {{ implode(', ', $document->author) }}</em>
<ul class="filterItems">
@foreach ($facet as $value => $count)
@if ($count)
<li class="list-group-item">
<a class="firstLabel"
href="?{{ http_build_query(array_merge(Input::all(), array('language' => $value))) }}">{{ $value }}</a>
<span class="badge">{{ $count }}</span>
</li>
@endif
<p>
<em>Abstract: {{ $document->abstract_output }}</em>
</p>
</div>
@endforeach
</ul>
</div>
</li>
@endforeach
</ul>
<?php $facet = $resultset->getFacetSet()->getFacet('datatype'); ?>
<div class="panel panel-primary">
{{-- <h3 class="panel-title">Datatype</h3> --}}
<h3 class="filterViewModelName">Data Type</h3>
<ul class="filterItems">
@foreach ($facet as $value => $count)
@if ($count)
<li class="list-group-item">
<a class="firstLabel"
href="?{{ http_build_query(array_merge(Input::all(), array('datatype' => $value))) }}">{{ $value }}</a>
<span class="badge">{{ $count }}</span>
</li>
@endif
@endforeach
</ul>
</div>
<?php $facet = $resultset->getFacetSet()->getFacet('year'); ?>
<div class="panel panel-primary">
<h3 class="filterViewModelName">Year</h3>
<ul class="filterItems">
@foreach ($facet as $value => $count)
@if ($count)
<li class="list-group-item">
<a class="firstLabel"
href="?{{ http_build_query(array_merge(Input::all(), array('year' => $value))) }}">{{ $value }}</a>
<span class="badge">{{ $count }}</span>
</li>
@endif
@endforeach
</ul>
</div>
</div>
</div>
<div class="eight columns">
@if (isset($resultset))
<header>
<p>Your search yielded <strong>{{ $resultset->getNumFound() }}</strong> results:</p>
<hr />
</header>
<section class="results normal">
<ul class="search-items isotope js-isotope u-cf">
@foreach ($resultset as $document)
<li>
<div class="post">
<header class="post-header">
<h3 class="post-title">
<a href="{{ URL::route('frontend.dataset.show',['id' =>$document->id]) }}">
{{ $document->title_output }}
</a>
</h3>
</header>
<div class="blog-meta">
{{ date('D, m M, Y', $document->server_date_modified) }}
</div>
@if (isset($document->title_additional) && is_array($document->title_additional))
<div class="blog-meta">
<em>Additional Title: {{ implode('; ', $document->title_additional) }}</em>
</div>
@endif
<div class="post-description">
@if (is_array($document->author))
<em>Author: {{ implode('; ', $document->author) }}</em>
@endif
<p>
<em>Abstract: {{ $document->abstract_output }}</em>
</p>
<p>
<em>Creating Corporation: {{ $document->creating_corporation }}</em>
</p>
</div>
</div>
</li>
@endforeach
</ul>
</section>
@endif
</div>
</div>
@endif
</div>
</section>
@ -89,6 +155,132 @@
@section('head')
<style>
*-------------------------------------------------- */
/* lists in the left bar */
/*-------------------------------------------------- */
.overflowing {
color: #444444;
list-style: none;
}
.overflowing span {
color: #444444;
font-style: italic;
text-decoration: underline;
cursor: pointer;
}
ul.filterItems li {
min-height: 15px;
color: #444;
font-size: 12px;
list-style-type: disc;
/*list-style-position:inside;*/
/*
* We want the bullets outside of the list,
* so the text is aligned. Now the actual bullet
* is outside of the lists container
*/
list-style-position: outside;
/*
* Because the bullet is outside of the lists
* container, indent the list entirely
*/
margin-left: 1em;
}
.filterItems.limited li:nth-of-type(1n+6) {
display: none;
}
ul.filterItems .active {
background-color: lightgray;
}
/*ul.filterItems li.hover{
background-color: yellow;
}*/
/*ul.filterItems li.hover .firstLabel,
ul.filterItems li.hover a{
color: #0099cc;
cursor:pointer;
}*/
/*ul.filterItems span.hover {
color: #0099cc;
cursor:pointer;
}*/
ul.filterItems li a:hover {
color: #0099cc;
cursor: pointer;
}
/* Relativer Tooltip */
.tooltip {
position: relative;
text-decoration: none;
font-weight: bolder;
color: #444444;
cursor: pointer;
overflow: visible;
font-size: 8px;
}
.sidebar.left {
background-color: rgb(244, 244, 244);
float: left;
border-left: none;
width: 250px;
height: 100%;
overflow-y: auto;
}
/* #left-bar {
position:absolute;
height:auto;
width:auto;
bottom:0;
top:0;
left:0;
right:0;
margin: 15px;
} */
.sidebar.right {
border: none;
margin-left: 250px;
background-color: white;
}
#left-bar .indexheader {
color: #a9a9a9;
font-weight: bold;
display: block;
}
#left-bar .filterViewModelName {
color: black;
margin-top: 10px;
margin-bottom: 2px;
/* font-size: 12px; */
display: block;
font-weight: bold;
}
.sidebar-simplesearch {
position: relative;
margin-bottom: 2.5em;
@ -111,4 +303,3 @@
</style>
@endsection