Background
I am currently re-writing a search engine...which I originally wrote a couple years ago in a hurry :)
Today, the search encompasses ~5 different internal business objects/tables: Users, Organizations, News Headlines, etc. So when the user types in "The Quick Brown Fox"
into the search box, he/she will get results of each type of business object.
Each business object has an associated stored procedure: spSearchUsers
, spSearchOrganizations
, etc.
The problem
Now, for each search, I am calling each stored procedure (via a BL -> Data Access Layer) multiple times for each business object type. For example, when the user searches for "The Quick Brown Fox"
, I send down the entire string unaltered, but also split the string on each single space, and search each word individually.
In this case, each stored procedure is called 5 times...a total of 25 separate database calls for a single search. I don't feel like this typical...but it still runs pretty quick. It takes roughly 4-5 seconds per search.
What I'd like to create
A single "master" stored procedure that takes the entire search string "The Quick Brown Fox"
that in turn calls each individual business object stored procedure (spSearchUsers
, spSearchOrganizations
, etc), performs a little bit of logic, and returns 1 result set.
So 1 search... 1 result.
Can this be achieved using stored procedures, functions, and/or user-defined table types?