# Enter multiple words in search bar to search one database field

**URL:** <https://forum.wixstudio.com/t/enter-multiple-words-in-search-bar-to-search-one-database-field/58093>\
**Category:** Ask the community\
**Tags:** code\
**Created:** [April 13, 2024, 2:09pm UTC](https://forum.wixstudio.com/t/enter-multiple-words-in-search-bar-to-search-one-database-field/58093 "2024-04-13T14:09:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Devin\_Hardin](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/devin_hardin/32/88849_2.png) [@Devin\_Hardin](https://forum.wixstudio.com/u/Devin_Hardin)\
**Post date:** [April 13, 2024, 2:09pm UTC](https://forum.wixstudio.com/t/enter-multiple-words-in-search-bar-to-search-one-database-field/58093/1 "2024-04-13T14:09:04Z")

</div>

I’m a newbie to coding, but overall I feel I’m doing fairly well. I feel like my issue should be super easy to solve or at least I should be ablet to find info on it, but I’ve had no luck. I have a search bar on my website that searches a database of images and works how I want it to IF I only enter one search word. The search bar is connected to a database field called ‘keywords’ where I have listed multiple words that describe the image. I’d like uses to be able to search multiple words and thus narrow the search a bit. Right now, if I put in multiple words, the search doesn’t render any results. My code is below. It uses contains() at the moment. I’ve tried eq() and hasAll(). I’ve tried placing a comma between the search words in the search bar. I’ve tried removing the commas between the works in my database field. As I said, it feels like this should be simple, but apparently for me it’s not. Any suggestions are greatly appreciated. Thanks!

$w(“#searchInput”).onKeyPress((e) =\> {  
console.log(e.target.id + ‘-clicked’);  
console.log('Pressed-Key: ', e.key);

```
    if (e.key === "Enter") {
        console.log('start search...');

        let keywords = $w('#searchInput').value
        
        wixData.query('MyGraphics').contains('keywords', keywords)
            .find()
            .then(results => {
                console.log('Results: ', results);

```

---

<div class="post-metadata">

**Author:** ![Devin\_Hardin](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/devin_hardin/32/88849_2.png) [@Devin\_Hardin](https://forum.wixstudio.com/u/Devin_Hardin)\
**Post date:** [April 15, 2024, 1:52pm UTC](https://forum.wixstudio.com/t/enter-multiple-words-in-search-bar-to-search-one-database-field/58093/2 "2024-04-15T13:52:43Z")

</div>

Found some code that’s workig as I want it to.

$w(“#searchInput”).onKeyPress((e) =\> {  
console.log(e.target.id + ‘-clicked’);  
console.log('Pressed-Key: ', e.key);

```
    if (e.key === "Enter") {
        console.log('start search...');

        let keywords = $w('#searchInput').value
        let str = keywords
        let array = str.split(" ")
        let query = wixData.query('MyGraphics')
        for (let i=0; i < array.length; i++) 
        {query = query.contains('keywords', array[i]); }
            query.find()
            .then(results => {
                console.log('Results: ', results);

```
