@@ -243,7 +243,12 @@ public function paginate(Builder $builder, $perPage, $page)
243243 */
244244 protected function performSearch (Builder $ builder , array $ options = []): mixed
245245 {
246- $ documents = $ this ->getOrCreateCollectionFromModel ($ builder ->model , false )->getDocuments ();
246+ $ documents = $ this ->getOrCreateCollectionFromModel (
247+ $ builder ->model ,
248+ $ builder ->index ,
249+ false ,
250+ )->getDocuments ();
251+
247252
248253 if ($ builder ->callback ) {
249254 return call_user_func ($ builder ->callback , $ documents , $ builder ->query , $ options );
@@ -591,16 +596,19 @@ public function deleteIndex($name)
591596 * Get collection from model or create new one.
592597 *
593598 * @param \Illuminate\Database\Eloquent\Model $model
594- * @return TypesenseCollection
599+ * @return \Typesense\Collection
595600 *
596601 * @throws \Typesense\Exceptions\TypesenseClientError
597602 * @throws \Http\Client\Exception
598603 */
599- protected function getOrCreateCollectionFromModel ($ model , bool $ indexOperation = true ): TypesenseCollection
604+ protected function getOrCreateCollectionFromModel ($ model , ? string $ collectionName = null , bool $ indexOperation = true ): TypesenseCollection
600605 {
601- $ method = $ indexOperation ? 'indexableAs ' : 'searchableAs ' ;
606+ if (! $ indexOperation ) {
607+ $ collectionName = $ collectionName ?? $ model ->searchableAs ();
608+ } else {
609+ $ collectionName = $ model ->indexableAs ();
610+ }
602611
603- $ collectionName = $ model ->{$ method }();
604612 $ collection = $ this ->typesense ->getCollections ()->{$ collectionName };
605613
606614 if (! $ indexOperation ) {
0 commit comments