2

Does Stackexchange Python API provide advance filtering support?

For example:

  1. Return all the questions under tag python and javascript with more than 50 upvotes.
  2. Return all the questions that has some substring matched in "title" or in "content".
  3. Include/Exclude filters on different properties.

Reference to official document is really appreciated.

ThinkGeek
  • 4,749
  • 13
  • 44
  • 91

1 Answers1

3

See the official API docs, the API does not well support complex queries directly, but the /search/advanced route does relay much of the power of the web site's search feature.

So:

  1. "Return all the questions under tag python and javascript with more than 50 upvotes."

    1. Use the /search/advanced route.
    2. Pass python;javascript in the tagged parameter.
    3. Pass score:50 in the q parameter.
    4. Live example.
    5. In that library, the equivalent call should be something like:

      .fetch('search/advanced', tagged='python;javascript', q='score:50')
      
    6. For that particular query, this would probably also work:

      .fetch('questions', tagged='python;javascript', min='50', sort='votes')
      


  2. "Return all the questions that have some substring matched in "title" or in "content"."

    1. Put the word in the q parameter. For example:
      /search/advanced?q=flask score:50&tagged=javascript
    2. Compare this to the use of the title parameter, which uses AND logic:
      /search/advanced?q=score:50&title=flask&tagged=javascript


  3. "Include/Exclude filters on different properties."

    1. That is rather vague. If you mean that you want to exclude questions that have a term, Then...
    2. /search/advanced provides the nottagged parameter.
    3. The q parameter will take some - terms just like the site search. For example"
      /search/advanced?q=-flask score:50&tagged=python;javascript

Notes:

  1. The q parameter accepts much of the question-related parameters of the site's web search.
  2. The OP states he is using this library, which has broad support for the Stack Exchange API (version 2.2).
  3. See the customary use of the term "filtering".
Brock Adams
  • 90,639
  • 22
  • 233
  • 295