Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable search engine, because correct results are coming from BE #307

Closed
oakleaf opened this issue Jan 14, 2022 · 4 comments
Closed

Disable search engine, because correct results are coming from BE #307

oakleaf opened this issue Jan 14, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@oakleaf
Copy link

oakleaf commented Jan 14, 2022

Hello, I'd like to disable the search engine entirely, so all items coming from the BE is shown. But I can't find a way to go around this, since I have to specify keys. When I do this, the "autoComplete.js" search engine displays the results in another order, and not grouped together if there are more matches than in one place.

So my request is to disable the searchEngine. Maybe a suitable way to do so is to not use the keys parameter at all, together with data.src is objects?

@oakleaf oakleaf added the enhancement New feature or request label Jan 14, 2022
@oakleaf oakleaf closed this as completed Jan 14, 2022
@oakleaf
Copy link
Author

oakleaf commented Jan 14, 2022

I found out how to do this. If I dont use any keys, use the searchEngine parameter and return the whole object.

obj.searchEngine = (q, r) => r;

@adamtheapiguy
Copy link

I found out how to do this. If I dont use any keys, use the searchEngine parameter and return the whole object.

obj.searchEngine = (q, r) => r;

can you post the whole code? I want to disable search engine and display results as is. also I need to cleanup everything to do with search engine. The api I'm calling does the search already. Is there a simplified version of the autoComplete?

@oakleaf
Copy link
Author

oakleaf commented Feb 19, 2023

Only like this;

    init(_data_source)
    {
        if(_data_source.src != undefined && typeof(_data_source.src) == "string")
        {
            let obj = {
                data: {
                    src: async (query) => {
                        try
                        {
                            if(this.fetch)
                            {
                                this.abort();
                                document.body.classList.add("autocomplete-searching");
                            }

                            this.fetch = abortableFetch(_data_source.src, { q: query });

                            return await this.fetch.ready();
                        } 
                        catch (error) 
                        {
                            return error;
                        }
                    }
                }
            };

            let keys = (_data_source.key != undefined && typeof(_data_source.key) == "string") ? [_data_source.key] : ((_data_source.keys != undefined) ? _data_source.keys : null);

            if(keys)
            {
                obj.data['keys'] = keys;
            }
            else
            {
                obj.searchEngine = (q, r) => r;
            }
             
            return obj;
        }
    }

@adamtheapiguy
Copy link

thanks for your response.

I ended up doing it like the below:

    const autoCompleteJS = new autoComplete({ // API Advanced Configuration Object
      selector: "#autoComplete",
      placeHolder: "Search our API Catalogue",
      searchEngine: function (query, record) {
        return record;
      },

it worked but I have few questions:
where is that searchEngine is defined?
How to clean up the autoComplete.js to remove everything to do with search engine. I just need a simple code to just make REST api calls and display all results coming back from the REST API call. I don't need the search engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants