regex - String intersection (find video with matching tags) in PostgreSQL -


i have postgres database videos have tags. tags stored alphabetically in semicolon delimited list. want able query database list of tags , return video highest match.

i've looked @ using regexp_match, ~, , others.

the best i've come far mediocre heuristic searches tags regex i.e.

select videos tags ~ 'kitten.*laser' 

bonus (imo) match tags fat-kitten or big-laser

but problem here if video missing 1 of tags won't in result, , if user picks many tags won't see videos. remedy started iterating number of videos want , popping off less relevant tags, that's probabilistic @ best , disaster @ worst.

what i'm looking kind of postgres query can pass in regex , find results videos largest intersection.

for example, let's pretend we're querying following data:

cat;disaster;mouse kitten;mouse;piano cat;mouse;keyboard 

an optimal query tags cat, mouse, keyboard return rows in following order

cat;mouse;keyboard cat;disaster;mouse kitten;mouse;piano 

because 1st row contains 3 matches, next row contains 2 matches, , last row contains 1 match.

tags classic many-many thing. possible move tags own table? you'd need join table has links between tags , videos. apologies if passed approach reason, thought i'd throw out there since it's traveled.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -