I need help - please

I have used Naylie’s code to search a database (Thank you Nayeli) and have modified slightly as I am using a database automatically created via wix.stores

Home Page Code

import {local} from ‘wix-storage’;
import wixLocation from ‘wix-location’;
$w.onReady(function () {
});
export function searchButton_click() {
let word = $w(“#searchBar”).value;
local.setItem(“searchWord”, word);
wixLocation.to(/search-results);
}

**Results Page Code **

import {local} from ‘wix-storage’;
import wixData from ‘wix-data’;

$w.onReady( function () {
var sameWord = local.getItem(“searchWord”);
$w(“#searchBar”).value = sameWord;
$w(“#searchBar”).placeholder = sameWord;
$w(‘#dataset1’).onReady( function () {
search();
});
});

export function searchButton_click() {
search();
}

function search() {
wixData.query(‘Stores/Products’)
.contains(‘name’, $w(“#searchBar”).value)
.or(wixData.query(‘Stores/Products’).eq(‘price’, $w(“#searchBar”).value))
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;
});
}

Try as I might i cannot get

.or(wixData.query(‘Stores/Products’).eq(‘price’, $w(“#searchBar”).value))

to work in conjunction with the ‘.contains’ - it returns 20 out of 45 products - and has no relation to the search??

It doesn’t appear to be clearing the wix-storage either but rather holding on to the initial user input, i.e ‘pink’ - is there a way to make the search bar return to ‘Search’ once the query has been fulfilled??

Also, I would love to have a ‘No Products Found’ if there’s nothing matching either criteria.

I have looked through lots of online help and suggestions and I confess - I got nothing!!

Please help, I am pulling my hair out - I have been at this for two days solid …

Thanks so much for your help :slight_smile:

NB: I didn’t underline this - the machine did :frowning:
wixLocation.to(/search-results);

Can you send a link to your page? Easiest route is to probably just clear the storage and set the search to null after the function. See below in bold

 
import {local} from 'wix-storage';
import wixLocation from 'wix-location';

$w.onReady(function () {

});

export function searchButton_click() {
let word = $w("#searchBar").value;
    local.setItem("searchWord", word);
wixLocation.to(`/search-results`);
}
**Results Page Code **
import {local} from 'wix-storage'; 
import wixData from 'wix-data';   

$w.onReady(function () {  

var sameWord = local.getItem("searchWord");     
$w("#searchBar").value = sameWord;     
$w("#searchBar").placeholder = sameWord;     
$w('#dataset1').onReady(function () {         
search();     
}); 
});   

export function searchButton_click() {     
search(); }   function search() {     
wixData.query('Stores/Products')    
.contains('name', $w("#searchBar").value)
.or(wixData.query('Stores/Products')
.eq('price', $w("#searchBar").value))         
.find()        
.then(res => {   
$w('#repeater1').data = res.items;
 local.clear(); 
 $w("#searchBar").value = null;
}); 
}

I’m try to look at this on laptop and I’m getting 502 Bad Gateway

Hi David, here’s the link
https://www.shyswardrobe.com

Could really use the ‘No Products Found’ code

The search bit seems to work … Just not the .or variation

I’m using this search code as well but its not ideal. When I search for “Raffle” for example my correct results are returned but if I search for “Bobby won the Raffle” then no results come up. The search is comparing the search bar text to a keyword field. Any help?

import {local} from ‘wix-storage’;
import wixData from ‘wix-data’;$w.onReady( function () {
var sameWord = local.getItem(“searchWord”);
$w(“#searchBar”).value = sameWord;
$w(“#searchBar”).placeholder = sameWord;
$w(‘#dataset1’).onReady( function () {
search();
});
}); export function searchButton_click() {
search();
} function search() {
wixData.query(‘Tutorial_search’).contains(‘tut_keywords’, $w(“#searchBar”).value) .find()
.then(res => {
$w(‘#repeater1’).data = res.items;
});}