You are here:  » Search & replace filters removes entries?!?


Search & replace filters removes entries?!?

Submitted by johanmichel on Fri, 2010-10-15 19:42 in

Weirdest thing, I thought I finally figured out how to have product titles replaced by using a filter. I am using the Search & Replace filters, f.e. I have lots of titles which say 'Vodafone iPhone 4' which have to be 'iPhone 4', so I added a filter 'Vodafone' to be replaced for nothing (space, or ''). Now when I import all entries that contain f.e. Vodafone are simply not imported :((((((( What am I doing wrong??

Submitted by support on Fri, 2010-10-15 20:23

Hi Johan,

I'm lookin at adding trimming (removing leading and trailing spaces) to fields after filter have been applied - but this can lead to other problems - but in the mean time, if "Vodafone " always precedes the product name, include the trailing SPACE in the Search value of your filter (replace remains as empty), e.g.

"Vodafone "

That should leave you with just "iPhone 4" if when preceded by "Vodafone "...

Cheers,
David
--
PriceTapestry.com

Submitted by johanmichel on Sat, 2010-10-16 09:21

David, your support is awesome and I'm glad the product for sure. I'm not yet sure how to remove f.e. "Vodafone" from all links but I will give it many tries before adding a new post to this forum. What I find extremely weird is that records are removed with a search & replace filter (im not using a drop filter or something). Any idea why this happens?

Submitted by support on Sat, 2010-10-16 09:30

Hi Johan,

It is probably down to the duplication prevention. For a product to be imported, the required fields must be valid (Product Name, Buy URL and Price), and the product name must be unique to that merchant.

What is likely happening here, especially with a mobile phone feed, is that having removed the network operator you are left with a less unique product name, for example if you previously had "Orange iPhone 4" and "Vodafone iPhone 4", and then you remove Orange and Vodafone using filters; only the first product with the name "iPhone 4" will be imported - subsequent ones are dropped by the duplicate prevention mechanism.

Hope that makes sense - if you're still not sure of anything let me know...

Cheers,
David.
--
PriceTapestry.com

Submitted by johanmichel on Sat, 2010-10-16 10:43

o wow, thats even better, it automatically removes the duplicates. Great :) :)

Submitted by johanmichel on Sat, 2010-10-16 10:46

I was wondering, is it somehow possible to use regular expressions in search & replace mode?

Submitted by johanmichel on Sat, 2010-10-16 10:49

One more thing, it would be so awesome if I could insert general filters for all feeds. For example leaving out 'Vodafone' in every feed import. I don't think this is (yet) possible right?

Submitted by support on Sat, 2010-10-16 10:53

Hi Johan,

You could experiment with a filter based on preg_replace(). Based on the code for the Search and Replace filter, add the following code to the end of your includes/filter.php file, just before the closing PHP tag:

  /*************************************************/
  /* searchReplaceRegExp */
  /*************************************************/
  $filter_names["searchReplaceRegExp"] = "Search and Replace RegExp";
  function filter_searchReplaceRegExpConfigure($filter_data)
  {
    print "Search (Perl RegExp):<br />";
    print "<input type='text' name='search' value='".widget_safe($filter_data["search"])."' />";
    widget_errorGet("search");
    print "<br /><br />";
    print "Replace:<br />";
    print "<input type='text' name='replace' value='".widget_safe($filter_data["replace"])."' />";
    widget_errorGet("replace");
  }
  function filter_searchReplaceRegExpValidate($filter_data)
  {
    if (!$filter_data["search"])
    {
      widget_errorSet("search","required field");
    }
  }
  function filter_searchReplaceRegExpExec($filter_data,$text)
  {
    return trim(preg_replace($filter_data["search"],$filter_data["replace"],$text));
  }

This would support, for example, a search for

(Orange|Vodafone|T-Mobile)

Global filters are coming very soon with the forthcoming update to Price Tapestry described in this thread...

With that in mind - you might want to avoid making too many modifications to the code base in the mean time (I'm aiming to launch the new version within 2 weeks) - upgrading will be straight forward using the Database Tool (/admin/ menu)...

Cheers,
David.
--
PriceTapestry.com

Submitted by johanmichel on Sat, 2010-10-16 11:07

Wow, excellent David, I'll be waiting on the update :)