Ok。私は現在、大学のプロジェクト (メタ検索エンジン) の集計手法に取り組もうとしています。3 つの配列を持つ 3 つの検索エンジンがあります。各配列は次のようになります。
// 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);
}
3 つの配列を 1 つの大きなリストにマージしました (これは素晴らしいことです)。
//Find duplicates:Step3:Merge Arrays (one long list)
$MergedArr=array_merge($BingArray, $GoogleArray, $BlekkoArray);
次に、重複を見つけて、それらのスコアを合計し (トップ スコアが集計リストの一番上に来るようにします。後で配列を並べ替えます)、重複エントリを削除する必要があります。
//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";
}
}
ステップ 4 はこれらのことを行いますが、現在は $newArr["trimmed URL here"][3]; のようになっています。そして、それらを降順でソートする必要があります [array_multisort()] が、$key の変更により正しく機能するかどうかは完全にはわかりません。
ステップ4を実行するためのより良い方法ですか、それともマルチソートを行うことができますか?
前もって感謝します。
編集:
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"
}
var_dump($MergedArr); の後の配列の例です。