Search with many words in the search bar - How is it done? how to add to existing search code

Hi;

I have an existing calling code that works fine. But I want to search a few words at the same time. (within the same search reference column, that is, the place to search one by one)

For example: car, blue, black, truck
If possible; I want to add additional functions to the search bar, for example, the two options below. When the user wants to make a call, when one of the two options is ticking his box, he should be able to make multiple calls according to the condition he has marked.

  • containing all
  • or containing any

This is how I make a search bar. Do you have a sample code?
The example helps me a lot since I am a novice in code.

Thank you

#search #searchbar #manywords #wordssearch #orsearch #containingall #searchdatabase #database #examplecode code

Hey!

We have a complete tutorial with two different methods of allowing users to search within a database collection.

Please read the following article for a step-by-step guide on how to set this up.

Corvid Tutorial: Adding Collection Data Search Functionality

You can also create a search function on your site using the wix-search API. The wix-search API has functions called hasAll() and hasSome() which will allow you to set functions to a selection box so a user can search something that contains all words or some.

I am unable to see the example code where you said “this is how I make a search bar”.

If this doesn’t help please send us a link to your site and an example of your code, and we will see what we can do to help further.

Dara | Corvid Team

Hi Umut,

If you want to include ALL, use the . eq() , if you want to include some of, use .contains() , or hasSome() .

Example:

  1. Must include all what you wrote EXACTLY:
wixData.query('myCollection').eq(fieldKey, fieldValue).find();
  1. Must contain everything you wrote
wixData.query('myCollection').contains(fieldKey, fieldValue).find();
  1. Matches some of what you wrote
wixData.query('myCollection').hasSome(fieldKey, fieldValue).find();

Please read more about wixData API.

Hi;
Thank you for the answers. I will try to try the methods. It can be a little difficult for me because I’m a beginner and I’m in the initial learning phase.

But I am sharing the search code I am using now. It works pretty well Just reacts fast. As soon as you start typing words for the search entry for the search, it opens, it gives early results, but it doesn’t actually search exactly. If you press enter when the word you entered to search is finished, it gives correct results. It has no end, except that it moves early.

Of course, I am researching to do better. In other words, I want to improve the existing search code in a way that users can make multiple calls about the search input.

Including the conditions I wrote above.

Finally, if you update the existing shared code to include the conditions I mentioned, it will be a very good tutorial for me, and it will create a tutorial resource for those who are looking for information on the forum.

Thank you

import wixData from 'wix-data';

$w.onReady(function () {
 //TODO: write your page related code here...

});

let debounceTimer;
export function searchBar_keyPress(event) {
 
    $w("#loadingGif").show();
 

 if (debounceTimer) {
        clearTimeout(debounceTimer);
        debounceTimer = undefined;
    }

    debounceTimer = setTimeout(() => {
        $w("#germany").setFilter(wixData.filter().contains("overview", $w('#searchBar').value)
                .or(wixData.filter().contains("projectTitleDescription", $w('#searchBar').value)
                    .or(wixData.filter().eq("country", $w('#searchBar').value))))
            .then(() => {
                count();
            })
    }, 50);
 

}

Hi;
Thank you for the answers. I will try to try the methods. It can be a little difficult for me because I’m a beginner and I’m in the initial learning phase.

But I am sharing the search code I am using now. It works pretty well Just reacts fast. As soon as you start typing words for the search entry for the search, it opens, it gives early results, but it doesn’t actually search exactly. If you press enter when the word you entered to search is finished, it gives correct results. It has no end, except that it moves early.

Of course, I am researching to do better. In other words, I want to improve the existing search code in a way that users can make multiple calls about the search input.

Including the conditions I wrote above.

Finally, if you update the existing shared code to include the conditions I mentioned, it will be a very good tutorial for me, and it will create a tutorial resource for those who are looking for information on the forum.

Thank you

import wixData from 'wix-data';

$w.onReady(function () {
 //TODO: write your page related code here...

});

let debounceTimer;
export function searchBar_keyPress(event) {
 
    $w("#loadingGif").show();
 

 if (debounceTimer) {
        clearTimeout(debounceTimer);
        debounceTimer = undefined;
    }

    debounceTimer = setTimeout(() => {
        $w("#germany").setFilter(wixData.filter().contains("overview", $w('#searchBar').value)
                .or(wixData.filter().contains("projectTitleDescription", $w('#searchBar').value)
                    .or(wixData.filter().eq("country", $w('#searchBar').value))))
            .then(() => {
                count();
            })
    }, 50);
 

}

???
Find it in the repeater to find out which word filtered data for searched words
Hi; I have a search page that searches from the database.

the feature I want to add;

  • show which word came from the repeater (multiple words) for the searched words

For example;
searched words; construction and electrical works

1- construction repair repair ------ includes the word: construction
2- construction and electricity - includes the word: - construction, electricity
3- includes electrical works and repair ------ word: electricity, works

my current search page code (how do i add the feature i mentioned? i would be glad if you share an example about this.)

içe wixData den ‘wix-veri’ ;
dışa aktarma işlevi searchButton_onClick (event) {
izin searchValue = $ (ağırlık ’ #SearchBox ’ ) .value;
izin searchwords = searchValue.split ( ’ );
let query = wixData.query ( ‘SouthAfrica’ )
.contains ( ‘genel bakış’ , searchWords [ 0 ]);

for ( let i = 1 ; i <searchWords.length; i ++) {
query = query.or (wixData.query ( ‘SouthAfrica’ )
.contains ( ‘genel bakış’ , searchWords [i]));
}

query.find ()
. sonra (res => {
$ w ( ’ #resultsTable ’ ) .rows = res.items;
});
}

#search #filter # multiple #words # searchWords #query #searchValue

???

BRIEFLY; to be told

  • Searched from multiple entries with input word.
  • The search was made, the results came to the repeater in the database.
  • to find out which word each entry contains in a column or in a text I want to learn as a result.

I hope you give an answer in 1 year (Unfortunately the average of the forum is like this)

example

I don’t understand what you’re saying or what you’re trying to achieve.

The help in this community is offered by passionate developers, and free of charge, they put their valuable time into helping others instead of using it for their projects, so you should be thankful to them.

You can always submit your project to Wix Marketplace to hire a developer, and they’ll find the right one for, alternatively , you can contact me for any assistance you need in your projects.

Hi;
Yes, you are one of the rare people trying to help and I appreciate it. But as a user and I am sure there are millions of users.

  • They know the wix code references page. So sharing the link to this is not a great blessing!
  • the main reason why people choose a platform like wix? “They want to develop a website themselves and make it easy / don’t need anyone”
    • if you think this is wrong you can comment
  • If they need to hire a developer, why would they want to deal with my crawl or other issues? There are millions of people who will make both web design and the code they want as a whole package business … Or isn’t it?

In conclusion, I want to explain and what you are stubborn in understanding
"We are the people who want to learn and develop their own solution … Doing the work to others does not improve you! and does not move you forward! (at least for me)
Is it a crime to strive to learn? Is it a crime to ask questions?

if so, what is the purpose of this forum? Look at the answer and conclusion analysis that has been opened with many topics. How many concluded and resolved topics are there? If wix examines this statistically, what I want to tell is more accurate.

and … thank you all

---- Also Yisrael; I think it would be better to question the criticism and the overall structure and purpose of the forum, rather than like it. Thank you for your liking though …

Hey Umut

First of all, I want you to feel welcomed in this community, it’s not a crime to learn, you can ask anything you want as long as it doesn’t go against the community guidelines.

Now regarding your points, not all members know every single piece of page in Corvid API Reference, including me, that’s why we always provide links to the relevant API.Of course the main goal for Wix is giving the opportunity to people who can’t code the ability to create a stunning website without any code knowledge, but they also have tools for hardcore developers, and everyone needs help once a while (hence you’re here), there are many cases where people needs to hire developers to add custom functionalities and features they didn’t need at the beginning or as they scale they need improvements.

There are already many articles an tutorials to help beginners start, but they need to have at least basic knowledge of coding in general and JavaScript in particular, this forum is NOT meant to change people from beginners to experts, there are many websites with JavaScript courses that help people learn.

Good answer! Ahmad
I understand you and there are the right things when they write. I think I wrote some of my own thoughts in the foreground. That’s why I deserve you. And I saw your efforts and attention to help in many topics on the forum.

Thank you also for trying to help.

You’re welcome Umut :blush:

Ahmad
the result of the job I try to achieve;
mark the searched word on the repeater in the results or find out which word is searched in a text box

is it possible to do this? if so is there a sample code or solution

Hi Umut.

Please remember all questions on this forum must be posted in English.

Thank you!

Dara | Corvid Team

It is possible, however, it requires a lot of coding skills.

ok update