ConorWebb96 / bb-type-ahead

A component used for querying tables, searching through results, selecting and then saving selected items back to the db.
8 stars 2 forks source link

Query a datasource instead of table #1

Open diogenesbrussels opened 1 year ago

diogenesbrussels commented 1 year ago

Hey @ConorWebb96

Thanks for the nice plugin, it was a project I was planning to look at to do something similar. Do you think it's possible to use a datasource rather than a table for the data? I'm using a query to obtain the data, which would allow me to do a more advanced text search in SQL, which isn't possible at the moment.

Thank you!

ConorWebb96 commented 1 year ago

Hey @diogenesbrussels,

The reason it uses the table type instead of datasource is because the table type only provides the tableID (For really performance). I'm hooking directly into the API SDK provided by Budibase to do the bulk for the searches on the tables. The main required element to perform the search function is the tableID.

Now with that said, are you basically wanting the search function to be altered so it is able to just search through a selected datasource instead? e.g. queries etc. I think this definitely can be done (If i've understood you correctly that is). I'll need to do a bit of digging to see how much work is involved.

Thanks for suggesting this! 🚀

diogenesbrussels commented 1 year ago

Hey @ConorWebb96

Thanks for the quick reply. I understand the use of the SDK API, which makes sense. I think you understood my case but here's a practical example of the request I'm making at the moment.

My SQL query look like this:

SELECT *, MATCH(`name`,`firstname`,`nickname`,`description`) AGAINST('{{search}}') AS score
FROM customers
WHERE 
MATCH(`name`,`firstname`,`nickname`,`description`) AGAINST('{{search}}')
OR `name` LIKE '%{{search}}%'
OR `firstname` LIKE '%{{search}}%'
OR `nickname` LIKE '%{{search}}%'
OR `description` LIKE '%{{search}}%'
OR `dossier` = '{{search}}';

Is it possible to modify the query bindings of a parent data provider? It wasn't obvious when I took a look. I also use a score to order the results but I don't think that has any impact. In the future, I'd like to implement a phonetic search, but that's another story :)