Skip to main content

Notifications

Community site session details
Power Apps - Building Power Apps
Answered

Search in collection with multiple keywords

Like (0) ShareShare
ReportReport
Posted on 5 Jan 2023 20:36:30 by 11

Hi

 

ClearCollect(

colTest,

{ ID: "1", Color: "black", Material: "metal", Size: "small", Type: "ball", Quantity: 40 },

{ ID: "2", Color: "yellow", Material: "plastic", Size: "big", Type: "ball", Quantity: 200 },

{ ID: "3", Color: "black", Material: "metal", Size: "medium", Type: "box", Quantity: 100 },

{ ID: "4", Color: "purple", Material: "glass", Size: "small", Type: "plate", Quantity: 100 })

 

probacska_1-1672950695920.png

 


I would like to make a searchbox with a multiple keywords search.

So, when I type "black metal small ball" to the searchbox -> I would like to get the ID: "1" row in the result.
When I type "black glass" to the searchbox -> I would like to get a blank result (and not the ID: "1", ID: "3", ID: "4" rows)

All words have to be AND connection.

I tried with this code, but it's not good.

 

ClearCollect(
colWords;
Split(
Trim(TextInput1.Text);
" "
)
);;
ClearCollect(
colResults;
Distinct(
Ungroup(
ForAll(
colWords;
Filter(
colProba;
colWords[@Result] in Color || colWords[@Result] in Material || colWords[@Result] in Size || colWords[@Result] in Type
)
);
"Value"
);
ID
)
);;
RemoveIf(
colResults;
Result = Blank()
);;
Clear(colFinal);;
ForAll(
colResults;
Collect(
colFinal;
First(
Filter(
colProba;
ID = Result
)
)
)
)

  • probacska Profile Picture
    11 on 08 Jan 2023 at 10:21:58
    Re: Search in collection with multiple keywords

    This is your code, slightly modified:

    With(
     {
     _max: Max(
     colProba;
     Sum(
     ForAll(
     Split(
     Trim(TextInput1.Text);
     " "
     );
     {
     Value: If(
     Result in colProba[@Color] || Result in colProba[@Material] || Result in colProba[@Size];
     1;
     0
     )
     }
     );
     Value
     )
     )
     };
     Filter(
     colProba;
     IsBlank(TextInput1.Text) || Sum(
     ForAll(
     Split(
     Trim(TextInput1.Text);
     " "
     );
     Result in colProba[@Color] || Result in colProba[@Material] || Result in colProba[@Size] 
     );
     Value
     ) = CountRows(
     Split(
     Trim(TextInput1.Text);
     " "
     )
     )
     )
    )

     

  • probacska Profile Picture
    11 on 06 Jan 2023 at 11:11:39
    Re: Search in collection with multiple keywords

    Thank you very very much!
    It works 😉

  • Verified answer
    WiZey Profile Picture
    3,023 Super User 2025 Season 1 on 06 Jan 2023 at 10:55:19
    Re: Search in collection with multiple keywords

    I tried something like this:

     

    With(
     { 
     _max: Max(
     cltTest4;
     Sum(
     ForAll(
     Split(
     TextInput6.Text;
     " "
     );
     {
     Value: If(
     Result = cltTest4[@Color];
     1;
     0
     ) + If(
     Result = cltTest4[@Material];
     1;
     0
     ) + If(
     Result = cltTest4[@Size];
     1;
     0
     )
     }
     );
     Value
     )
     )
     };
     Filter(
     cltTest4;
     IsBlank(TextInput6.Text) || Sum(
     ForAll(
     Split(
     TextInput6.Text;
     " "
     );
     Result in [
     cltTest4[@Color];
     cltTest4[@Material];
     cltTest4[@Size]
     ]
     );
     Value
     ) = _max
     )
    )

     

    It would take a bit of time to explain the logic here, but basically it check two things at once:

     

    First, the maximum count of validated conditions. If you type "purple glass", it will check if the record validate 2 conditions, but if you type "black glass" if will check if the record validate at least 1 condition.

    Second, it will check if said record has at least the text you've input by checking in a temporary table where I've stored the color, material and size. If "purple" is stored in a record, it will return it.

     

    Can you try with this and see how it goes?

  • probacska Profile Picture
    11 on 06 Jan 2023 at 09:15:59
    Re: Search in collection with multiple keywords

    Hello WiZey!

    This is a sample collection, I use about 20 columns in the real project. I think it's easier to fill out one field than about 20 search fields and it also takes up little space.

  • WiZey Profile Picture
    3,023 Super User 2025 Season 1 on 06 Jan 2023 at 08:32:39
    Re: Search in collection with multiple keywords

    Hello @probacska ,

     

    It should be possible after spending some brainpower, but first I'd like to ask why is it not possible to have three separate text inputs for the material, the color and the size?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,743 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,079 Most Valuable Professional

Leaderboard