Search a Database

Hi ziv,
I’m trying to develop a complex recipe - recommendation - inventory application.
I can elaborate the details in private.
For that, I want to have many tables with different relationship to get the complexity I’m looking for.

Thanks,
Navit

Take a look at our coming soon page.
we are working or adding references between collections and allowing for “joining” two or more collections in a single query.

relevant for your needs?

Hi ziv, yes it’s very relevant :smiling_face:
When does it going to be avaliable?

That worked Ziv!

see if you can find it and if you know why it now works…
I see

  query.contains('myField', searchWords[i]);  

has changed to

 query = query.contains('myField', searchWords[i]); 

I’m guessing that before we couldn’t tell query what it’s search parameters were without the “query =” before the formula?

Me again… hahaha
I know you just gave me exactly what I asked for, but is it possible to achieve this using Sorts and Filters instead of query? The reason I ask is because I have set sort buttons for my filter buttons, that won’t work with queries. So say a search result returns a large amount items, and they want to sort old to new, new to old, a to z or z to a, they can’t do this at the moment, even though I have buttons there for it.

So I’m thinking of doing one of these options based on your answer. Listed from Most to Least preferred.

  • Change search results to filter instead of query.
    or
  • Hide buttons if the search a query is active.
    or
  • Create a separate page for searching.

not sure I follow…
what prevents you from adding a sorting operation to the query?
just do a .descending or .ascending to the query before running it…

Navit - please open a new post for this, this one is search related.
thanks.

Hi, guys!!

It WORKS!!! I followed Nayeli’s video and it worked like a charm! The only hiccup I had was that in my search results table, the results are showing the RichText code as well as the text, instead of just the text. (see screenshot) I may just be missing something simple, but obviously, I would like just the text to appear. Do I need two identical columns in my database with identical information - one with RichText formatting for the Dynamic Page and one unformatted for tables (please say no, please say no . . . ).

Also, this particular search is always going to return just one record. Is it possible to send the results straight to the dynamic page or to regular text fields right there on the search page instead of to a results table so I could make it look pretty?

Thank you so much to everyone on the Wix Code team for being so patient with us newbie coders and to the other beta team members for sharing our work!! Thank you, thank you, thank you!!

Hi walking B,
lets start a new thread for this.
this one is about search…

Ziv,

what prevents you from adding a sorting operation to the query?
I have no idea, but my filter/sort buttons stop working entirely once a query has been submitted.

I have sort and filter buttons using this code

Filter Button(s)

// ... filter videos to TAG
export function TAGButton_onClick(event) {
		console.log("filtering videos to TAG");

 $w("#videos").setFilter( wixData.Filter().contains('tags', 'TAG') )
 
      .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
}

Sort Buttons

export function OldNewButton_onClick(event) {
			console.log("Sorted Videos Oldest To New");
			session.setItem("sortOldNewEnabled", "value");
$w("#myCollection").setSort( wixData.sort()
  .ascending("created")

)
  .catch( (error) => {
    let errorMsg = error.message;
      let code = error.code;
        } );  
}

export function NewOldButton_onClick(event) {
			console.log("Sorted Videos Newest To Old");
			session.setItem("sortNewOldEnabled", "true");
$w("#myCollection").setSort( wixData.sort()
  .descending("created")  
)
  .catch( (error) => {
    let errorMsg = error.message;
      let code = error.code;
        } );  
}

export function ZAButton_onClick(event) {
			console.log("Sorted Videos Z To A");
			session.setItem("sortZAEnabled", "true");
$w("#myCollection").setSort( wixData.sort()
  .descending("title")
)
  .catch( (error) => {
    let errorMsg = error.message;
      let code = error.code;
        } );  
}

export function AZButton_onClick(event) {
			console.log("Sorted Videos A To Z");
			session.setItem("sortAZEnabled", "true");
$w("#myCollection").setSort( wixData.sort()
  .ascending("title")
)
 .catch( (error) => {
     let errorMsg = error.message;
         let code = error.code;
           } );   
}

The query is default sorted to .descending(“created”). What happens is I run a search and the results appear as they should. But when I click the sort buttons connected to the code above. Say I click the sort Z - A, or the Old - New button, they don’t sort the query results, they do, nothing.

All my filter buttons also break, so I think need a way to turn the search method into a dataset .contains filter instead of a query.

Otherwise I need a way to clear/remove the query before filtering when clicking the filter buttons and a way to hide the sort buttons when a query is active.

I’m sorry if that doesn’t explain it any better.

Hi All, I tried the same code as Nayeli’s after watching her beautiful video and it worked for me. But now it’s not. No error in preview mode as well.

Can you post a screenshot of your TA_Classes collection contents?

It’s me again :wink:

So … Help please …

Seems after using this code so many times (and having it work successfully) …I am stuck …

Post: The code performs the search but fails to connect the table rows to anything.

Thank you so much for this awesome discussion. I have two questions:

  1. I want to use the search feature for my database, allowing users to search the ‘title’ column from my database. However, instead of showing results in a table, I just want the ‘on click’ to take the users to a dynamic page with the value they insert. For example: If someone types “neurons” in the textbox and hit submit, I want them to be taken to the page R-Suri.com/key-terms/neurons. How can I make this happen?

  2. Is there a way to allow users to hit the ‘enter’ key in addition to clicking on the submit button. I was looking at duplicating the same code as the one I would use for submit button, but with the ‘onKeyPress’ command. Thoughts?

Can the search function search in more then one colum?
I’ve tried:


But it gives me the following error code

Hello Yoav, Ziv, Nayeli

I have a dynamic page, which displayed data extracted from database, based on user input, perfectly (thanks to Nayeli’s video) ! Now, this database also has a document field, how do I connect this document to the first column of the data fetched from the databse, so that it can be downloaded when clicked on first column?

The table element here is not connected with the database and is accessed and displayed through code only, as explained in varoius examples in forum.

Following is the code am using

import wixData from ‘wix-data’;

export function partySearch_onclick(event) {
let searchValue = $w(‘#partyInput’).value;

 wixData.query('JudgmentNotes') 
    .contains('title', searchValue) 

    .find() 
    
    .then(res =>  
    { 
        let foundItems = res.items; 
        
        $w('#resultsTable').rows = res.items; 
    }); 

}

Following is the structure of dataset:

Column - Party Name; Type - Text; Field key - title
Column - Court; Type - Text
Column - Referrence; Type - Text
Column - Date; Type - Text
Column - Citation; Type - Text
Column - Held; Type - Text
Column - Document; Type - Document; Field key - document

With the ‘title’ Field Key, I need the ‘document’ Field Key connected.

Please guide, how to go about it.

Anupam Dubey

Hello everyone,

Problem solved. I was making a silly mistake.

Now it’s working absolutely fine.

Thanks for guiding in forum.

Dear Ziv,

i am unable to do search , although already used all coding as per described by you

My website : https://gdexindia.wixsite.com/gdexindia11
editor : https://editor.wix.com/html/editor/web/renderer/edit/7b1a1493-bd68-433a-889f-7c382be000cc?metaSiteId=cc46de08-d072-4d32-896e-6612cf62d781&editorSessionId=246D118A-8C69-4713-BA8C-505CF3C4A65F

coding : //For full API documentation, including code examples visit Velo API Reference - Wix.com

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

export function searchButton_onClick(event) {
wixData.query(‘Member-database’)
.contains(‘name’, $w(‘#input1’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
});

Please do the needful

Regards
Rajesh Dudhat

Hello Yoav,

Is it possible to search from two fields? That is, is it possible to search from the Title field and the description field that I have at the same time using a OR condition? What if I want to search the entire dynamic page for the search term instead of just one field? Is all these possible using wix code? Thanks :slight_smile: