Just FYI, by “hack” I mean “a clever or quick fix to a computer program problem,” not a security exploit. When programmers talk about a “hack,” they often mean a solution that gets the job done, even though seems like it “breaks the rules,” because it uses a piece of technology in a way the maker probably didn’t intend. Sometimes this happens because the right tool for the job either doesn’t exist, or we’re too lazy to go get it—ever open a paint can with a screwdriver?

One of ChannelAdvisor’s own CSE experts, Mark Vandegrift, sent me the following hack he used to create a clever business rule for filtering. He wanted a rule that would filter out items that did NOT have certain words in their titles. Another way to put it is he wants a filter that only keeps items if their titles contain certain “keeper” words:

But the list [of keeper words] was so long that writing the filter as NOT(CONTAINS OR CONTAINS OR CONTAINS….) was not an option. So instead I created a lookup list with the words/phrases I was looking for as the “Name” and something arbitrary as the “Value” (I used “vandegrift”). I then used as part of my filter an expression that looks like this:

NOT(CONTAINS(
REPLACEWORDLIST(”topseller-title-search”,
TOLOWER($offername)),”vandegrift”)))

So the system is going through my list of “include” terms, replacing that term in the title with the arbitrary word, then looking for the arbitrary word. Thought this was worth sharing as it could have many applications. Next time you find your self writing a long string of CONTAINS OR CONTAINS… give this a try.

Thanks, Mark! Of course, what this is telling me is that Mark really needs a new function that is to REPLACEWORDLIST as CONTAINS is to REPLACE: that is, it checks a piece of text to see if it contains words from a given list. Call it CONTAINSWORDLIST.

Guess I know what I’ll be working on for my next fun project…