Jorge Vargas wrote:
> Hi,
> 
> I'm trying to implement a "simple search" field in my application and
> I was wondering which will be the best way to implement it on
> SQLAlchemy. I have googled around and found several partial solutions
> but none of them convince me of being the right way.
> 
> My use case is the following. I got a textfield search box which will
> post a set of words, my webapp is to take those words and do a query
> in *any* field of the corresponding table, and it is to say within
> just one table. For example I got a User class that has
> first_name,last_name,address_fields. And I ran a query for "John
> Thompson", that will bring me back a list of user objects where any of
> the following is valid, "John" in first_name, "John" in last_name,
> "John" in address, "Thompson" in first_name, "Thompson" in last_name,
> "Thompson" in address_field.

Instead of running complex queries for searches you can try a different 
approach. You can use a Full Text Search or a solution similar to FTS.

Create a new column in User table and triggers on insert and on update. 
The triggers should convert all data from other columns to lowercase 
strings and concatenate them.

In your example you would only need to select the rows where the new 
column contains "john" or "thompson".

Pros:
- easier to search
- searches may be faster

Cons:
- redundancy of data
- may require more work (triggers etc)

Regards,
Wojciech Malinowski

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to