アイテムがユーザーの定義した優先度とどの程度厳密に一致しているかを計算しようとしています。以下は私がそれをやったと思った方法です。しかし、私は過度に経験を積んでおらず、より良い方法があるかどうかを知りたがっています。オブジェクトの属性へのユーザーの好みとの一致一致率での並べ替え
単純な例として車を使用します。私たちは色と車のスタイル(車、バンなど)に絞り込みます。今は最初の桁は=最初の属性(白)2進数に上記を変換する場合
Color: ()White, (*)Black, ()Red
Style: ()Car, ()Van, (*)Suv, (*)Truck
:ユーザーがHTMLで選択
第一
は以下を形成します続けています。
属性コード = 0100011(黒、SUV、トラック)
パートMySQLで今二
Select item_id, attribute_code FROM items
items table = [item_id][attribute_code]
次利用のPHPの各項目は、コードの一致を属性どのように密接に計算しますユーザーの設定
// Set users attribute code to var
$user_pref = $_POST['user_att_code'];
while($row=mysql_fetch_array($result))
{
// Pull attribute_code from database and put into var
$item_code = $row['attribute_code'];
// Set counters
$count_digit = 0;
$count_match = 0;
// Length of attribute code
$length = 7;
// Start calculating match
while($count_digit <= $length)
{
// Does first digit of users code = 1?
// Does first digit of items code = 1?
if($user_pref{$count_digit} != 0 && $user_pref{$count_digit} == $item_code{$count_digit})
{
// Add a positive match point to counter
$count_match++;
}
// Next digit in code
$count_digit++;
}
if($count_match > 0)
{
// Make array of item_id and match amount
$item_search [$row['item_id']] = $count_match;
}
}
// Sort array by most similar
arsort($item_search);
次に、もう少しコードを使用してパーセンテージを計算します。
上記のことは、ユーザーが希望する属性コードをデータベースのすべてのアイテム属性コードと比較することでした。それは、各コードを数字で桁上げし、一致があるたびに集計を行いました。最後に、その項目の集計を配列に入れ、次の項目の属性コードに移動します。
user: 0100011
it_1: 0100011 = 100% match
it_2: 0100100 = 50% match
it_3: 0011000 = 0% match
// If you notice the 50% does not make sense ignore it.
// I left something out for simplification.
これはわかりました。しかし、それは良いこととは思われません。 パフォーマンスがほとんどです。 150,000アイテムを想定し、属性コードの長さは約200です。これは、1回の検索で少なくとも30,000,000回の計算(上記に基づく)です。
おそらく別の方法がありますか?これは大きな問題ですか?
+1興味深い質問 – NullUserException