2

What is the Algorithm that one can use to make filters like !-u2CTCBE?

For example /2.1/filters/create?include=question.body&unsafe=false returns "filter": "!9hnGssGO4". How is this String calculated? Is it possible to implement this in an application?

1 Answer 1

3

The "algorithm" for generating these filters is not publicly available, although some information about how the strings are constructed is known. Allow me to heavily quote from Kevin Montrose's blog:

"Filters, at their core, ended up being a simple bitfield of which fields to include in a response."

So basically, the filter string is an ASCII representation of a bitfield containing information about what the filter includes and its "safe" attribute.

However, the following statement (which I strongly agree with) provides a clear explanation as to why you should avoid any attempt to reverse engineer the strings:

"The point of bit shuffling is to make it both harder to figure out the implementation (though naturally not impossible, the average developer is more than bright enough to figure our scheme out given enough time) so such “too clever for your own good” behavior is harder to pull off, and to really drive the point home that you shouldn’t be creating filters without calling /filter/create."

I see no reason why you would want to avoid calling /filter/create since it is simple, fast, and only needs to be done once.

2
  • I was just curious. /filter/create is not recommended to be used in applications according to the documentation.
    – Binoy Babu
    Nov 17, 2012 at 0:55
  • @BinoyBabu: There is nothing wrong with using the method in your application. The docs are just reminding you that filters are completely immutable and can be embedded in your application rather than generated with a call to /filter/create every time they are needed. They only need to be created once - they will continue to exist as long as you need them. Nov 17, 2012 at 1:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .