Skip to content

Commit

Permalink
Merge pull request #60 from Ku3mi41/feature/debounced-search
Browse files Browse the repository at this point in the history
feat: debounced search
  • Loading branch information
bfritscher authored Apr 24, 2024
2 parents 83ee762 + 4c261a5 commit b244ace
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
66 changes: 66 additions & 0 deletions src/components/search/DebouncedSearchBox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<template>
<q-input
v-model="query"
@clear="clear"
dense
autofocus
outlined
type="search"
clearable
clear-icon="close"
placeholder="Search...">
<template v-slot:prepend>
<q-icon name="search" />
</template>
</q-input>

</template>

<script>
import { connectSearchBox } from 'instantsearch.js/es/connectors';
import { createWidgetMixin } from 'vue-instantsearch/vue3/es';
export default {
mixins: [createWidgetMixin({ connector: connectSearchBox })],
props: {
delay: {
type: Number,
default: 200,
required: false,
},
},
data() {
return {
timerId: null,
localQuery: '',
};
},
unmounted() {
if (this.timerId) {
clearTimeout(this.timerId);
}
},
methods: {
clear() {
this.query = '';
}
},
computed: {
query: {
get() {
return this.localQuery;
},
set(val) {
this.localQuery = val;
if (this.timerId) {
clearTimeout(this.timerId);
}
this.timerId = setTimeout(() => {
this.state.refine(this.localQuery);
}, this.delay);
},
},
},
};
</script>
7 changes: 5 additions & 2 deletions src/components/search/SearchInstantSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
:middlewares="middlewares"
>
<ais-configure :hits-per-page.camel="12" />
<ais-search-box placeholder="" />
<ais-search-box index-name="instant_search" :search-client="searchClient">
<debounced-search-box />
</ais-search-box>
<ais-stats></ais-stats>
<ais-current-refinements />

Expand Down Expand Up @@ -71,12 +73,13 @@

<script lang="ts">
import SearchResultItem from 'src/components/search/SearchResultItem.vue';
import DebouncedSearchBox from 'src/components/search/DebouncedSearchBox.vue';
import TypesenseInstantSearchAdapter from 'typesense-instantsearch-adapter';
import { CollectionSchema } from 'typesense/lib/Typesense/Collection';
import { defineComponent } from 'vue';
export default defineComponent({
components: { SearchResultItem },
components: { SearchResultItem, DebouncedSearchBox },
name: 'SearchInstantSearch',
data() {
const data = {
Expand Down

0 comments on commit b244ace

Please sign in to comment.