Saturday, 15 January 2011

sorting relevance with mysql match against multiple words in 2 tables -


In the morning,

I have a search bar on a website where I'm searching for a wildcard I wanted to search for a word word in 2 tables and 4 columns, so I changed coding to a match.

I have the relevance order of this issue. At the moment, if I search for 3 words then I would like to display the first products with those three words but it seems that the third word is to be shown in the 2nd and third position in priority. Not sure if this is due to such extensive search (column-wise) or I need to associate the relevancy per column.

I've added the boolean mode and changed the spacing to the maximum with the search string

I am using the statement prepared with PDO for maximum protection .. (I hope)

My current code ..

  $ search = filter_var ($ _GET ['s'], FILTER_SANITIZE_STRING); $ Searchfor = str_replace ('', '& gt;', $ searchfor); $ ItemResults = $ conn- & gt; Ready ("SELECT a. * Item_info_short with a left JOIN item_information b on a.id = b.id WHERE MATCH (a.title, a.manufacturer, a.item_code, a.colour, b .shortdescription) (against: BOOLEAN Search for MODE) LIMIT $ offset, $ itemsperpage "); $ ItemResults-> BindValue (': searchfor', $ searchfor, PDO :: PARAM_STR); $ ItemResults-> Executed ();   

Thanks in advance for any help

Normally But you will always need the order to ensure a certain order, but MySQL matches some of the natural language magic, because the reason for the rows is always according to relevance. Unfortunately for you, this does not apply to Boolean searches.

Says:

Boolean full-text searches have these characteristics:

  • They do the rows in order to reduce the relevancy automatically Do not Sort You can see it from the preceding query result: One with the highest relevance is the line that "MySQL" ???

    Instead of using a Boolean search, you can search for a natural language, or use other searches to do according to the results: < Pre> SELECT a. * Against the item_info_short LEFT JOIN item_information b on a.id = b.id WHERE MATCH (a.title, a.manufacturer, a.item_code, a.colour, b.shortdescription)) (Order for: Search for BOOLEAN MODE) Against match (Attil, AIMNetter, A.EtemCDID, A.Courer, B. Short Description) (Search in natural language mode) DESC LIMIT $ offset, $ itemspace ");

    Or, possibly better / faster:

      SELECT a. * Item_info_short from LEFT JOIN item_information b on a.id = b.id WHERE match (A.T.T.T. L., A.M.M., A.I.I.M.C.D., A.Coucher, B. Shortcuts) Against (search in natural language mode) DESC offset offset, $ ITSpace ");    

No comments:

Post a Comment