May 16, 2022 03:59 AM
Hi there - We are trying to filter records based on multiple IDs but it is doing so in a loop so we can’t use the || or && as we don’t always know if there are multiple and often times there are 5 or more variables.
We want something like this:
var these= tabale_await.records.filter(f_record => f_record.getCellValueAsString(“Term_at_id”) == [any of these])
Is it possible?
May 16, 2022 02:02 PM
Any thoughts on having this return the recordID from the linked table, not the recordIDs that match from the table with the terms?
May 16, 2022 02:03 PM
@Bill.French - Here is a sample table. Essentially I am trying to build the equivalent of finding all the menu items // recipes that have peanuts in them.
May 16, 2022 02:06 PM
Ah, okay. You are building a full-text search engine of sorts, right?
May 16, 2022 02:14 PM
Hi - They don’t need to be ranked, and weights aren’t important. I am trying to avoid a loop (with the type of peanut foods for example) within a loop (all the recipes).
I’d like to have it spit out all the recipes with all the types of peanuts all at once.
May 16, 2022 02:41 PM
The code below would work if I had an efficient way of mapping all the values from the table into keys.
var data = [{"id":"123","color":"Red","model":"Tesla"},{"id":"124","color":"Black","model":"Honda"},{"id":"125","color":"Red","model":"Audi"},{"id":"126","color":"Blue","model":"Tesla"}]
var keys = ["color", 'model'];
var values = ["Tesla", "Audi", "Red"];
var result = data.filter(function(e) {
return keys.every(function(a) {
return values.includes(e[a])
})
})
console.log(result);
May 16, 2022 04:28 PM
Yep - the hash index would work.
May 16, 2022 11:31 PM
Hi Bill - Thanks for the suggestion but I do not now how to do make the hash index for 8000 values. Do you have a way?
May 17, 2022 06:04 AM
Yes, it’s outlined in the article. The premise is simple - loop through all records of the table to generate JSON objects based on keys before performing the logic that uses the index. This typically takes a second or two and has the added advantage of removing duplicate keys. You are left with a clean index to perform single-digit millisecond lookups.
May 17, 2022 10:37 AM
Is there a way to save and store a hash and/or import it?
May 17, 2022 10:55 AM
Also, responded in line on your page. It isn’t clear what is the format of oRecord