Skip to content

Commit

Permalink
Use default suggester component
Browse files Browse the repository at this point in the history
  • Loading branch information
frank-ulrich-weber committed Jul 25, 2024
1 parent 621f939 commit a73cecc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
22 changes: 10 additions & 12 deletions Classes/Middleware/SearchSuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
{
$response = $handler->handle($request);
// Get input parameters and decrypt core name.
$parameters = $request->getQueryParams();
$parameters = $request->getParsedBody();
// Return if not this middleware
if (!isset($parameters['middleware']) || ($parameters['middleware'] != 'dlf/search-suggest')) {
return $response;
Expand All @@ -61,18 +61,16 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
// Perform Solr query.
$solr = Solr::getInstance($solrCore);
if ($solr->ready) {
$query = $solr->service->createSelect();
$query->setHandler('suggest');
$query = $solr->service->createSuggester();
$query->setQuery(Solr::escapeQuery((string) $parameters['q']));
$query->setRows(0);
$results = $solr->service->select($query)->getResponse()->getBody();
$result = json_decode($results);
if (is_iterable($result->spellcheck->suggestions)) {
foreach ($result->spellcheck->suggestions as $suggestions) {
if (is_object($suggestions)) {
foreach ($suggestions->suggestion as $suggestion) {
$output[] = $suggestion;
}
$query->setCount(10);
$results = $solr->service->suggester($query);
foreach ($results as $termResult) {
foreach ($termResult as $termSuggestions) {
$suggestions = $termSuggestions->getSuggestions();
foreach($suggestions as $suggestion)
{
$output[] = $suggestion['term'];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Configuration/ApacheSolr/configsets/dlf/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ limitations under the License.
<field name="default" type="standard" indexed="true" stored="false" required="true" multiValued="true" default="" />
<field name="timestamp" type="date" indexed="true" stored="true" required="true" multiValued="false" default="NOW" />
<!-- Autocomplete field for search form. -->
<field name="autocomplete" type="autocomplete" indexed="true" stored="false" multiValued="true" />
<field name="autocomplete" type="autocomplete" indexed="true" stored="true" multiValued="true" />
<!-- Fulltext field for OCR results. -->
<field name="fulltext" type="text_ocr" indexed="true" stored="true" multiValued="false" default="" termVectors="true" termPositions="true" termOffsets="true" />
<!-- Record ID of the document (required for OAI_DC output). -->
Expand Down
31 changes: 16 additions & 15 deletions Configuration/ApacheSolr/configsets/dlf/conf/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,11 @@
-->

<!-- Autocomplete Handler -->
<requestHandler name="/suggest" class="org.apache.solr.handler.component.SearchHandler">
<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggest</str>
<str name="spellcheck.count">10</str>
<str name="spellcheck.onlyMorePopular">true</str>
<str name="suggest.dictionary">suggest</str>
<str name="suggest">true</str>
<str name="suggest.count">10</str>
</lst>
<arr name="components">
<str>suggest</str>
Expand All @@ -725,16 +724,18 @@
<searchComponent class="solrocr.OcrHighlightComponent" name="ocrHighlight" />

<!-- Autocomplete Component -->
<searchComponent name="suggest" class="solr.SpellCheckComponent">
<lst name="spellchecker">
<str name="name">suggest</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.fst.FSTLookup</str>
<str name="buildOnCommit">true</str>
<str name="field">autocomplete</str>
<str name="queryAnalyzerFieldType">autocomplete</str>
</lst>
</searchComponent>
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">suggest</str>
<str name="lookupImpl">FuzzyLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">autocomplete</str>
<str name="suggestAnalyzerFieldType">autocomplete</str>
<str name="buildOnStartup">false</str>
<str name="buildOnCommit">false</str>
<str name="buildOnOptimize">false</str>
</lst>
</searchComponent>

<schemaFactory class="ClassicIndexSchemaFactory"/>

Expand Down

0 comments on commit a73cecc

Please sign in to comment.