Skip to content

Commit 3a51c96

Browse files
committed
Fixed duplicate entry for search queries
1 parent 97ab031 commit 3a51c96

File tree

2 files changed

+2
-35
lines changed

2 files changed

+2
-35
lines changed

resources/js/components/Search/Autocomplete.vue

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -159,33 +159,6 @@ export default {
159159
160160
return extraFilters
161161
},
162-
163-
getMiddlewares() {
164-
let middlewares = InstantSearchMixin.methods.getMiddlewares.bind(this).call()
165-
166-
const stateChanged = useDebounceFn((changes) => {
167-
const query = Object.entries(changes.uiState).find(([id, state]) => {
168-
return state?.query
169-
})?.[1]?.query
170-
171-
if (!query) {
172-
return
173-
}
174-
175-
rapidezAPI('post', '/search', {
176-
q: query,
177-
})
178-
}, 3000)
179-
180-
return [
181-
...middlewares,
182-
() => ({
183-
onStateChange(changes) {
184-
stateChanged(changes)
185-
},
186-
}),
187-
]
188-
},
189162
},
190163
}
191164
</script>

src/Http/Controllers/SearchController.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,17 @@ public function track(Request $request): SearchQuery
4040
// Prevent automatic indexing each time it is updated.
4141
config('rapidez.models.search_query')::disableSearchSyncing();
4242
$searchQuery = config('rapidez.models.search_query')::withoutGlobalScope(IsActiveScope::class)
43-
->firstOrNew(
43+
->firstOrCreate(
4444
[
4545
'query_text' => Str::lower($request->q),
4646
'store_id' => config('rapidez.store'),
4747
],
4848
[
4949
'num_results' => $request->results ?? 0,
50-
'popularity' => 1,
50+
'popularity' => 0,
5151
]
5252
);
5353

54-
if (! $searchQuery->exists) {
55-
$searchQuery->save();
56-
57-
return $searchQuery;
58-
}
59-
6054
$searchQuery->popularity++;
6155
if ($request->has('results')) {
6256
$searchQuery->num_results = $request->results;

0 commit comments

Comments
 (0)