2012-08-30 106 views
0

我有一个独特的任务,我已经得到了,而且我正处在最后一步,但是这个子任务证明是非常困难的!所以你有背景:我们运行一个Magento网站,并使用定制的SOLR搜索页面。我正在使用phpSolrClient来解析Solr XML并返回可用的结果,然后从中生成搜索结果页面。Alter Magento索引全文搜索?

我得到的任务是在Magento的后端有一个“属性”,让我们称之为“search_tags”。我们的目标是能够插入一个标签,它的delimitered用逗号重量:

sight^2,hearing^1,smell^3

我想编辑Magento的全文重新索引掰开串代码,并插入标记X时间到fulltext1_en字段。所以它会增加两次“视力”,“听”一次,“闻”三次。这可以让我们说,当有人搜索榨汁机时,尽管“榨汁机”或“果汁”一词没有出现在fulltext1_en字符串中,但可以在页面上放置一个搅拌机。我已经开发了用于拉取,分割和迭代的代码...但是我现在处于停滞状态,因为我不知道在reindex过程中将哪些代码编辑到fulltext1_en中。如果任何人有任何编辑Magento的Fulltext Reindex的经验,您的意见将不胜感激!我查看了Indexer.php,但是该文件中的所有内容最多都是模棱两可的,所以这没有任何帮助!得爱Magento!

回答

0

确定为那些希望改变,并使用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_attributescatalog_product_entity_varchar并使用SELECT查找attribut_idvalue 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倍!索引完成后,搜索您网站搜索中的任何标签:您添加标签的那个项目应该显示在靠近顶部的位置。请享用!