SOLRを使用してMagentoのカスタム検索に「加重タグ」を変更して付与しようとしている人にとってはOKです。これを正しく行うために一晩中起きていましたが、うまくいきます...
まず、Magento でフィルターを作成し、すべての製品に適用します。私は「search_tags」と名付けました。
次に、テスト項目のフィルターで次の式を使用します。
dude^25,crazyman^25,wierdsearch^25
各単語の後にカラットが続き、その後に重みを付けます。(これは、単語が繰り返されて fulltext1_en に追加される回数です。)
それが完了したら、次のファイルを開きます。
/app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext.php
MySQL4と書かれていることは知っていますが、気にしないでください。SOLRはこのインデックスを使用します。
500 行目あたりに、次のブロックが表示されます。
if ($selects) {
$select = '('.join(')UNION(', $selects).')';
$query = $this->_getWriteAdapter()->query($select);
while ($row = $query->fetch()) {
このブロックのすぐ下に次を挿入します。 注: ここにリストした属性 ID は使用しないでください。これは私のセットアップに固有のものです。この ID を見つけるには、データベースを検索する必要があります。JOIN を使用して結合eav_attributes
しcatalog_product_entity_varchar
、SELECT を使用して検索attribut_id
し、value
WHERE entity_id = (ここに製品 ID を挿入) を使用しました。面倒ですが、それしか方法はありません。これにより、その製品のすべての属性が返されます。先ほど入力したタグが付いているものを探して、その ID を取得します。それを以下のコードに挿入します。
$attr_val = $row['value']; // Set attr_val so that it can be manipulated in following IF
if ($row['attribute_id'] == 457) { // 457 is the ID of MY search_tags filter, yours WILL be different! It can be found by joining eav_attributes table and catalog_product_entity_varchar and searching for the attribute value and ID where entity_id is X
$input = $row['value']; // Set $input to value of filter
$attr_val = ""; // Create Emtpy string
$pieces = explode( ',', $input ); // Explode filter by comma
foreach ($pieces as $val){
$i=1;
$val = explode( '^', $val); // Explode each "tag" by carat
while ($i <= $val[1]) { // Loop while $i is less than or equal to the number on the right side of the carat
$i++;
$attr_val = $attr_val . " " . $val[0]; // Append $attr_val with the word to the right side of the carat
}
}
}
$result[$row['entity_id']][$row['attribute_id']] = $attr_val; // Modified from Original
それを挿入した後...次に、次のブロックをコメントアウトします。
$result[$row['entity_id']][$row['attribute_id']] = $row['value']; // ORIGINAL BLOCK -- UNCOMMENT -- DO NOT DELETE
フルテキストの再インデックスを実行すると、 fulltext1_en に、「dude」、「crazyman」、および「weirdsearch」を 25 回すべて追加したことが示されるはずです。インデックスが完成したら、サイト検索で任意のタグを検索します。タグを追加したアイテムは、一番上ではないにしても、近くに表示されるはずです。楽しみ!