# Search for two parameters

**URL:** <https://forum.wixstudio.com/t/search-for-two-parameters/9745>\
**Category:** Ask the community\
**Tags:** code, question, wix-stores\
**Created:** [July 9, 2018, 7:02am UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745 "2018-07-09T07:02:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![topink-webmaster](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@topink-webmaster](https://forum.wixstudio.com/u/topink-webmaster)\
**Post date:** [July 9, 2018, 7:02am UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/1 "2018-07-09T07:02:03Z")

</div>

hi,

1. I try to search the store database for two parameters.  
In the name of the product and description of the product.  
But the search result only shows me results from the name of the product and does not show products that the word I am looking for also appears in the description of the product.
2. I’m trying to make it that if you press ENTER on the keyboard it moves it to the search page.

the site: www.topink.co.il

import {local} **from** ‘wix-storage’;  
import wixData **from** ‘wix-data’;  
import wixLocation **from** ‘wix-location’;  
import wixWindow **from** ‘wix-window’;

$w.onReady( **function** () {  
$w(‘#repeater1’).hide()  
});

**let** lastFilterTitle;  
**let** lastFilterDes;  
**let** debounceTimer;  
export function searchBox\_keyPress(event, $w) {  
$w(‘#repeater1’).show()  
$w(‘#searchBox’).onKeyPress(event, $w) =\> {  
let key = event.key;  
}  
**if** (debounceTimer) {  
clearTimeout(debounceTimer);  
debounceTimer = undefined;  
}  
debounceTimer = setTimeout(() =\> {  
filter($w(‘#searchBox’).value);  
}, 100);  
}

**function** filter(title, des) {  
**if** (lastFilterTitle !== title || lastFilterDes !== des) {  
**let** newFilter = wixData.filter();  
**if** (title)  
newFilter = newFilter.contains(‘name’, title);  
**if** (des)  
newFilter = newFilter.contains(‘description’, des);  
$w(‘#dataset1’).setFilter(newFilter);  
lastFilterTitle = title;  
lastFilterDes = des;  
}  
}

export function searchButton\_click() {

**let** word = $w(“#searchBox”).value;

```
local.setItem("searchWord", word); 

wixLocation.to(`/results`); 

```

}

---

<div class="post-metadata">

**Author:** ![topink-webmaster](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@topink-webmaster](https://forum.wixstudio.com/u/topink-webmaster)\
**Post date:** [July 9, 2018, 9:42am UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/2 "2018-07-09T09:42:12Z")

</div>

??

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [July 9, 2018, 4:09pm UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/3 "2018-07-09T16:09:43Z")

</div>

These following lines of code are not just unnecessary, but it probably overrides the **searchBox\_keyPress()** event handler so it most likely never gets called. And that will most likely prevent your word search from working.

```javascript
$w('#searchBox').onKeyPress(event, $w) => {
    let key = event.key;
}

```

You should first delete those lines of code, and make sure that the searchBox\_keyPress() is connected in the input field’s property panel.

---

<div class="post-metadata">

**Author:** ![topink-webmaster](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@topink-webmaster](https://forum.wixstudio.com/u/topink-webmaster)\
**Post date:** [July 10, 2018, 11:46am UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/4 "2018-07-10T11:46:10Z")

</div>

It is properly connected.  
I try to do when pressing the ENTER key on the keyboard when in SEARCHBOX. This puts you to the results page

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [July 10, 2018, 11:52am UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/5 "2018-07-10T11:52:15Z")

</div>

What page is this code on?

---

<div class="post-metadata">

**Author:** ![topink-webmaster](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@topink-webmaster](https://forum.wixstudio.com/u/topink-webmaster)\
**Post date:** [July 10, 2018, 11:54am UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/6 "2018-07-10T11:54:12Z")

</div>

on site header and on page rsults. www.topink.co.il

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [July 10, 2018, 12:04pm UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/7 "2018-07-10T12:04:23Z")

</div>

Your filter function has two parameter:  
**function filter(title, des) {**

However, you are only calling it with one parameter:  
**filter($w(‘#searchBar’).value);**

If you want the search also based on description, then you will need to pass both items to the filter function.

---

<div class="post-metadata">

**Author:** ![topink-webmaster](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@topink-webmaster](https://forum.wixstudio.com/u/topink-webmaster)\
**Post date:** [July 10, 2018, 12:08pm UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/8 "2018-07-10T12:08:33Z")

</div>

ok how i do that i am not an expert

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [July 10, 2018, 12:18pm UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/9 "2018-07-10T12:18:21Z")

</div>

Where in your code is the title to be used in the filter? Where in your code is the description to be used in the filter? You need to call the filter function with both the title and the description.

---

<div class="post-metadata">

**Author:** ![topink-webmaster](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@topink-webmaster](https://forum.wixstudio.com/u/topink-webmaster)\
**Post date:** [July 15, 2018, 8:32am UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/10 "2018-07-15T08:32:06Z")

</div>

**let** lastFilterTitle;  
**let** lastFilterDes;  
**let** debounceTimer;  
export function searchBar\_keyPress(event, $w) {  
$w(‘#repeater1’).show()  
**if** (debounceTimer) {  
clearTimeout(debounceTimer);  
debounceTimer = undefined;  
}  
debounceTimer = setTimeout(() =\> {  
filter($w(‘#searchBar’).value);  
}, 100);  
}

**function** filter(title, des) {  
**if** (lastFilterTitle !== title **&&** lastFilterDes !== des) { ///// i try search in name **and** in description  
**let** newFilter = wixData.filter();  
**if** (title)  
newFilter = newFilter.contains(‘name’, title);  
**if** (des)  
newFilter = newFilter.contains(‘description’, des);  
$w(‘#dataset2’).setFilter(newFilter);  
lastFilterTitle = title;  
lastFilterDes = des;  
}  
}

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [July 15, 2018, 1:04pm UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/11 "2018-07-15T13:04:20Z")

</div>

What isn’t working? Take a look at [Example: Search a Database](https://www.wix.com/code/home/forum/wix-tips-and-updates/example-search-a-database) which is the code to the tutorial article that you used, and does exactly what you want. You can load this example in the editor, try it, and modify it to your own use.

---

<div class="post-metadata">

**Author:** ![topink-webmaster](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@topink-webmaster](https://forum.wixstudio.com/u/topink-webmaster)\
**Post date:** [July 16, 2018, 5:42am UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/12 "2018-07-16T05:42:41Z")

</div>

I think you do not understand me, I made like in the video but without the option of choice. I want to add when searching for a product will search both parameters the name of the product and the description of the product and will show what he found in the description **and** name.

**i try this**

**function** filter(title, des) {  
**if** (lastFilterTitle !== title || lastFilterDes !== des) {  
**let** newFilter = wixData.filter();  
**if** (title)  
newFilter = newFilter.contains(‘name’, title);  
**if** (des)  
newFilter = newFilter.contains(‘description’, des);  
$w(‘#dataset2’).setFilter(newFilter);  
lastFilterTitle = title;  
lastFilterDes = des;  
}

**and this**

**function** filter(title, des) {  
**if** (lastFilterTitle !== title **&&** lastFilterDes !== des) {  
**let** newFilter = wixData.filter();  
**if** (title)  
newFilter = newFilter.contains(‘name’, title);  
**if** (des)  
newFilter = newFilter.contains(‘description’, des);  
$w(‘#dataset2’).setFilter(newFilter);  
lastFilterTitle = title;  
lastFilterDes = des;  
}  
}

**and this**

**function** search() {  
wixData.query(“Stores/Products”)  
.contains(‘name’, $w(“#searchBox”).value)  
//.contains(‘description’, $w(“#searchBox”).value)  
.find()  
.then(res =\> {  
$w(‘#searchRepeater’).data = res.items;  
})  
. **catch** (err =\> {  
console.log(‘err’, err)  
})  
}

**I’m not an expert. I make every possible attempt and sometimes it succeeds and sometimes I do not. I try to work according to logic. But my logic and the logic of a code expert are different, so I turn here for help.**  
**I did most of the way and I just needed the final touch to complete what I needed.**

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [July 16, 2018, 11:52am UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/13 "2018-07-16T11:52:18Z")

</div>

“when searching for a product will search both parameters” - That’s what the example does. You’re right, I don’t understand.

---

<div class="post-metadata">

**Author:** ![topink-webmaster](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@topink-webmaster](https://forum.wixstudio.com/u/topink-webmaster)\
**Post date:** [July 16, 2018, 11:56am UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/14 "2018-07-16T11:56:13Z")

</div>

I want one search line to look for both the name of the product and the description of the product.  
I have a website for printers and printer ink.  
When a customer searches for a sample printer 8250. There is a printer with that name and the 8250 cartridge appears in its description. So I want them both to appear in the results

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [July 16, 2018, 12:01pm UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/15 "2018-07-16T12:01:53Z")

</div>

If you search for printer 8250, then the query will return that record, including the name and the description.

---

<div class="post-metadata">

**Author:** ![topink-webmaster](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@topink-webmaster](https://forum.wixstudio.com/u/topink-webmaster)\
**Post date:** [July 16, 2018, 12:12pm UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/16 "2018-07-16T12:12:40Z")

</div>

Ok, how do I do this in code? Because I only managed one parameter

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [July 16, 2018, 12:20pm UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/17 "2018-07-16T12:20:03Z")

</div>

On your page, you need to have a title text component and description text component. For an item as a query result, just set these components to item.title and item.description.

---

<div class="post-metadata">

**Author:** ![chris-derrell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/chris-derrell/32/1774_2.png) [@chris-derrell](https://forum.wixstudio.com/u/chris-derrell)\
**Post date:** [July 16, 2018, 12:48pm UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/18 "2018-07-16T12:48:07Z")

</div>

Topink,

Just to make sure, are you saying you want the filter to filter by title **and** description? Meaning that if I search for “8250”, the results that come up will be (1) printers with a _ **title** _ of 8250, and those with (2) a _ **title and description** _ of 8250?

If so, that’s exactly what your code here does correctly. It adds both filters.

```javascript

  if(title)  
      newFilter = newFilter.contains('name', title);  
  if(des)
      newFilter = newFilter.contains('description', des); 

```

But, if you’re saying you want it to have the option of (3) printers with just a description of “8250”, you’d need to change your code a little bit, or use the or function of the WixDataFilter

---

<div class="post-metadata">

**Author:** ![topink-webmaster](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@topink-webmaster](https://forum.wixstudio.com/u/topink-webmaster)\
**Post date:** [July 16, 2018, 12:58pm UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/19 "2018-07-16T12:58:41Z")

</div>

the results that come up will be (1) printers with a _ **title** _ of 8250, and those with (2) a _ **description** _ of 8250?

this code–

```javascript
if(title)      
        newFilter = newFilter.contains('name', title); 
 if(des)  
        newFilter = newFilter.contains('description', des);  

```

not give me the prodact with the 8250 in the description  
[https://www.topink.co.il/product-page/טונר-מקרוי-tn-321cl-brother](https://www.topink.co.il/product-page/%D7%98%D7%95%D7%A0%D7%A8-%D7%9E%D7%A7%D7%A8%D7%95%D7%99-tn-321cl-brother)  
only the printer  
[https://www.topink.co.il/product-page/מדפסת-לייזר-משולבת-ברדר-dcp-8250dn-brother](https://www.topink.co.il/product-page/%D7%9E%D7%93%D7%A4%D7%A1%D7%AA-%D7%9C%D7%99%D7%99%D7%96%D7%A8-%D7%9E%D7%A9%D7%95%D7%9C%D7%91%D7%AA-%D7%91%D7%A8%D7%93%D7%A8-dcp-8250dn-brother)

![](https://us1.discourse-cdn.com/wix/original/3X/b/9/b9789916acf1ebed0f19c28b2878621df2169159.png)

---

<div class="post-metadata">

**Author:** ![chris-derrell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/chris-derrell/32/1774_2.png) [@chris-derrell](https://forum.wixstudio.com/u/chris-derrell)\
**Post date:** [July 16, 2018, 1:09pm UTC](https://forum.wixstudio.com/t/search-for-two-parameters/9745/20 "2018-07-16T13:09:13Z")

</div>

Right, exactly. If you want it to give you both you can use the following code instead.

```javascript
 if(title) 
       newFilter = newFilter.contains('name', title); 
 if(des)   
       newFilter = newFilter.or(wixData.filter().contains('description', des)); 
        

```

[Next page](https://forum.wixstudio.com/t/search-for-two-parameters/9745.md?page=2)
