Handling data table search of user input strings with ilike and full text match simultaneously

Hello and welcome!

You could probably do these all at the same time by using a list of query terms. This may not work as it is untested but I think what you should be trying to do is create a search based on all of the possible combinations rather than multiple searches. Does this make sense?

# Untested
@anvil.server.callable
def search_cap(search_string):
  search_terms = search_string.split()
  search_terms = [“%{}%”.format(term.lower()) for term in search_terms]
  query_list = [q.ilike(term) for term in search_terms ] + [q.full_text_match(term,raw=True) for term in search_terms ]
  search = app_tables.my_table.search(
    q.any_of(
    column1=q.any_of(*query_list),
    column2=q.any_of(*query_list),
    column3=q.any_of(*query_list),
    column4=q.any_of(*query_list),
    )
  )

I would check this line carefully too
search_terms = search_string.split() search_terms = [“%{}%”.format(term.lower()) for term in search_terms]

If you wanted to make this a little simpler, you could use the Anvil Extras Chips input component to create a list of search terms and then you could skip the splitting string code.

FYI you can paste formatted code by surrounding the code in backticks in the forum (`)

2 Likes