From 0651eae7ecdeb3b0781ed1231d601d936603e07d Mon Sep 17 00:00:00 2001 From: Dan Brown <ssddanbrown@googlemail.com> Date: Sun, 26 Mar 2017 19:34:53 +0100 Subject: [PATCH] Improve efficiency of single entity search indexing --- app/Services/SearchService.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Services/SearchService.php b/app/Services/SearchService.php index ae8dd008a..ef11de728 100644 --- a/app/Services/SearchService.php +++ b/app/Services/SearchService.php @@ -100,7 +100,11 @@ class SearchService $nameTerms = $this->generateTermArrayFromText($entity->name, 5); $bodyTerms = $this->generateTermArrayFromText($entity->getText(), 1); $terms = array_merge($nameTerms, $bodyTerms); - $entity->searchTerms()->createMany($terms); + foreach ($terms as $index => $term) { + $terms[$index]['entity_type'] = $entity->getMorphClass(); + $terms[$index]['entity_id'] = $entity->id; + } + $this->searchTerm->newQuery()->insert($terms); } /** @@ -121,7 +125,7 @@ class SearchService $chunkedTerms = array_chunk($terms, 500); foreach ($chunkedTerms as $termChunk) { - $this->searchTerm->insert($termChunk); + $this->searchTerm->newQuery()->insert($termChunk); } }