Search code examples
phphtmltumblr

Presenting a results list based on separate queries of an external site


This is more of a "is this possible?" question than one seeking help with a specific aspect of a problem. What I'd like to do is this:

Let's say I've got a site called search.com whose sole purpose is to search a site called example.org

  1. The user enters two or more terms they'd like to search for in search.com: for example, Apples AND Oranges.

  2. Search.com submits each of these terms as a separate search query to example.org. Example.org returns a list of every article in its database tagged Apples, and a list of every article in its database tagged Oranges.

  3. Search.com examines these lists and identifies the articles that are tagged with both Apples AND Oranges.

  4. The posts tagged with only one or the other term are discarded; a list of articles on Example.org tagged Apples AND Oranges is shown to the user.

The obvious question is why I can't just search for Apples AND Oranges on example.org. The problem is that example.org (really the website tumblr, if you're curious) doesn't currently allow for this in their native architecture. I'm sufficiently annoyed by this oversight and their lack of interest in implementing the capability that I'd be willing to hack together my own external solution to the problem if it were A) possible and B) not overly complex to accomplish.

So, is something like this possible? And if so, how difficult would it be to implement?


Solution

  • Tumblr offers an API, which knows a Tagged Method:

    /tagged – Get Posts with Tag

    Examples

    • http://api.tumblr.com/v2/tagged?tag=gif
    • http://api.tumblr.com/v2/tagged?tag=lol

    It outputs 20 posts by default (you can change this with the limit parameter, but only 1-20). I guess it would be possible to get more (or all) posts if you specify the timestamps with the before parameter.

    You could use any programming language you like. For some there might be special Tumblr libraries, which would make this job easier, I guess.