File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 33namespace arnoson ;
44
55use Kirby \Cms \Collection ;
6+ use Kirby \Cms \Page ;
67use Kirby \Cms \Pagination ;
78use Loupe \Loupe \SearchResult ;
89
910class KirbyLoupeCollection extends Collection {
11+ private array $ hitsByUuid = [];
12+
1013 public function __construct (protected SearchResult $ searchResult ) {
1114 parent ::__construct ();
1215 foreach ($ searchResult ->getHits () as $ hit ) {
13- $ this ->append (page ($ hit ["uuid " ]));
16+ $ uuid = $ hit ["uuid " ];
17+ $ this ->hitsByUuid [$ uuid ] = $ hit ;
18+ $ this ->append (page ($ uuid ));
1419 }
1520 }
1621
1722 public function searchResult () {
1823 return $ this ->searchResult ;
1924 }
2025
26+ /**
27+ * Get the raw search hit from Loupe for the specified page.
28+ */
29+ public function hit (Page $ page ) {
30+ return $ this ->hitsByUuid [$ page ->uuid ()->toString ()];
31+ }
32+
33+ /**
34+ * Get the formatted attributes from Loupe for the specified page.
35+ */
36+ public function formatted (Page $ page ) {
37+ return $ this ->hitsByUuid [$ page ->uuid ()->toString ()];
38+ }
39+
2140 public function paginate (...$ arguments ) {
2241 // The original Collection class uses Pagination::for() which will
2342 // automatically set the total parameter based on the collection length
You can’t perform that action at this time.
0 commit comments