I have implemented a search against a database of magazines. Each magazine may have up to four articles of interest. I am trying to retrieve all magazines with the word or phrase entered into a search input box. It ONLY works against the first field. What Am I Missing here?
Url: https://jds-cvoa.wixsite.com/cvoa/copy-of-regional-newsletters
Wix code I am using:
import wixData from 'wix-data';
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
$w.onReady(function () {
//TODO: write your page related code here...
});
export function searchButton_onclick() {
wixData.query('CVOA-Magazines')
.contains('article1' || 'article2' || 'article3' || 'article4',$w('#input1').value)
.find()
.then(res=>{
$w('#table1').rows = res.items;
});
}
Thanks,
JD
This code works perfectly! but I am trying to perfect this. If you write more than one word it doesn't show any results unless the string be entered exactly as the data phrase is wrote, so I would like to make this can combine words with no matter the order are entered and so find combinations.. EG
can some one help?
Yes, you use the .or operator... here is the final code:
export function input1_keyPress(event, $w) { if (event.key === "Enter") wixData.query('CVOA-Magazines') .contains('title', $w('#input1').value) .or(wixData.query('CVOA-Magazines').contains('article1', $w('#input1').value)) .or(wixData.query('CVOA-Magazines').contains('article2', $w('#input1').value)) .or(wixData.query('CVOA-Magazines').contains('article3', $w('#input1').value)) .or(wixData.query('CVOA-Magazines').contains('article4', $w('#input1').value)) .find() .then(res => { $w('#repeater1').data = res.items; }); }
Hi JD,
I'm developing a site with a different topic but similar data structure.
Did you solve your problem with multiple fields search? I'm desperate to make it run.
phip
Scroll up... it is in my initial post. :-) HERE is is again:
import wixData from 'wix-data';
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
$w.onReady(function () {
//TODO: write your page related code here...
});
export function searchButton_onclick() {
wixData.query('CVOA-Magazines')
.contains('article1' || 'article2' || 'article3' || 'article4',$w('#input1').value)
.find()
.then(res=>{
$w('#table1').rows = res.items;
});
}
Following her original code for the contains was:
.contains('article1',$w('#input1').value)
And that works as expected. I added the OR condition to check the other fields. It only returns items with the match in 'article1'.
Hey,
Can you please share the code you were asking about?
Tal
Thanks Tal,
I already looked at that video but I don't need the filter. Then I found Nayeli tutorial which was way more easier. https://youtu.be/ZdIB0Q7WXP4
After I got it working I modified the .contains to use an OR to see if the search value was contained in the other three database fields.
I just looked at the other thread. Should I be using multiple if statements?
Thanks
JD
Hi,
I recommend checking out this video tutorial. Moreover, you can check this thread for filtering repeater using multiple user inputs.
Good luck,
Tal.