Chris Dowdeswell
Chris Dowdeswell

Reputation: 868

How would you reproduce a tagging system like the one StackOverflow uses?

I am trying to produce a tagging system for a recruitment agency model and love the way SO separates tags and searches for the remaining phrases.

How would you compare the tags in a table to the search query etc...

I have come up with the following but it has some hickups...

  1. User enters search query
  2. Full text SQL contains() search on tbl_tags
  3. Returns 5 results
  4. Check if each "exact tag phrase" exists in original query string.
  5. If it does exist then add tagID to array.
  6. Remove tag names from original search string...
  7. Search in tbl_people for people with linked TagIDs and search text fields with remaining text.

Example search : French Project Managers with Oracle experience

Tags : [French] [Project Manager]s with [Oracle] experience

Remaining text : s with experience

Now the problem comes when I search for Project Managers it leaves me with a surplus "s"... and there are probably other bugs with this logic too that I cannot account for...

Any ideas on how to make the logic perfect?

Thanks in advance, I understand this might be a bit of an abstract question...

Upvotes: 1

Views: 318

Answers (1)

tvanfosson
tvanfosson

Reputation: 532745

You're missing a key ingredient of how StackOverflow does its search. SO requires that the user delineate the tags in the search string by explicitly putting brackets around the tags. The (probably simplified) logic would then be.

  1. Extract marked tags using regex to detect contents inside brackets
  2. Using list of most common tags, scan string for unmarked tags and extract them.
  3. Remove tag meta characters
  4. Perform full-text search, filtered by tags

Upvotes: 1

Related Questions