amaannawab923 commented on code in PR #33357:
URL: https://github.com/apache/superset/pull/33357#discussion_r2075590173


##########
superset/models/helpers.py:
##########
@@ -1888,12 +1888,26 @@ def get_sqla_query(  # pylint: 
disable=too-many-arguments,too-many-locals,too-ma
                     elif op in {
                         utils.FilterOperator.ILIKE.value,
                         utils.FilterOperator.LIKE.value,
+                        utils.FilterOperator.TEXT_SEARCH.value,
                     }:
                         if target_generic_type != GenericDataType.STRING:
                             sqla_col = sa.cast(sqla_col, sa.String)
 
                         if op == utils.FilterOperator.LIKE.value:
                             where_clause_and.append(sqla_col.like(eq))
+                        elif op == utils.FilterOperator.TEXT_SEARCH.value:
+                            # Convert to string and handle None case
+                            search_value = str(eq) if eq is not None else ""
+                            if (
+                                search_value
+                            ):  # Only add clause if search value is not empty
+                                pattern = search_value.lower()
+                                where_clause_and.append(
+                                    sa.or_(
+                                        sqla_col.ilike(f"{pattern}%"),
+                                        sqla_col.ilike(f"% {pattern}%"),

Review Comment:
   I did try using ilike but ilike fails in scenarios with strings have more 
than one substring 
   
   For example:
   In case of fullname which is usually used by most orgs 
   If someone wants to search by first name & last name they expect the same 
result 
   Let's take the name 
   "John Anderson"
   
   You want to type both john & anderson & expect the same result 
   then  ilike(" And"%) or ilike("Joh%")
   will return the same full name and infact it goes to an unlimited number of 
substrings
   
   For example: 
   Searching for James Carter Wilson
   
    ilike(" Car"%) 
    ilike(" Wil%")
    will still return James Cater wilson since the rest of the substrings also 
have a leading space
   
   
   These test cases will fail when just using ilike
   Below is a screenshot of it working in action 
   Where it returns both "Ahmad Andra" & "Andra Alsup" where andra is last name 
of the first while last name of the second respectively 
   
   <img width="1718" alt="Screenshot 2025-05-06 at 12 17 30 AM" 
src="https://github.com/user-attachments/assets/4cacad90-6a76-496d-bf25-1095efe2368f";
 />
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to