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 })
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
)
)
)
)
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);
" "
)
)
)
)
Thank you very very much!
It works 😉
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?
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.
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?
WarrenBelz
146,743
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,079
Most Valuable Professional