1

Ok. I'm currently trying to work on the aggregation technique for a college project (Metasearch engine). I've got three search engines with three arrays. Each array is like this:

// Array created to store the query results
$GoogleArray = array ();

//Top score for Rank 1
$score=100;
//Prefix/specifier to be replaced by space for comparing the URL
$prefix = array ('http://','https://','www.');

//The variables will now be populated with values from the json(results)
foreach($js->items as $item){
    $link2 =  str_replace ($prefix, '', $item->link );
    $link = $item->link;
    $title = $item->title;
    $snippet = $item->snippet;
    //Decrements through score for each result
    $scores = $score--;
    $GoogleArray[] = array($link, $title, $snippet, $scores, $link2);
}

I've merged the three arrays into one large list (which is great):

//Find duplicates:Step3:Merge Arrays (one long list)
$MergedArr=array_merge($BingArray, $GoogleArray, $BlekkoArray);

Then I need to find the duplicates, add their scores together (so the top score goes to the top of the aggregated list; sort array later on) and remove the duplicate entry:

//Find duplicates:Step4:Find the duplicates and add them together (re-score)
//////////////////////////////////////////////
//http://stackoverflow.com/questions/5821948/
/////////////////////////////////////////////

$newArr = array();

//sum the values in a specific key of that array
foreach($MergedArr as $row){
    if($link2===$link2){
        $key = substr($row[4],0);

        $newArr[$key][0]=$row[0];
        $newArr[$key][1]=$row[1];
        $newArr[$key][2]=$row[2];
        $newArr[$key][3]+=$row[3]; //adding the values (int) here ("Scores")
    }else{
        echo "There are no duplicates";
    }
}

Step 4 does those things but now it is like $newArr["trimmed URL here"][3]; and I need to sort them in a descending order [array_multisort()] but not entirely sure if it will work properly due to the $key change.

Is their a better way to do Step 4 or can I still precede with a multisort?

Thanks in advance.

Edit:

array(30) { 

[0]=> array(5) 

{ 
[0]=> string(35) "http://www.speakeasy.net/speedtest/" 
[1]=> string(20) "Speakeasy Speed Test" 
[2]=> string(109) "Test your Internet Connection with Speakeasy's reliable and accurate broadband speed test. What's your speed?" 
[3]=> int(100) 
[4]=> string(24) "speakeasy.net/speedtest/" 
} 

[1]=> array(5) 

{ 
[0]=> string(20) "http://www.test.com/" 
[1]=> string(12) "Test Central" 
[2]=> string(158) "Test.com provides a complete software solution for creating online tests and managing enterprise and specialist certification programs, in up to 22 languages." 
[3]=> int(99) 
[4]=> string(9) "test.com/" 
} 

[2]=> array(5)

{ 
[0]=> string(33) "http://en.wikipedia.org/wiki/Test" 
[1]=> string(39) "Test - Wikipedia, the free encyclopedia" 
[2]=> string(165) "Test, TEST or Tester may refer to: Contents 1 Assessment 2 Science and technology 3 People 4 Media 5 Other 6 See also Assessment Test (assessment), an assessment ..." 
[3]=> int(98) 
[4]=> string(26) "en.wikipedia.org/wiki/Test" 
} 

Just an example of some of the array after a var_dump($MergedArr);

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.