Skip to content

Commit 8c832c4

Browse files
aertmannskurfuerst
authored andcommitted
[TASK] Improve output to something useful
- Adds summary from the fulltext using highlighting - Adds pagination of results - Adds breadcrumb for each result - Wraps output in container for styling This change has originally been based upon mocdk@c326730.
1 parent 7167c20 commit 8c832c4

7 files changed

Lines changed: 87 additions & 28 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
namespace Flowpack\SearchPlugin\EelHelper;
3+
4+
/* *
5+
* This script belongs to the TYPO3 Flow package "Flowpack.SearchPlugin". *
6+
* *
7+
* It is free software; you can redistribute it and/or modify it under *
8+
* the terms of the GNU Lesser General Public License, either version 3 *
9+
* of the License, or (at your option) any later version. *
10+
* *
11+
* The TYPO3 project - inspiring people to share! *
12+
* */
13+
use TYPO3\Flow\Annotations as Flow;
14+
use TYPO3\Eel\ProtectedContextAwareInterface;
15+
16+
/**
17+
* Additional Array Helpers which might once
18+
*
19+
* @Flow\Proxy(false)
20+
*/
21+
class SearchArrayHelper implements ProtectedContextAwareInterface {
22+
23+
/**
24+
* Concatenate arrays or values to a new array
25+
*
26+
* @param array|mixed $array1 First array or value
27+
* @param array|mixed $array2 Second array or value
28+
* @param array|mixed $array_ Optional variable list of additional arrays / values
29+
* @return array The array with concatenated arrays or values
30+
*/
31+
public function flatten($arrays) {
32+
$return = array();
33+
array_walk_recursive($arrays, function($a) use (&$return) { $return[] = $a; });
34+
return $return;
35+
}
36+
37+
/**
38+
* All methods are considered safe
39+
*
40+
* @param string $methodName
41+
* @return boolean
42+
*/
43+
public function allowsCallOfMethod($methodName) {
44+
return TRUE;
45+
}
46+
47+
}

Classes/Flowpack/SearchPlugin/TypoScriptObjects/CanRenderImplementation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
/* *
6-
* This script belongs to the TYPO3 Flow package "Flowpack.SearchPlugin.TypoScriptObjects". *
6+
* This script belongs to the TYPO3 Flow package "Flowpack.SearchPlugin". *
77
* *
88
* It is free software; you can redistribute it and/or modify it under *
99
* the terms of the GNU Lesser General Public License, either version 3 *

Configuration/Settings.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ TYPO3:
22
Neos:
33
typoScript:
44
autoInclude:
5-
'Flowpack.SearchPlugin': TRUE
5+
'Flowpack.SearchPlugin': TRUE
6+
7+
TypoScript:
8+
defaultContext:
9+
Flowpack.SearchPlugin.Array: 'Flowpack\SearchPlugin\EelHelper\SearchArrayHelper'
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{namespace neos=TYPO3\Neos\ViewHelpers}
22
{namespace ts=TYPO3\TypoScript\ViewHelpers}
3+
{namespace search=TYPO3\TYPO3CR\Search\ViewHelpers}
4+
<div{attributes -> f:format.raw()}>
5+
{searchForm -> f:format.raw()}
36

4-
{searchForm -> f:format.raw()}
5-
6-
Showing {searchResults -> f:count()} of {totalSearchResults} results
7-
8-
{searchResultRenderer -> f:format.raw()}
7+
<f:if condition="{searchQuery}">
8+
<search:widget.paginate query="{searchQuery}" as="results">
9+
Showing {results.accessibleCount} of {totalSearchResults} results
10+
<ts:render path="searchResultRenderer" context="{searchResults: results}" />
11+
</search:widget.paginate>
12+
</f:if>
13+
</div>
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
{namespace neos=TYPO3\Neos\ViewHelpers}
2+
<neos:link.node node="{node}">{title}</neos:link.node>
23

3-
<b><neos:link.node node="{node}">
4-
{title}
5-
</neos:link.node></b><br />
4+
<f:if condition="{highlight}">
5+
<p>
6+
<f:for each="{highlight}" as="fragment" iteration="fragmentIterator">
7+
{fragment -> f:format.raw()}{f:if(condition: fragmentIterator.isLast, else: '...')}
8+
</f:for>
9+
</p>
610

7-
<f:if condition="{description}">
8-
{description}
11+
<div class="breadcrumb">
12+
<span>Path:</span>
13+
<f:for each="{parents}" as="parent">
14+
<neos:link.node node="{parent}" />
15+
</f:for>
16+
<neos:link.node node="{node}" />
17+
</div>
918
</f:if>

Resources/Private/TypoScript/ResultRendering.ts2

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ prototype(Flowpack.SearchPlugin:SingleResult) < prototype(TYPO3.TypoScript:Case)
1515
prototype(TYPO3.Neos:DocumentSearchResult) < prototype(TYPO3.TypoScript:Template) {
1616
templatePath = 'resource://Flowpack.SearchPlugin/Private/Templates/SearchResult/DocumentSearchResult.html'
1717
node = ${node}
18+
highlight = ${Flowpack.SearchPlugin.Array.flatten(searchHit.highlight)}
1819

1920
title = ${q(node).property('title')}
2021
description = ''
22+
parents = ${Array.reverse(q(node).parents('[instanceof TYPO3.Neos:Document]').get())}
2123
}
2224

23-
prototype(TYPO3.Neos.NodeTypes:PageSearchResult) < prototype(TYPO3.Neos:DocumentSearchResult)
24-
25-
26-
prototype(TYPO3.NeosDemoTypo3Org:ChapterSearchResult) < prototype(TYPO3.Neos:DocumentSearchResult) {
27-
description = ${q(node).property('chapterDescription')}
28-
}
25+
prototype(TYPO3.Neos.NodeTypes:PageSearchResult) < prototype(TYPO3.Neos:DocumentSearchResult)
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
21
prototype(Flowpack.SearchPlugin:Search) {
32

4-
// we store the search results in the TypoScript context, so that they bubble through the nested elements like the searchResultRenderer
5-
@override.searchResults = ${this.searchQuery.execute()}
6-
7-
8-
searchQuery = ${Search.query(site).fulltext(request.arguments.search || '')}
3+
searchTerm = ${request.arguments.search}
4+
searchQuery = ${this.searchTerm ? Search.query(site).fulltext(this.searchTerm) : null}
95

106
totalSearchResults = ${this.searchQuery.count()}
11-
searchResults = ${searchResults}
127

138
searchForm = Flowpack.SearchPlugin:Search.Form
149

1510
searchResultRenderer = TYPO3.TypoScript:Collection {
11+
// the "searchResults" are filled from the <search:widget.paginate> ViewHelper.
1612
collection = ${searchResults}
1713
itemRenderer = Flowpack.SearchPlugin:SingleResult
1814
itemName = 'node'
15+
// we also make the full ElasticSearch hit available to nested rendering, if possible
16+
itemRenderer.@override.searchHit = ${searchResults.searchHitForNode(node)}
1917
}
2018

21-
searchResultRenderer.@process.wrap = ${'<ul>' + value + '</ul>'}
19+
searchResultRenderer.@process.wrap = ${'<ol>' + value + '</ol>'}
2220
prototype(Flowpack.SearchPlugin:SingleResult).@process.wrap = ${'<li>' + value + '</li>'}
2321

2422
@cache {
@@ -34,5 +32,4 @@ prototype(Flowpack.SearchPlugin:Search) {
3432
prototype(Flowpack.SearchPlugin:Search.Form) < prototype(TYPO3.TypoScript:Template) {
3533
templatePath = 'resource://Flowpack.SearchPlugin/Private/Templates/NodeTypes/Search.Form.html'
3634
searchWord = ${request.arguments.search}
37-
}
38-
35+
}

0 commit comments

Comments
 (0)