确定为那些希望改变,并使用SOLR给“加权标签”,以在Magento自定义搜索,我一整晚都没睡得到这个权利,但它的工作原理...
首先,在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,并获取它的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应该表明您已经添加了“花花公子”,“crazyman”和“weirdsearch”所有的25倍!索引完成后,搜索您网站搜索中的任何标签:您添加标签的那个项目应该显示在靠近顶部的位置。请享用!
来源
2012-08-31 16:13:16
Zak