Guest User

Untitled

a guest
Jun 24th, 2018
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. // Bing
  2. preg_match_all('(<div class="sb_tlst">.*<h3>.*<a href="(.*)".*>(.*)</a>.*</h3>.*</div>)siU',$c_bing, $r_bing);
  3.  
  4. // Google
  5. preg_match_all("@<h3\s*class=\"r\">\s*<a[^<>]*href=\"([^<>]*)\"[^<>]*>(.*)</a>\s*</h3>@siU",$c_google,$r_google);
  6.  
  7. // Yahoo
  8. preg_match_all('(<h3><a class.*href="(.*)".*>(.*)</a>)siU',$c_yahoo,$r_yahoo);
  9.  
  10.  
  11. $final_results = array();
  12. $final_results_score = array();
  13. $fcount = 0;
  14.  
  15. for ($i = 0; $i < count($r_bing[2]); $i++){
  16. // add all the bing results to the final results directly
  17.  
  18. $final_results[$fcount] = $r_bing[1];
  19. $final_results_score[$fcount] = (10-$i); // more score more priority, so the rank 1 has 10 score
  20. $fcount++;
  21. }
  22.  
  23. for ($i = 0; $i < count($r_google[2]); $i++){
  24. // now while adding google results check if the result already exist in the final_results
  25. for($j = 0; $j < $fcount; $j++){
  26. if($final_results[$j] == $r_google[1]){
  27. // if already exist you need not re-add it, but increase its score
  28. $final_results_score[$j] += (10-$i);
  29. }
  30. else{
  31. // if not, just add it to the list
  32. $final_results[$fcount] = $r_google[1];
  33. $final_results_score[$fcount] = (10-$i); // more score more priority, so the rank 1 has 10 score
  34. $fcount++;
  35. }
  36. }
  37. }
  38. // the same procedure to the yahoo results
  39. for ($i = 0; $i < count($r_yahoo[2]); $i++){
  40.  
  41. for($j = 0; $j < $fcount; $j++){
  42. if($final_results[$j] == $r_yahoo[1]){
  43. $final_results_score[$j] += (10-$i);
  44. }
  45. else{
  46. // if not, just add it to the list
  47. $final_results[$fcount] = $r_yahoo[1];
  48. $final_results_score[$fcount] = (10-$i);
  49. $fcount++;
  50. }
  51. }
  52. }
  53.  
  54. // now that you have all the results without repeatation and also their scores
  55. // use bubble sort algorithm to arrange them in order and you are done!
  56.  
  57. for($i = 0;$i < $fcount;$i++){
  58. for($j = 0;$j < $i-1;$j++){
  59. if($final_results_score[$j] < final_results_score[$j+1]){
  60. // swap score
  61. $temp = $final_results_score[$j];
  62. $final_results_score[$j] = $final_results_score[$j+1];
  63. $final_results_score[$j+1] = $temp;
  64. // and swap search too
  65. $temp = $final_results[$j];
  66. $final_results[$j] = $final_results[$j+1];
  67. $final_results[$j+1] = $temp;
  68. }
  69. }
  70. }
Add Comment
Please, Sign In to add comment