Search() function with external CSV file

1. What is the problem? Be very detailed.

I am trying to use the search function with an external CSV file.
SELECT_ONE ....... SEARCH('STREETS.CSV')
It's working, but I have 8k lines in this CSV file, so, when I open the form question on the Collect App, it freezes for 5 or 6 seconds before showing the list with the streets. When I start typing it filters the street names perfect.

My problem is with the freezing. Is there a way to not pre load all street names and only start showing results after 3 or 4 characters?

2. What app or server are you using and on what device and operating system? Include version numbers.

KoboToolBox servers

3. What you have you tried to fix the problem?

I've tried autocomplete('csvfile') with no success
I've tried the minimal appearance - It doesn't let me search, just gives me a dropdown list
I've tried select_one_from_file csvfile.csv - It doesn't load the CSV file
I've tried select_one_external csvfile.csv - It doesn't load the CSV file

4. What steps can we take to reproduce the problem?

Just try to search on a external CSV file with 8k lines.

5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.

Hi Bruno.
Welkome to thé odk community.

You will need to make use of search() options such as startswith() or contains().
We use it to filter matching lines into 400000 species name.
For the moment the documentation page is not complete ans you'll find the description of those options here : Looking for an old documentation page about search() function

"search(csvName, 'startswith', columnsToSearch, searchText)": This search expression includes all distinct rows that start with the specified text in the specified column(s) (e.g., "search('hhplotdata', 'startswith', 'respondentname', ${nameprefix})"). The third parameter specifies either a single column name to search, or a comma-separated list of column names to search. Rows with matches in any specified column will be included."

4 Likes

@mathieubossaert
Thanks very much for your help! Indeed there is no documentation for those options!
Thanks a lot! I was stuck on this for 3 days.

Much love from Recife - Brasil!

Just one more question: I had to add another field, (text search string) then in the next page I show the searched results with this search string. Is there a way to make it all happen in the same page?

Hi Bruno,

yes you can :slight_smile:
Try the field-list appearence for your group of questions : https://odk-demo.readthedocs.io/en/latest/form-widgets.html#field-list

Mathieu

1 Like

I'm still having trouble getting this to work as the link to the advanced search-and-select sample form in the current XLSforms documentation isn't functioning.

I've attached these old samples files from that were in the old documentation link above, however, when I upload these as they are it doesn't look like they are working properly. For the "Please select the household's region" question in row 17 my form looks like this:

So it looks like it is only referencing the choices tab and not the hhplotdetails.csv despite having "search('hhplotdetails')" in the appearance column.

If anyone has a basic sample XLSform with partner CSV that would be HIGHLY appreciated.

hhplotdetails.csv (16.4 KB)
Sample-SearchAndSelect.xls (58 KB)

The search() appearance/function does not work in web forms. Unless you have more than 50k or so rows in your CSV or are using slow devices, we generally recommend using select_one_from_file with a choice_filter which works exactly the same way as a select from a choice list in the form. You can use any kind of expression in the choice_filter column to filter the list from the CSV.

If you need to access specific columns from your CSV after you've selected an item, you can use list lookups with instance().

2 Likes

Hi @mathieubossaert
I could not open your link, please.