itemsapi / itemsjs

Extremely fast faceted search engine in JavaScript - lightweight, flexible, and simple to use

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to prefilter search, when passing paramenter from URL

acerosillo opened this issue · comments

Hi guys,

I have a URL that is passing some parameters (strings), that I want the search page to have filtered when you land on the page :

v-careers-search-page.html?careerssearch=xxx&Job_family_group=xxx&Organisation_name=xxx&Primary_location_country=GB

so for example when I land on the search page, I would like the 'Primary_location_country' checkbox to prefilter all GB countries, but also be able to filter any other options given from GB

hope this makes sense..

cheers,
A

Hi, this is more js question. Such a lib https://medialize.github.io/URI.js/ may help you with parsing url parameters (if you are doing it on the frontend side)

I have this :

        computed: {
            searchResult: function () {

                var uri = window.location.href.split('?');
                //if URL has params filtered from params passed.
                if (uri.length == 2) {
                    var result = itemsjs.search({
                        query: this.query,
                        filters: this.filters,
                        prefilter: function(items) {
                            return items.filter(item => {
                            //This is where I will pass in my parameters from URL eg. ?careerssearch=&Job_family_group=2&Organisation_name=0&Primary_location_country=GB
                            return item.Primary_Location_Country == "US";
                        })
                        }
                    })
                }
                //if URL has no params list as nomarl...
                if (uri.length == 1) {
                    var result = itemsjs.search({
                    query: this.query,
                    filters: this.filters
                    })

                }
                
                return result
            }
        }

this works, but can't get the checkbox to be checked.

I am closing because this is more Vue.js related question