5 steps to implement word based search in Power Apps

A common requirement in Power Apps is to create a word based search on data in galleries.

Step 1 – Basic search in Power Apps

First of all I would like to have a look at some basic (not working so well) search on data in galleries.

In my example here I’m using a SharePoint list as my data source, but there is no real difference between SharePoint and Dataverse or SQL in this case.

Imagine I have an app as shown below with a textinput control and a gallery displaying list items.

5 steps to implement word based search in Power Apps Microsoft Power Apps image

To offer a basic search you could use the following code:

If(TextInput1.Text = “”,
Actions,
Filter(Actions, TextInput1.Text = Title)
)

The above code will exactly match the Title field in my data with the text typed into the search box. First issue here of course is that we want to partly match the search text with the data, so that When I type part of the Title field I will also get the data returned.

Step 2 – Partly match search text

This is going to be a small change to the above code. Just replace the = with the in and the search will now work on just typing part of a word.

If(TextInput1.Text = “”,
Actions,
Filter(Actions, TextInput1.Text in Title)
)

5 steps to implement word based search in Power Apps Microsoft Power Apps image 1

Notice that you will get a delegation warning on the in operator when you use SharePoint as a datasource.

In general I would consider alternative data source solutions when using larger volumes of data anyway as you may see some delegation warnings.

Step 3 – Searching multiple fields

Now if you wanted to search on multiple field you could also check multiple fields for your search text as shown below:

5 steps to implement word based search in Power Apps Microsoft Power Apps image 2

Still all quite simple stuff, but however about searching for each of the words that we type in the search box.

When the user searches for “List Connectors” the fiirst item in the above screenshot will appear in the results, but just imagine if a user searched for “Connectors List”, they would not get any records returned. As the total set of characters in “Connectors List” doesn’t appear in the data there will be not results returned.

Step 4 – Word based search

Now we could use somethign like this if there are two words that we are searching for:

If(TextInput1.Text = “”,
Actions,
Filter(Actions, (First(Split(TextInput1.Text, ” “)).Result in Title) && (Last(Split(TextInput1.Text, ” “)).Result in Title) )
)

5 steps to implement word based search in Power Apps Microsoft Power Apps image 3

Now all we have to do is check now just the first and last word but check all the words.

Step 5 – Word based search

To make this all work I updated the search box OnChange code to include the following code:

ClearCollect(
colWords,
Split(
TextInput1.Text,
” ”
)
);
ClearCollect(
colResults,
Distinct(
Ungroup(
ForAll(
colWords,
Filter(
Actions,
colWords[@Result] in Title
)
),
“Value”
),
{
Title: Title,
Description: Description,
Connector: Connector
}
)
)

And my Items property on the Gallery now needs to be set to:

colResults.Result

By doing this the Words that were typed into the search box will be split by the space character and the colResults collection will contain all the items that include the words that I have been looking for.

word based search in Power Apps

Continue Reading Pieter Veenstra’s Article on their blog

5 steps to implement word based search in Power Apps

A common requirement in Power Apps is to create a word based search on data in galleries. First of all I would like to have a look at some basic (not working so well) search on data in galleries.

Blog Syndicated with Pieter Veenstra’s Permission

More About This Author

Pieter Veenstra

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *