Thursday 15 September 2011

mysql - Optimizing a sql query used for searching articles -


I have a query that I am searching for the database. The query is created in the code and the words are parametitated so that everything is good and safe. I say that because these words can not come from the table because they are generated based on the user input from the search field.

Something like this should work, I'm wondering what is better / faster way to search

  Selection amount (score * multiplier) score, AI Select a word, 'railway staff' word 2, the word 'railway worker' word union, all select 2 points, 'one railway word union select all 1 point,' Employees' word unius all selected 1 score, word 'railway' unius all selected 0 points, word 'a') word added (Select 'title' type), 1 multiplier union select all 'Summary', 1.1 Union Select All 'Description', 1.5) X Inner Join (SELECT id, 'title' TYPE, URIN All All Object ID , 'Abstract' type, search from the summary article where the summary & lieutenant;> 'Union All Substituted Art', 'Extension' type, Articles from Text to Textectains) SS Y TEP = X. Like the TPE and search, contact ('%', rule.mm, '%') Write an article on INNER ID- ID by A.ID = s.id group, DESC by title command; ;   

A functional simple demo is running.

Your query looks good enough for me. However, if you are ready to trade readability for repeating the status of joining each part of your UNION :

 , a slightly better performance The scheme can be obtained .. .. INNER JOIN (SELECT id, 'title' TYPE, title title where title like '% A railway worker%' or '% railway worker%' or '% one railway%' Or '% Employee%' or '% Railway%' such as title or title '% a%' union ALL ....    

No comments:

Post a Comment