# How to Create a Search for Your Database

**URL:** <https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928>\
**Category:** Show and tell\
**Tags:** tips, code\
**Created:** [February 1, 2018, 1:04pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928 "2018-02-01T13:04:57Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![felipe-bustos](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/felipe-bustos/32/692_2.png) [@felipe-bustos](https://forum.wixstudio.com/u/felipe-bustos)\
**Post date:** [March 19, 2018, 12:54pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/21 "2018-03-19T12:54:41Z")

</div>

Matthew, order by filter arrangement and for the favorites you need to have a member profile page (there’s an other thread about this in the forum) and a collection to store and modify the favourites. You can shoot me an email if needed: [felipe@diaytech.com](mailto:felipe@diaytech.com)

---

<div class="post-metadata">

**Author:** ![matthew](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@matthew](https://forum.wixstudio.com/u/matthew)\
**Post date:** [March 22, 2018, 7:48am UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/22 "2018-03-22T07:48:47Z")

</div>

Thanks so much Felipe. It looks like we’ve ironed out these problems. Really appreciated!

---

<div class="post-metadata">

**Author:** ![wayne](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/wayne/32/2461_2.png) [@wayne](https://forum.wixstudio.com/u/wayne)\
**Post date:** [March 29, 2018, 8:07pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/23 "2018-03-29T20:07:57Z")

</div>

I have 9700 products in my repeater. It takes about 45 seconds to open. Any ideas how I can speed it up?  
[https://planethost.wixsite.com/pmls/search2](https://planethost.wixsite.com/pmls/search2)

---

<div class="post-metadata">

**Author:** ![code-queen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-queen/32/696_2.png) [@code-queen](https://forum.wixstudio.com/u/code-queen)\
**Post date:** [March 29, 2018, 8:13pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/24 "2018-03-29T20:13:22Z")

</div>

Wayne,

You want to try hiding the repeater on load … then set timer to appear after a few seconds. Either way …each dataset has a limit to only show 1,000 …so I dont think your page is trying to load all 9700 products. It could just be trying to load the first 1000 or something else on the page.

If i were a customer on a page … I doubt I would make it to view all 1000 products. I would probably want to see some sort of either featured products and then sort/filter buttons to narrow down my search.

---

<div class="post-metadata">

**Author:** ![daniel-2](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/daniel-2/32/2832_2.png) [@daniel-2](https://forum.wixstudio.com/u/daniel-2)\
**Post date:** [March 30, 2018, 2:15pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/25 "2018-03-30T14:15:48Z")

</div>

I have mirrored all steps written by YOAV’s video and code exaple, but finaly works only search bar. When I try to filter by dropdown, only one category in dropdown filtering products but others unfurtunately show nothing.  
Please help!

---

<div class="post-metadata">

**Author:** ![wayne](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/wayne/32/2461_2.png) [@wayne](https://forum.wixstudio.com/u/wayne)\
**Post date:** [March 30, 2018, 3:23pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/26 "2018-03-30T15:23:44Z")

</div>

Thanks Code Queen. That was my aim.  
Even testing with the editor and the sandbox collection - it take ‘forever’!

I have managed to get it working 100% with a table. Something like this

Then how do I get a repeater doing the same thing ?

1. Set the base of this table to show the entire search result instead of cutting it off?
2. If I click on one of the images or a row… How do I get it to open on a new page with the entire supplier listing?

 ![](https://us1.discourse-cdn.com/wix/original/3X/f/3/f35f11da45a023c548427d39d51633816dd37eae.jpeg)

You are a star… Where did you learn javascript?

---

<div class="post-metadata">

**Author:** ![code-queen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-queen/32/696_2.png) [@code-queen](https://forum.wixstudio.com/u/code-queen)\
**Post date:** [March 30, 2018, 3:34pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/27 "2018-03-30T15:34:41Z")

</div>

Thank you 🙂

I learned right here in this forum by asking questions and using all the resources that Wix has. (Articles, Examples, API lists, videos …)

I have always loved logic and puzzles. Wix Code fit right in. It was love at first ‘site’ 😉

Try playing around with the table settings for different viewing styles, etc. If you want them to click on a row to be redirected to another page — you need to build a dynamic single item page and then connect it using your table settings.

You can watch my repeater video here: [How to use Wix Repeaters | Create Property Listing, Directory - YouTube](https://www.youtube.com/watch?v=uiftGNZsLXA&t=1s)

And if I may make a design suggestion … try making the background a lighter solid color … like white … or beige. This is especially important if you are building a website that gives all the attention to the products. You want the visitor’s attention on the product and not the background. The ‘fancier’ you get with colors … the more you lose their focus.

---

<div class="post-metadata">

**Author:** ![wayne](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/wayne/32/2461_2.png) [@wayne](https://forum.wixstudio.com/u/wayne)\
**Post date:** [March 30, 2018, 4:01pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/28 "2018-03-30T16:01:37Z")

</div>

Thanx CQ. I agree. I found wix to be hugely powerful because its a WYSIWIG system. Most of the others are not. I really enjoy wix. Will look at your video shortly.

---

<div class="post-metadata">

**Author:** ![wayne](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/wayne/32/2461_2.png) [@wayne](https://forum.wixstudio.com/u/wayne)\
**Post date:** [March 31, 2018, 3:38pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/29 "2018-03-31T15:38:26Z")

</div>

Its not working..  
I have created a test site with the continent articles, images etc.  
Then I built a repeater connecting it to the Articles dataset  
I added the two search inputs and added their name ID’s  
Copied the code Ctrl C + V into the page.

NOTHING…

You forgot to mention the dataset needs to be Read & Write or it will not function.

This is my result.  
[https://planethost.wixsite.com/testsite](https://planethost.wixsite.com/testsite)

These are the permissions - which no one ever mentions and is the main issue with many issues.

 ![](https://us1.discourse-cdn.com/wix/original/3X/3/c/3ce377af1d6f8951bd4cc69ccead3155510f9bce.png)

# And the code

import wixData from “wix-data”;

$w.onReady(() =\> {  
loadContinents();  
});

let lastFilterTitle;  
let lastFilterContinent;  
let debounceTimer;

export function iTitle\_keyPress(event, $w) {  
if (debounceTimer) {  
clearTimeout(debounceTimer);  
debounceTimer = undefined;  
}  
debounceTimer = setTimeout(() =\> {  
filter($w(‘#iTitle’).value, lastFilterContinent);  
}, 500);  
}

export function iContinent\_change(event, $w) {  
filter(lastFilterTitle, $w(‘#iContinent’).value);  
}

function filter(title, continent) {  
if (lastFilterTitle !== title || lastFilterContinent !== continent) {  
let newFilter = wixData.filter();  
if (title)  
newFilter = newFilter.contains(‘articleTitle’, title);  
if (continent)  
newFilter = newFilter.contains(‘continent’, continent);  
$w(‘#dataset1’).setFilter(newFilter);   
lastFilterTitle = title;  
lastFilterContinent = continent;  
}  
}

function loadContinents() {  
wixData.query(‘Articles’)  
.find()  
.then(res =\> {  
let options = [{“value”: ‘’, “label”: ‘All Continents’}];  
options.push(…res.items.map(continent =\> {  
return {“value”: continent.title, “label”: continent.title};  
}));  
$w(‘#iContinent’).options = options;  
});

# }

X  
X  
X  
X  
X  
X  
X

ERROR ins the code  
It doesn’t work until

```
  	options.push(...res.items.map(continent => { 
  		return {"value": continent.title, "label": continent.title}; 

```

BECOMES

```
  	options.push(...res.items.map(continent => { 
  		return {"value": continent.continent, "label": continent.continent}; 

```

The learning curve is rediculously steep. Is there not a course on wix code somewhere???

---

<div class="post-metadata">

**Author:** ![wayne](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/wayne/32/2461_2.png) [@wayne](https://forum.wixstudio.com/u/wayne)\
**Post date:** [March 31, 2018, 4:11pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/30 "2018-03-31T16:11:40Z")

</div>

So … i sincerely hope someone is able to give me the correct code.

---

<div class="post-metadata">

**Author:** ![wayne](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/wayne/32/2461_2.png) [@wayne](https://forum.wixstudio.com/u/wayne)\
**Post date:** [March 31, 2018, 4:42pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/31 "2018-03-31T16:42:30Z")

</div>

Vortex…  
I am reading the code above and comparing it to the code in the video. CHALK AND CHEESE.  
There is nothing wrong with you or I.

I think those who get it right have changed the code somewhere. I just wish someone would post the correct code. I am wasting 6 hours of every day trying to work this out and it IS NOT WORKING!

---

<div class="post-metadata">

**Author:** ![wayne](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/wayne/32/2461_2.png) [@wayne](https://forum.wixstudio.com/u/wayne)\
**Post date:** [March 31, 2018, 5:12pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/32 "2018-03-31T17:12:31Z")

</div>

Hi Nayeli,  
I was following your video [- YouTube](https://www.youtube.com/watch?v=ZdIB0Q7WXP4)  
Firstly I cannot believe the steep learning curve we have with wix code. I sympathise with you fully.

Secondly, I followed your video and it made SO MUCH SENSE!  
Please keep making videos of what you learn. It is really very beneficial to us.

I have been trying to add a Search input for my repeater… Im going mad trying to do this…

---

<div class="post-metadata">

**Author:** ![code-queen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-queen/32/696_2.png) [@code-queen](https://forum.wixstudio.com/u/code-queen)\
**Post date:** [March 31, 2018, 5:54pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/33 "2018-03-31T17:54:51Z")

</div>

Well thank you 🙂

It has been challenging but every day I learn more and more.

Maybe these notes might help you: [Totally Codable - Trusted Velo Community](https://www.webixdesigns.com/forum/wix-code-for-all/search-on-keypress-with-dropdown)

I have other code resources here: [https://www.totallycodable.com/forum/codes-for-templates](https://www.totallycodable.com/forum/codes-for-templates)

And I invite you to join my FB group where you can post your questions to get insight from other wix users, experts and coders 🙂 . [Totally Codable Community - Web Design, Wix, Velo, No Code and more . . . | Facebook](http://www.facebook.com/groups/wixcode)

---

<div class="post-metadata">

**Author:** ![lukas-blaha](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/lukas-blaha/32/2886_2.png) [@lukas-blaha](https://forum.wixstudio.com/u/lukas-blaha)\
**Post date:** [April 2, 2018, 7:34pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/34 "2018-04-02T19:34:11Z")

</div>

Still doesnt show “All continents” , when i try All continents in menu, doesnt show anything…

---

<div class="post-metadata">

**Author:** ![natuc](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@natuc](https://forum.wixstudio.com/u/natuc)\
**Post date:** [April 5, 2018, 10:43pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/35 "2018-04-05T22:43:02Z")

</div>

Hi Nayeli! I’ve been watching your videos on youtube, these are very helpful! Thank you! I’m not a code expert but i’m building a website and for this I need 3 search categories on my home page and filter these categories from a database and display them to an user. I read the tutorial " How to Use Code to Let Your Users Search a Collection " however I don’t know how to do this with two or more search criteria. Appreciate your suggestions!

---

<div class="post-metadata">

**Author:** ![\_greg-1](https://avatars.discourse-cdn.com/v4/letter/_/f4b2a3/32.png) [@\_greg-1](https://forum.wixstudio.com/u/_greg-1)\
**Post date:** [April 24, 2018, 5:22pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/36 "2018-04-24T17:22:14Z")

</div>

Here is code I am using to import vehicle years from my Wheels2 dataset to a drop down (user input). It works except it doesn’t remove repeat values of vehicle years.

import wixData from “wix-data”;  
$w.onReady(() =\> {  
wixData.query(‘Wheels2’)  
.ascending(‘vehyear’)  
.limit(1000)  
.find()  
.then(res =\> {  
let options = [{“value”: ‘’, ‘label’: ‘All Years’}];  
options.push(…res.items.map(vehyear =\> {  
return {‘value’: vehyear.title, ‘label’: vehyear.vehyear};  
}));  
$w(‘#iyear’).options = options;  
});  
});  
let lastFilterTitle;  
let lastFilterYear;  
function filter(title, newyear) {  
if (lastFilterTitle !== title || lastFilterYear !== newyear) {  
let newFilter = wixData.filter();  
if (title)  
newFilter = newFilter.contains(‘title’, title);  
if (newyear)  
newFilter = newFilter.eq(‘vehyear’, newyear);  
$w(‘#Wheels2’).setFilter(newFilter);  
lastFilterTitle = title;  
lastFilterYear = newyear;  
}  
}

export function iyear\_change(event, $w) {  
filter(lastFilterTitle, $w(‘#iyear’).value);  
}

// vehyear is a field in my dataset  
// title is my primary key  
I know in the video the field continent had each continent more than once. If someone can explain to me why this isn’t working for me I would appreciate it. I believe it is because my 'function filter" isn’t being executed.

Greg

---

<div class="post-metadata">

**Author:** ![\_greg-1](https://avatars.discourse-cdn.com/v4/letter/_/f4b2a3/32.png) [@\_greg-1](https://forum.wixstudio.com/u/_greg-1)\
**Post date:** [April 25, 2018, 8:40pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/37 "2018-04-25T20:40:34Z")

</div>

So I recently got this from Jeff from Wix from another forum post and I modified it to work with my dataset field years. However it only returns about 20 years from 1969 - 1988 vs 1969 - 2016. It seems that using an array here is limiting my returned filtered values where in my above code actually uses the parameter .limit(1000). Even thought I hadded .limit() in this code, but I believe the array is limiting here. Thoughts, anyone? Bueller?

import wixData from ‘wix-data’;

$w.onReady(function () {  
wixData.query(“Wheels2”)  
.limit(1000)  
.ascending(‘vehyear’)  
.find()  
.then(results =\> {  
const uniqueYears = getUniqueYears(results.items);  
$w(“#iyear”).options = buildOptions(uniqueYears);  
});

```
function getUniqueYears(items) {     
		const YearsOnly = items.map(item => item.vehyear);    
   		return [...new Set(YearsOnly)]; 

```

}

```
function buildOptions(Years) {    
	return Years.map(vehyear => { 
	return {label:vehyear, value:vehyear};   
	}); 
} 

```

});

---

<div class="post-metadata">

**Author:** ![will-tenenbaum](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@will-tenenbaum](https://forum.wixstudio.com/u/will-tenenbaum)\
**Post date:** [May 3, 2018, 5:20pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/38 "2018-05-03T17:20:05Z")

</div>

I was wondering how to run two search boxes on a single page. Search by Industry and Search by Last Name. The Industry search works using the following code, but the lastName one does not. Any ideas?

import wixData from “wix-data”;

let lastFilterIndustry;  
let lastFilterLastName;  
let debounceTimer;  
export function iIndustry\_keyPress\_1(event, $w) {  
if (debounceTimer) {  
clearTimeout(debounceTimer);  
debounceTimer = undefined;  
}  
debounceTimer = setTimeout(() =\> {  
filter($w(‘#iIndustry’).value);  
}, 200);  
}

export function iLastName\_keyPress(event, $w) {  
filter($w(‘#iLastName’).value);  
}

function filter(industry, lastName) {  
if (lastFilterIndustry !== industry || lastFilterLastName !== lastName) {  
let newFilter = wixData.filter();  
if (industry)  
newFilter = newFilter.contains(‘industry’, industry);  
if (lastName)  
newFilter = newFilter.contains(‘lastName’, lastName);  
$w(‘#dataset1’).setFilter(newFilter);  
lastFilterIndustry = industry;  
lastFilterLastName = lastName;  
}

}

---

<div class="post-metadata">

**Author:** ![felipe-bustos](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/felipe-bustos/32/692_2.png) [@felipe-bustos](https://forum.wixstudio.com/u/felipe-bustos)\
**Post date:** [May 3, 2018, 7:04pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/39 "2018-05-03T19:04:08Z")

</div>

Hey WIll why dont just 1 searchbox and refine your filter with the or( ) function?

---

<div class="post-metadata">

**Author:** ![code-queen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-queen/32/696_2.png) [@code-queen](https://forum.wixstudio.com/u/code-queen)\
**Post date:** [May 3, 2018, 7:12pm UTC](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928/40 "2018-05-03T19:12:50Z")

</div>

I agree with Felipe 😉

Seems like you understand a bit of code … try this:

[https://www.totallycodable.com/forum/codes-for-templates/search-this-or-that-code-repeater-results](https://www.totallycodable.com/forum/codes-for-templates/search-this-or-that-code-repeater-results)

[Previous page](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928.md?page=1)

[Next page](https://forum.wixstudio.com/t/how-to-create-a-search-for-your-database/27928.md?page=3)
