You are here:  » Filter to Drop Record if match is found


Filter to Drop Record if match is found

Submitted by ChrisNBC on Tue, 2014-01-28 12:42 in

Hi David,

Hope all is going well.

I'm sure this must have come up before but I searched the forum and couldn't see anything ...I know there are already filters to drop a record if it does not contain a particular word/s. I wondered if you could tell me if there are any existing filters which drop a record if a match is found?

Thanks in advance.

Regards
Chris

Submitted by support on Tue, 2014-01-28 12:50

Hi Chris,

There's Drop Record RegExp and Drop Record If Not RegExp for when more than simple keyword matching is required. In the text box on the configuration page for the filter, you can match multiple keywords for example using:

(keyword1|keyword2|keyword3)

e.g. a pipe-separated list of expressions to match (each can be a regular expression in its own right), all enclosed in brackets. Be careful not to include any superfluous white space...

Cheers,
David.
--
PriceTapestry.com

Submitted by Actual on Sun, 2014-02-09 19:02

I have tried using a global filter with both Drop Record and Drop Record RegExp. Neither option actually removed the product when I put the keyword in. Does Drop Record required in enclosed in brackets as well? I'ved tried it with and without. Any clues? An example of use would be great...

Submitted by support on Mon, 2014-02-10 08:58

Hi Actual,

Drop Record doesn't require brackets as the value is just provided as the $needle parameter to PHP's strstr() function.

Drop Record RegExp only requires brackets if you wish to match more than one value (although they won't do any harm with just one), this is where you can use, e.g.

(value 1|value 2|value 3)

Each value, separated by PIPE within the brackets is a regexp in its own right - so one thing to bear in mind is that if the value you are trying to match contains characters that are significant in regexp's they need to be escaped, for example to match AB-1234 the "-" must be escape so you would use:

AB\-1234

That's unlikely to be the problem here if you're not able to drop the record with the basic Drop Record filter, so going back to that filter, bear in mind that it is case sensitive so "widget" would not match "Widget". If you wanted to make it case insensitive, then in includes/filter.php look for the following code at line 181:

  $filter_dropRecordFlag = (strstr($text,$filter_data["text"]) !== FALSE);

...and REPLACE with:

  $filter_dropRecordFlag = (stristr($text,$filter_data["text"]) !== FALSE);

Hope this helps! If still not sure, if you could post an example of the product name you're trying to drop and the value being used in the filter I'll check it out further with you of course...

Cheers,
David.
--
PriceTapestry.com

Submitted by Actual on Thu, 2014-02-27 19:14

Hi David,

I've implemented the case insensitive mod above at line 181 because I was having trouble filtering some categories about with Drop Record RegExp

I have 2 categories, names as such (without the '):
'Beds Pillowcases'
'Beds Pillows'
'Beds Storage Boxes'

I have tried Drop Record RegExp on the category field with this:
(pillowcases|pillows|storage boxes)

but they don't filter out! What am I doing wrong?

Just before this filter, I have run a Drop Record If Not RegExp filter, which has run fine.

Can't figure what else to do here. Hope you can help.

Steve.

Submitted by Actual on Thu, 2014-02-27 19:22

Got to the bottom of why my filter is not working. The code above at line 181 has made no difference - it still requires the case to be right. When I tried Pillows in instead of pillows, it worked fine.

Did I edit line 181 wrong or are their further edits required to remove the case?

Steve.

Submitted by support on Fri, 2014-02-28 09:24

Hi Steve,

The modification to line 181 of includes/filter.php only applies to the basic Drop Record (non reg-exp) version. To make a Drop Record [If Not] RegExp case insensitive, you can delimit the expression and add the "i" flag, for example:

/(pillowcases|pillows|storage boxes)/i

Cheers,
David.
--
PriceTapestry.com