I'm exploring an idea to add a search box on my enterprise application that deals with car parking for staff. There is a simple textbox on the portal in the header that doesn't relate to any particular context. I deal with the following main entities:
- Companies
- Staff
- System Users
- Parking Requests
I want the user to type something like 'taxi' and the search box should show a list of results in a table with the first column showing the full keyword and a second column showing the type of entity searched.
So, the actual searching in DB will be more of a LIKE operation but we deal with that later (I'll ask the user to enter at least 3 characters on UI and then start sending queries with every keypress to keep filtering). Here is what I have right now:
SELECT
NEWID() [Id]
,CompanyId [EntityId]
,NameE [Keyword]
,'C' [Type]
FROM dbo.Companies
UNION
SELECT
NEWID() [Id]
,InternetUserId [EntityId]
,NameE [Keyword]
,'IU' [Type]
FROM InternetUsers
UNION
SELECT
NEWID() [Id]
,InternetUserId [EntityId]
,UserName [Keyword]
,'IU' [Type]
FROM InternetUsers
UNION
SELECT
NEWID() [Id]
,ParkingCardId [EntityId]
,ParkingCardId [Keyword]
,'P' [Type]
FROM ParkingCards
This works for me as a view. It works a bit slowly and with hiccups. You can see, I have the InternetUsers
table entered twice for each column of interest.
Am I on the right track here? is there a better way of doing this? Is there a fancy name for this feature that I'm trying to implement?