Search with a concat alias

search using a concatenated field alias in a database query.

Overview

The search fails because the WHERE condition incorrectly requires the same search term to match multiple individual columns simultaneously.
Instead of using separate conditions in the 'Where conditions' box, add a single rule in the 'Rules list' box that uses the CONCAT_WS function to search the combined field.

Answered
Connectivity v6
Fr Fredolino 09 Dec, 2021
I have in "Fields to retrieve" this concat:
CONCAT_WS( ' ', Haupt.gattung , Haupt.art):Article.title

In the "Where conditions"
are individual queries with "OR".

For example:
(
BEAU.name / LIKE / %{data:search_freigabe_Txt}% / continue
OR
Haupt.art / LIKE / %{data:search_freigabe_Txt}% / continue
OR
Haupt.gattung / LIKE / %{data:search_freigabe_Txt}% / continue
)

In the "Searchable fields":
Haupt.art
OR
BEAU.name
OR
Haupt.gattung
)

The search works by entering individual search terms.
How does the search also work by entering the concat alias?
My setting doesn't work:

(
Haupt.art / LIKE / %{data:search_freigabe_Txt}% / continue
AND
Haupt.gattung / LIKE / %{data:search_freigabe_Txt}% / continue
)
OR
(
BEAU.name / LIKE / %{data:search_freigabe_Txt}% / continue
OR
Haupt.art / LIKE / %{data:search_freigabe_Txt}% / continue
OR
Haupt.gattung / LIKE / %{data:search_freigabe_Txt}% / continue
)

What is the problem?

F.
we webbusteruk 10 Dec, 2021
Answer
1 Likes
(
Haupt.art / LIKE / %{data:search_freigabe_Txt}% / continue
AND
Haupt.gattung / LIKE / %{data:search_freigabe_Txt}% / continue
)

The issue above is that you're using one data string to search BOTH Haupt.art and Haupt.gattung columns. Eg if your {data:search_freigabe_Txt} is "canis", both Haupt.art AND Haupt.gattung must contain "canis". So the only result that will show is if it is "canis canis".

If you wanted to search for a concat string containing Haupt.art and Haupt.gattung using one data string, you will have to use Rules list. In the Rules list box, try:
CONCAT_WS( ' ', Haupt.art, Haupt.gattung)/LIKE:%{data:search_freigabe_Txt}%
This topic is locked and no more replies can be posted.