denniso Posted February 16, 2007 Share Posted February 16, 2007 Hi all! First I'd like to say that this is the greatest of communities and you guys helping others are worth all respect! OK, here is my question. I've made an Online Thai to English dictionary. When someone search for a word I look up the searchword in the database sorrounded by "%". I search in 2 fields, the "search word" field and in the "related words" field. The problem is that sometimes the query can return a lot of matches from the database. For example is someone likes to look up the word "cat" i get 23 pages with 50 results each. See for your self: http://english-thai-dictionary.com/index.php?action=dictionary;sa=search;fields=related;search=cat Now. I would like to put the exakt matches first in my result (if there are any exact matches ...) This record for example .... http://english-thai-dictionary.com/index.php?action=dictionary;sa=details;id=9397 is an exact match of the given search string. The search result is stored in an array like this: $dictionaryContext[$item] = array( 'ID' => &$the_data['ID'], 'S' => &$the_data['S'], 'FL' => &$the_data['FL'], 'TL' => &$the_data['TL'], 'FLWC' => &$the_data['FLWC'], 'flwctext' => $flwctext, 'FLSamp' => &$the_data['FLSamp'], 'FLOpp' => &$the_data['FLOpp'], 'FLSyn' => &$the_data['FLSyn'], 'Cls' => &$the_data['Cls'], 'FLDef' => &$the_data['FLDef'], 'TLSyn' => &$the_data['TLSyn'], 'FLNotes' => &$the_data['FLNotes'], 'TLNotes' => &$the_data['TLNotes'], 'StyleLevel' => &$the_data['StyleLevel'], 'styleleveltext' => $styleleveltext, 'StyleAge' => &$the_data['StyleAge'], 'styleagetext' => $styleagetext, 'StyleGroup' => &$the_data['StyleGroup'], 'stylegrouptext' => $stylegrouptext, 'StylePower' => &$the_data['StylePower'], 'stylepowertext' => $stylepowertext, 'StyleGeneral' => &$the_data['StyleGeneral'], 'stylegeneraltext' => $stylegeneraltext, 'Transliteration' => &$the_data['Transliteration'], 'Pending' => &$the_data['Pending'], 'EstablishedBy' => &$the_data['EstablishedBy'], 'LastUpdatedBy' => &$the_data['LastUpdatedBy'], 'TimeCreated' => &$the_data['TimeCreated'], 'TimeUpdated' => &$the_data['TimeUpdated'], 'EstablishedByUsername' => &$the_data['EstablishedByUsername'], 'EstablishedByUserID' => &$the_data['EstablishedByUserID'], 'LastUpdatedByUsername' => &$the_data['LastUpdatedByUsername'], 'LastUpdatedByUserID' => &$the_data['LastUpdatedByUserID'] ); I would like to sort the array in relevance order. That is, first I would like to put exakt matches, secondly comes matches where the search string is part of a string but sorrounded with spaces (or is at the start or at the end of the string)... like ' a <b>cat</b> ate my dog' or '<b>cat</b> people'. After that I would like to put any matches that has the searchword as a start or an ending, like '<B>cat</B>alogue'. Then the rest follows in alfabetical order .... I have no clue in how to reorder my array and howto sort it ... can you help me a little bit in the right direction? Thanks a lot in advance! Dennis Link to comment https://forums.phpfreaks.com/topic/38793-sorting-array-for-output-in-a-dictionary/ Share on other sites More sharing options...
effigy Posted February 16, 2007 Share Posted February 16, 2007 Have you considered Full-Text Searches? These can generate a rating to sort on. Link to comment https://forums.phpfreaks.com/topic/38793-sorting-array-for-output-in-a-dictionary/#findComment-186454 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.