| | |
Union Site Search with Relevance
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved
![]() |
I am building a site search that involves a union of two tables in two databases and needs to have relevancy factored in.
I do not want to use a full-text or boolean search.
I can search one database and one table using relevance fine. I can union the two tables and search without relevance fine. When I put relevance on both tables with the union it no longer works.
Here is the query with union that works:
Here is the query on one table with relevance that works:
Here is the query with union and relevance that does not work:
I wouldn't be surprised if I did something really silly and screwed up a paren or something. I have been working on this for days and just can't seem to find the mistake that is keeping the union with relevance from running.
Thank you for looking and I hope someone can help!
I do not want to use a full-text or boolean search.
I can search one database and one table using relevance fine. I can union the two tables and search without relevance fine. When I put relevance on both tables with the union it no longer works.
Here is the query with union that works:
MySQL Syntax (Toggle Plain Text)
(SELECT gameID,title FROM searchTest.games WHERE((title LIKE '%$searchTerm1%' OR author LIKE '%$searchTerm1%' OR description LIKE '%$searchTerm1%'))) UNION (SELECT postID,title FROM searchTest2.posts WHERE((title LIKE '%$searchTerm1%' OR username LIKE '%$searchTerm1%' OR content LIKE '%$searchTerm1%') ))
Here is the query on one table with relevance that works:
MySQL Syntax (Toggle Plain Text)
SELECT gameID,title, ((2*(title LIKE '%$searchTerm1%'))+(1.5*(author LIKE '%$searchTerm1%'))+(1*(description LIKE '%$searchTerm1%')))AS relevance FROM games WHERE(title LIKE '%$searchTerm1%' OR author LIKE '%$searchTerm1%' OR description LIKE '%$searchTerm1%')AND locked=0 ORDER BY relevance DESC
Here is the query with union and relevance that does not work:
MySQL Syntax (Toggle Plain Text)
SELECT gameID,title, ((2*(title LIKE '%$searchTerm1%'))+(1.5*(author LIKE '%$searchTerm1%'))+(1*(description LIKE '%$searchTerm1%'))) AS relevance FROM games WHERE (((title LIKE '%$searchTerm1%' OR author LIKE '%$searchTerm1%' OR description LIKE '%$searchTerm1%'))AND locked=0) UNION SELECT postID,title, ((2*(title LIKE '%$searchTerm1%'))+(1.5*(author LIKE '%$searchTerm1%'))+(1*(description LIKE '%$searchTerm1%'))) AS relevance FROM searchTest2.posts WHERE (((title LIKE '%$searchTerm1%' OR username LIKE '%$searchTerm1%' OR content LIKE '%$searchTerm1%'))AND locked=0)
Thank you for looking and I hope someone can help!
![]() |
Other Threads in the MySQL Forum
- Previous Thread: MySQL backup converting all data to lowercase
- Next Thread: Calling a procedure from Trigger
| Thread Tools | Search this Thread |
agplv3 alfresco api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization





