Powerapps: Splitting search text into individual s

2019-07-11 06:47发布

问题:

I have created a table in powerapps that collects the individual strings from a text input box. The table is working and as users type in the text box it creates new items down the column. Now I am trying to Filter a Gallery to only display items that match any of the values in the table.

I am trying to filter by a multi-line text field. If a single word in the block of text matches, I would like it to display. The table will eventually be hidden from view, but as I look at it now, whenever words are typed in the text box, then separated with a space, it creates a new entry in the table.

This is the code for items on the table that works.

AddColumns(Split(SearchBox.Text," "),"Words",Result)

This is my attempted code for items on the gallery.

Filter(Projects,Details in DataTable1.Result)

Projects is the name of my data and Details is the name of the column with the multiline text I want searched.

I get an error saying the 'Result' name isn't valid. I can't find what expression to put in the second part of the Filter code. Actual results, my Gallery displays nothing when there are words typed. Expected results I want it to display all items that match at least one word from Details and the searchbox.

Thank you, Ryan Stewart

回答1:

There is no direct way to do what you want, but we can create an expression that could get to that. It will be something along the lines of:

Filter(
    Projects,
    Sum(
        ForAll(
            Filter(Split(SearchBox.Text, " "), Len(Trim(Result)) > 0),
            If(Result in Details, 1, 0)),
        Value) > 0)

Let's go through it. This sub-expression:

Filter(Split(SearchBox.Text, " "), Len(Trim(Result)) > 0)

It splits down your search text box into words, and also removes any empty words which you would get if you had two spaces between the words or leading or trailing spaces.

Then, for all words that were split, we see if that word is contained in the Details column of your list; if so we get the value 1, and 0 otherwise. The result of the ForAll sub-expression is a list of values corresponding to each the items in Projects. We then Sum those values. If any of the words from the search box were present in the details, then the sum will be greater than 0.

Finally we can filter the Projects based on that value, which should give you the result you want.