2132
Views
4
Comments
Aggregate LIKE operator search for words even if not sequencial
Question

Hey,

Title is a mess but I couldn't describe it well in a few words.

Here's what I have right now:

Input where you write whatever you want to search.

Let's say you type "GDBP Online" and hit search, in the list I have two strings,

1-"GDBP Online Test", which is returned on the search;

2-"GDBP Test Online", which is not returned.


In my aggregate I have a normal like operator 

SyntaxEditor Code Snippet

Content.Title like "%" + Session.Content_SearchKeyword + "%"


Although the second string doesn't have both words sequential, I still need to return it in the search because it has the two words typed in.


Is there a way I could do this?


I can't have heavy logic here, we are talking about hundreds of records. Mobile app btw.

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi,

As long as the words enter should be in the same sequence as in the table, why not replace all spaces in the filter with and %.

That should work.

Regards,

Daniel 

2021-05-27 16-55-28
Miguel Tavares

I can confirm that this works.
You can use the Replace Built-In Function to create a filter that "ignores" the white spaces and searches for every word that you're writing, disregarding their order.

Content.Title like "%" + Replace(Session.Content_SearchKeyword, " ", "%") + "%"

2019-04-09 00-57-55
carl ruhle

Hi Fábio, it is possible to get what you want, but there is a catch.

The catch is, you will have to do some work before (create a function to create the filter statement)

We will assume that the DB is Microsoft SQL Server, I think that it is.

The solution that I could get is to use the charindex function (https://docs.microsoft.com/en-us/sql/t-sql/functions/charindex-transact-sql?view=sql-server-ver15)

This is an example that you can try it out for fun

CHARINDEX(find-what, find-where, start-from-character-position)

select Content.Title
from Content
where (CHARINDEX('GDBP',Content.Title ,0)>0
and
CHARINDEX('Online',Content.Title ,0)>0
)

This will select all titles that have both variables on the title, in any order they night apear. 

Hope this will help you

Good coding ....

2022-05-06 15-55-33
Alvaro Contreras

Hi Fábio.
Did you solve this?, I have the same problem and I have tried different ways to solve it but i have not been able to.

Thanks!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.