Ais-input and get parameter

Is there any way I can import the value of a GET parameter to the ais-input on page load?

I want when the user enters the link /search?q=macbook to fill the input and search.

for the record, after checking the documentation it seems that this can be done easily by adding the query to the search store using something like

            this.searchStore.query = getparameter;
1 Like

Yep, that’s how you can do it, an option that doesn’t require you to edit the searchStore is by adding the query prop with the value you get from the url to <ais-index>

see https://community.algolia.com/vue-instantsearch/components/index.html#props

Hey @haroen, thanks for the link.

In the context of this question, is there any way to specify multiple values for a query prop? Possibly an array of values.

My code looks like this

<product-list :category_id="{{ $category->id }}">

and i’d like to show products from multiple categories (basically a category’s subcategories’ products)

I tried passing an array and multiple times the category_id without luck.

Any ideas?

Hey @chrys,

Sorry for answering late. I’m not 100% sure what you mean though, where does <product-list> come from? Can you share some code with input that works and something that you want to work?

Thanks!

Hi @haroen,
Product-list is basically a wrapper for ais-index.

Product-List.Vue
-----------------
<template>
    <ais-index :search-store="searchStore">
        <slot></slot>
    </ais-index>
</template>


<script>
    import {
        createFromAlgoliaCredentials,
        FACET_OR,
    } from 'vue-instantsearch';

    const store = createFromAlgoliaCredentials(
        'X',
        'X'
    );
    store.indexName = 'products';

    export default {
        props: ['category_id'],
        data() {
            return {searchStore: store}
        },
        methods:{
            ......
        },
        created() {
            this.searchStore.addFacet('category_id', FACET_OR);
            this.searchStore.addFacetRefinement('category_id', this.category_id);
        }

    }
</script>

I basically want to give two values in the Facet Refinement. If I give 1 and 2, I expected both category products to be returned.

Hi @chrys

If you want to have products that are in two categories at the same time then you should probably use a FACET_AND. FACET_OR is for retrieving facets from either categories. To set two values you should call addFacetRefinement twice with one value at a time.

Let us know how that works for you.

Cheers,

It worked thank you @Bobylito !