pyairtable icon indicating copy to clipboard operation
pyairtable copied to clipboard

Add support for LOWER and SEARCH function for Airtable fields

Open daneasterman opened this issue 3 years ago • 3 comments
trafficstars

Hi there,

When using this library to do a text keyword search using the FIND method, it will not return any results if the cases of the text do not match. For example, if a title field has "Villa" but the user searches "villa", nothing will be found.

A workaround common among many Airtable API forum answers is to use the LOWER method on both the user's search term and the text in the field. Python can obviously handle the user input, forcing it to lower using the built-in method, but I think Airtable's specific LOWER method is needed to cast the whole field to lowercase.

This seems to be something a lot of developers need. How easy / possible is it to provide support for this?

See this stack overflow question for more info / context: https://stackoverflow.com/questions/42429056/how-do-you-filter-an-airtable-record-that-contains-a-given-string-but-may-also

Many thanks, Daniel

daneasterman avatar Apr 19 '22 17:04 daneasterman

Should be doable to add new formula helpers to support this. Would requiring adding SEARCH and LOWER helpers?

The result would be building a formula like this:

formula = SEARCH(LOWER(value), LOWER(FIELD('col')))

Until those helpers are added (PR welcome) , you can always build the formula manually using string formatting as shown in stackoverflow.

gtalarico avatar Apr 19 '22 17:04 gtalarico

I'm just finishing off a major feature for a web app I'm building, but after that would really like to make a contribution to this project with the LOWER method. Hopefully I can get it done by the end of this week.

daneasterman avatar Apr 21 '22 10:04 daneasterman

Also regarding the a new SEARCH helper, I don't believe it's a top priority as the FIND helper which has already been implemented does a very similar thing. See here: https://support.airtable.com/hc/en-us/articles/203255215-Formula-Field-Reference#text

TLDR: According to the support docs, SEARCH returns "empty" if nothing is found. FIND returns 0.

daneasterman avatar Apr 21 '22 10:04 daneasterman

Hey @gtalarico just a heads up I have made a PR for this enhancement request here: https://github.com/gtalarico/pyairtable/pull/171 Thanks!

daneasterman avatar Aug 18 '22 13:08 daneasterman

LOWER merged. Closing it for now since seems to be enough

gtalarico avatar Aug 24 '22 06:08 gtalarico