2
2
3
3
namespace Wilr \SilverStripe \Algolia \Service ;
4
4
5
- use Exception ;
6
5
use Psr \Log \LoggerInterface ;
7
6
use SilverStripe \Core \Injector \Injector ;
8
7
use SilverStripe \ORM \ArrayList ;
@@ -23,7 +22,7 @@ class AlgoliaQuerier
23
22
* @param string $selectedIndex
24
23
* @param string $query
25
24
* @param array $searchParameters
26
- * @param array $ORMFilters filter ORM objects prior to returning the results as a PaginatedList
25
+ * @param array $ORMFilters This argument is used to filter ORM objects prior to returning the results as a PaginatedList
27
26
*
28
27
* @return PaginatedList
29
28
*/
@@ -55,13 +54,15 @@ function array_key_first(array $arr)
55
54
}
56
55
57
56
$ records = ArrayList::create ();
57
+ $ totalItems = $ results ['nbHits ' ];
58
58
59
59
if ($ results && isset ($ results ['hits ' ])) {
60
60
foreach ($ results ['hits ' ] as $ hit ) {
61
61
$ className = isset ($ hit ['objectClassName ' ]) ? $ hit ['objectClassName ' ] : null ;
62
62
$ id = isset ($ hit ['objectSilverstripeID ' ]) ? $ hit ['objectSilverstripeID ' ] : null ;
63
63
64
64
if (!$ id || !$ className ) {
65
+ $ totalItems --;
65
66
continue ;
66
67
}
67
68
@@ -70,6 +71,8 @@ function array_key_first(array $arr)
70
71
71
72
if ($ record && $ record ->canView ()) {
72
73
$ records ->push ($ record );
74
+ } else {
75
+ $ totalItems --;
73
76
}
74
77
} catch (Throwable $ e ) {
75
78
Injector::inst ()->get (LoggerInterface::class)->notice ($ e );
@@ -87,15 +90,12 @@ function array_key_first(array $arr)
87
90
88
91
if ($ results ) {
89
92
$ output = $ output ->setCurrentPage ($ results ['page ' ] + 1 )
90
- ->setTotalItems ($ results [ ' nbHits ' ] )
93
+ ->setTotalItems ($ totalItems )
91
94
->setLimitItems (false )
92
95
->setPageStart ($ results ['page ' ] * $ results ['hitsPerPage ' ])
93
96
->setPageLength ($ results ['hitsPerPage ' ]);
94
97
}
95
98
96
- // add raw output from algoia for manipulation
97
- $ output ->raw = $ results ;
98
-
99
99
return $ output ;
100
100
}
101
101
0 commit comments