0

I am using the /questions/unanswered API to try and get all unanswered questions, sorted by upvotes, and with the tags specified.

How can I pass multiple tags to the /unanswered route(s) using OR-logic between those tags?

For example: I want to look for unanswered questions with tags Vm OR vmss OR azure-functions.

I know that passing tagged=c;java will return only those questions with both tags as this is an AND constraint. I am looking for OR constraint.

If this API does not allow OR-ing the tags, then is there an alternate way of achieving this?

3
  • 1
    @Hans, thanks for replying. I am looking for stack exchange API that I can call from my app.
    – Karishma Tiwari - MSFT
    Commented Apr 23, 2018 at 22:59
  • 2
    Possible duplicate of Getting questions that have a specific tag or tags? Commented Apr 24, 2018 at 0:25
  • @BhargavRao the api that you shared does allows OR between tags but it shows answered as well as unanswered questions. I want all unanswered questions sorted by upvotes and allowing OR between tags. Commented Apr 25, 2018 at 17:45

1 Answer 1

0

Theoretically, you could do this with the /search/advanced route.
But, due to a bug, that route does not OR its tags as it is supposed to.
Go and upvote that bug report, and theoretically it will get fixed sooner.

For now, the workaround will require a little bit more work from your app:

  1. Use the /questions/unanswered route (or the /search/advanced route with accepted=False) to query the tags one at a time.
  2. Merge the results from step one, discarding duplicates.
  3. Sort to taste.

For example, suppose I wanted the unanswered questions tagged either OR .
I would do the following:

  1. Fetch questions/unanswered?tagged=unityscript(link), paging as necessary.

  2. That gets results like:

    "items": [ {
        "tags": ["c#", "unity3d", "game-engine", "unityscript"],
        "owner": { "display_name": "Ahmed Zafar" },
        "answer_count": 1,
        "score": 7,
        "creation_date": 1432146724,
        "last_edit_date": 1432235001,
        "question_id": 30357724,
        "link": "https://stackoverflow.com/questions/30357724/destroying-clone-destroys-all-clones",
        "title": "Destroying clone destroys all clones"
      }, {
        "tags": ["c#", "unity3d", "unityscript"],
        "owner": { "display_name": "Sora" },
        "answer_count": 2,
        "score": 4,
        "creation_date": 1425211434,
        "last_edit_date": 1425215933,
        "question_id": 28793306,
        "link": "https://stackoverflow.com/questions/28793306/unity3d-crash-after-switching-a-scene-containing-a-webcamtexture",
        "title": "Unity3d crash after switching a scene containing a webcamtexture"
      },
      //etc.
    
  3. Fetch questions/unanswered?tagged=rate-limiting(link), paging as necessary.

  4. That gets results like:

    "items": [ {
        "tags": ["java", "spring", "spring-security", "oauth-2.0", "rate-limiting"],
        "owner": { "display_name": "aj.esler" },
        "answer_count": 5,
        "score": 14,
        "creation_date": 1334619572,
        "question_id": 10183168,
        "link": "https://stackoverflow.com/questions/10183168/how-to-implement-rate-limiting-based-on-a-client-token-in-spring",
        "title": "How to implement rate limiting based on a client token in Spring?"
      }, {
        "tags": ["nginx", "rate-limiting"],
        "owner": { "display_name": "linbo" },
        "answer_count": 1,
        "score": 9,
        "creation_date": 1363835060,
        "question_id": 15538728,
        "link": "https://stackoverflow.com/questions/15538728/does-nginx-httplimitreqmodule-support-per-hour-day-week",
        "title": "Does nginx HttpLimitReqModule support per hour/day/week?"
      },
      //etc.
    
  5. Merge the result sets, discarding any duplicate question_ids:

    {
      "score": 7,
      "question_id": 30357724,
      ...
    }, {
      "score": 4,
      "question_id": 28793306,
      ...
    },
    //etc.
    {
      "score": 14,
      "question_id": 10183168,
      ...
    }, {
      "score": 9,
      "question_id": 15538728,
      ...
    },
    //etc.
    
  6. Sort to taste:

    {
      "score": 14,
      "question_id": 10183168,
      ...
    }, {
      "score": 9,
      "question_id": 15538728,
      ...
    }, {
      "score": 7,
      "question_id": 30357724,
      ...
    }, {
      "score": 4,
      "question_id": 28793306,
      ...
    },
    //etc.
    
  7. Done!

4
  • I also started to do a workaround for my case using /search api. I am thinking which approach will work better for my case. Commented Apr 26, 2018 at 20:10
  • You're welcome. Do you mean the /search/advanced route? The plain /search route won't let you find unanswered questions easily. Commented Apr 26, 2018 at 20:19
  • I am using plain/search which gives both answered and unanswered questions and then using (if is_answered == false) to filter out the questions which have no answers. Commented Apr 26, 2018 at 20:24
  • I do not recommend such an approach. For example, for the 3 tags you listed in the question, there are 7,332 total questions, but only 2,605 unanswered ones. This means you would be loading 4,727 questions unnecessarily. Commented Apr 26, 2018 at 20:39

You must log in to answer this question.

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