Help

Re: Filter values based on multiple values

4756 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Rose_Haft1
8 - Airtable Astronomer
8 - Airtable Astronomer

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?

25 Replies 25

Any thoughts on having this return the recordID from the linked table, not the recordIDs that match from the table with the terms?

@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.

Ah, okay. You are building a full-text search engine of sorts, right?

  • You want the results (hits) to be field-agnostic
  • You want the hits to be ranked (maybe) based on relevance
  • Some terms and some fields carry more weight than others

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.

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);

Yep - the hash index would work.

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?

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.

Is there a way to save and store a hash and/or import it?

Also, responded in line on your page. It isn’t clear what is the format of oRecord