Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 547509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:58:51+00:00 2026-05-13T10:58:51+00:00

I am working on a search/tag system. My original query I wrote was for

  • 0

I am working on a search/tag system. My original query I wrote was for when I was storing ‘title’, ‘description’ and a comma seperated ‘tags’ column in my article/video table. I have since realised the advantage of normalising my tags. I now have three table to deal with…

tbl_Articles

  • article_id
  • title
  • description
  • content

tbl_tag_index

  • tag_id (surrogate primary id)
  • tag_type (equals 1 for tbl_Articles,
    2 for tbl_videos)
  • tag_word_id (see table bellow)
  • tag_target_id (article_id/video_id –
    depends on tag_type)

tbl_tag_word

  • tag_word_id
  • tag_word (finally the actual tag)

This query returns the tags… only problem is it returns them as different rows. I guess I would need the results to be grouped to the same row so that my search query may work

SELECT * 
  FROM `tbl_articles` A 
  JOIN `tag_index` I ON A.article_id = I.tag_target_id 
  JOIN tag_word W ON I.tag_word_id = W.tag_word_id 
 WHERE I.tag_type_id = 1

Here is my old search query

SELECT *, 
(
(CASE WHEN `description` LIKE '%hotel%' THEN 1 ELSE 0 END) + 
(CASE WHEN `description` LIKE '%london%' THEN 1 ELSE 0 END) + 
(CASE WHEN `description` LIKE '%lazy%' THEN 1 ELSE 0 END) + 
(CASE WHEN `description` LIKE '%dog%' THEN 1 ELSE 0 END) +

(CASE WHEN `title` LIKE '%hotel%' THEN 1 ELSE 0 END) + 
(CASE WHEN `title` LIKE '%london%' THEN 1 ELSE 0 END) + 
(CASE WHEN `title` LIKE '%lazy%' THEN 1 ELSE 0 END) + 
(CASE WHEN `title` LIKE '%dog%' THEN 1 ELSE 0 END) +

(CASE WHEN `tags` LIKE '%hotel%' THEN 1 ELSE 0 END) + 
(CASE WHEN `tags` LIKE '%london%' THEN 1 ELSE 0 END) + 
(CASE WHEN `tags` LIKE '%lazy%' THEN 1 ELSE 0 END) + 
(CASE WHEN `tags` LIKE '%dog%' THEN 1 ELSE 0 END)

) AS relevance
FROM `tbl_Articles`
WHERE `description` LIKE '%hotel%'
  OR `description` LIKE '%london%'
  OR `description` LIKE '%lazy%'
  OR `description` LIKE '%dog%' 
  OR `title` LIKE '%hotel%'
  OR `title` LIKE '%london%'
  OR `title` LIKE '%lazy%'
  OR `title` LIKE '%dog%'
  OR `tags` LIKE '%hotel%'
  OR `tags` LIKE '%london%'
  OR `tags` LIKE '%lazy%'
  OR `tags` LIKE '%dog%'
ORDER BY relevance DESC
LIMIT 0 , 10;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:58:51+00:00Added an answer on May 13, 2026 at 10:58 am

    Use:

    SELECT A.*, 
           GROUP_CONCAT(DISTINCT w.tag_word ORDER BY w.tag_word ASC SEPARATOR ',') AS tags,
           COUNT(DISTINCT w.tag_word) +
           (CASE WHEN `description` LIKE '%hotel%' THEN 1 ELSE 0 END) + 
           (CASE WHEN `description` LIKE '%london%' THEN 1 ELSE 0 END) + 
           (CASE WHEN `description` LIKE '%lazy%' THEN 1 ELSE 0 END) + 
           (CASE WHEN `description` LIKE '%dog%' THEN 1 ELSE 0 END) +
    
           (CASE WHEN `title` LIKE '%hotel%' THEN 1 ELSE 0 END) + 
           (CASE WHEN `title` LIKE '%london%' THEN 1 ELSE 0 END) + 
           (CASE WHEN `title` LIKE '%lazy%' THEN 1 ELSE 0 END) + 
           (CASE WHEN `title` LIKE '%dog%' THEN 1 ELSE 0 END) AS relevance
      FROM tbl_articles A 
      JOIN tag_index I ON A.article_id = I.tag_target_id 
      JOIN tag_word W ON I.tag_word_id = W.tag_word_id 
     WHERE I.tag_type_id = 1
       AND w.tag_word IN ('hotel', 'london', 'lazy', 'dog')
    GROUP BY a.article_id, a.title, a.description, a.content
    ORDER BY relevance DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I working on a tag based search. I have three tables tag(id,name), tagXmedia(id,tag_id,media_id), and
I'm working on a search page and <datatag> tag seems to be a great
I'm working on a tag-based search. The user can search one tag or multiple
i'm designing a tag system and i'm looking for a good search algorithm. It
sql_query=SELECT id,headline,summary,body,tags,issues,published_at FROM sphinx_search I am working on the search feature of my Web
me working on search in a multilingual site (currently only english and turkish). As
I have spatial search working well with SOLR 3.2 Example : ?q=*&fq={!geofilt pt=48.86761919303129,2.3527903735351856 sfield=coordinates
I have a simple search working in my rails app, but it only searches
I am trying to put full text search working on SQL Server 2008, however
I am altering the question now! I have the search working using the following:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.