Search in a dynamic page

Hello!
I have a dynamic page that shown by category.
I want to add search but only in the specific category.
I have search bar but when I search it shows items from the whole database and not from a specific category.

There is a way to do it?

Thank you!

Hi,

did you implement your own search code over your collection? can you please share the site url and code sample?

Shlomi

did you try something like this but with the category also in context?

export function searchButton_click_1() {
wixData.query(‘Search’)
.contains(‘title’, $w(‘#textInput1’).value)
.find()
.then(res => {
$w(‘#resultsTable’).rows = res.items;
$w(‘#resultsTable’).show();
});
}

This is the code i used:

import wixData from ‘wix-data’;

// For full API documentation, including code examples, visit http://wix.to/94BuAAs

$w.onReady(function (){
//TODO: import wixData from ‘wix-data’;
});

export function searchButton_onClick (){
wixData.query(‘businesses’)
.contains(‘City’, $w(‘#input1’).value)
.or(wixData.query(‘businesses’)
.contains((‘title’), $w(‘#input1’) .value))
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
});
}

If i search it shows me all the data but i want the data just from the specific dynamic page

Nevo,

please refer to the following option https://www.wix.com/code/reference/wix-data.WixDataFilter.html to both use a single query rather than 2 db searches. and also add the category of the dynamic page to filter the data by its category.
btw, are you able to get the current category in context for the item the dynamic page is displaying using code?

can you please also share the url of the site you are trying to build?

Shlomi

Hay nevo,

I think you are missing another condition in your query - to filter the data by the current dynamic page.

It normally involve something like the following - in addition to your code above

 wixData.query('businesses')
   .contains('City', $w('#input1').value)
	.or(wixData.query('businesses')
   .contains(('title'), $w('#input1')  .value))
   .eq('FIELD', $w('#DYNAMIC_DATASET1').getCurrentItem().FIELD)
...
  1. FIELD in the code above is the field you use to identify the relation between the dynamic page and the items you search.
  2. Note that you should write field names in lower case - just city, not City
  3. Note you do not need the parenthesis around the title field name ('title) - just use ‘title’

Thanks YOAV.
Can i contact you privately?

???