tpitale/legato — Issue #11: Custom joins of filters
Author: proby
Created: 2012-02-22 21:11:51+00:00
State: open

I'm not sure if this is an issue/feature request or if I'm incorrectly using Legato. For a set of filters I want to filter keywords that match a set of regexes while excluding a set of keywords. I'm not sure how to accomplish that. Here's an example that will hopefully make it clear what I'm thinking:

Let's say I have an array of regular expressions and an array of excluded keywords:
```
regexes = ["REGEX1","REGEX2","REGEX3"]
keywords = ["KW1","KW2","KW3"]
```

I have my model class:

```ruby
class Visits
extend Legato::Model

metrics :visits

filter :organic_searches, &lambda {matches(:medium, 'organic')}
filter :matching_regexes, &lambda { |regexes|
regexes.map { |regex| contains(:keyword, regex)}
}
filter :excluding, &lambda { |keywords|
keywords.map { |keyword| does_not_match(:keyword, keyword)}
}
end
```

Currently when I execute:
```query = Visits.matching_regexes(regexes).excluding(keywords).organic_searches(profile).filters.to_params```
I get:
```"ga:keyword=~REGEX1,ga:keyword=~REGEX2,ga:keyword=~REGEX3;ga:keyword!=KW1,ga:keyword!=KW2,ga:keyword!=KW3;ga:medium==organic"```
(the ga:keyword!= parameters are joined by OR (a comma))

What I'd like to be able to get:
```"ga:keyword=~REGEX1,ga:keyword=~REGEX2,ga:keyword=~REGEX3;ga:keyword~=KW1;ga:keyword~=KW2;ga:keyword~=KW3;ga:medium==organic"```
(the ga:keyword!= parameters are joined by AND (a semicolon))

Does this make sense?