13

I am interested in the getting a list of the question based on a tag or a search query. I will give you an example.

So If I use the search keyword as "ipv4", it should give me a big list of questions related to ipv4. All I want to do is get the questions (title) as a list or an array so that I can do some processing on it.

simhumileco
  • 31,877
  • 16
  • 137
  • 115
Vish
  • 333
  • 1
  • 4
  • 13
  • 1
    Welcome to Stack Overflow. That's a very broad question. It sounds like you're asking for details about how to construct every aspect of the code, maybe even how to program, without even specifying which language you might be working with. I doubt you'll get many or any complete answers. See [How to Ask A Good Question](http://stackoverflow.com/help/how-to-ask) and [On Topic](http://stackoverflow.com/help/on-topic) – clearlight Apr 03 '15 at 13:52

3 Answers3

8

Stackexchange offers https://api.stackexchange.com/docs/advanced-search endpoint.

So for example, get on https://api.stackexchange.com/search/advanced?site=stackoverflow.com&q=firebase would return you something like this:

enter image description here

This is simplest example but as you will find in the docs, there are numerous parameters based on which search can be performed. Some of them are:

  • accepted - true to return only questions with accepted answers, false to return only those without. Omit to elide constraint.
  • answers - the minimum number of answers returned questions must have.
  • body - text which must appear in returned questions' bodies.
  • tagged - a semicolon delimited list of tags, of which at least one will be present on all returned questions.
  • title - text which must appear in returned questions' titles.
  • user - the id of the user who must own the questions returned.
  • ...

Hope this helps!

Cheers!

Teodor Hirs
  • 449
  • 5
  • 8
6

You can get this information utilizing the questions/ route. In this call, you will pass the tag(s) you are interested in to the tagged parameter (separated by a semicolon (;)).

To constrain questions returned to those with a set of tags, use the tagged parameter with a semi-colon delimited list of tags. This is an and constraint, passing tagged=c;java will return only those questions with both tags. As such, passing more than 5 tags will always return zero results.

For your specific question (searching for ipv4), you can utilize this as a starting point:

http://api.stackexchange.com/docs/questions#order=desc&sort=activity&tagged=ipv4&filter=!BHMIbze0EPheMk572h0ktETsgnphhU&site=stackoverflow&run=true

The filter is optional, but I've stripped out some of the default fields to present a smaller example. The link above returns entries that look like this:

"items": [
{
  "tags": [
    "ruby-on-rails",
    "ipv4",
    "geokit"
  ],
  "link": "http://stackoverflow.com/questions/29460004/rails-geokit-incorrectly-converting-ipv4-address-to-latitude-and-longitude",
  "title": "Rails: Geokit incorrectly converting IPv4 address to latitude and longitude"
},
{
  "tags": [
    "networking",
    "ip",
    "ipv4",
    "maxmind",
    "cidr"
  ],
  "link": "http://stackoverflow.com/questions/28358851/merging-of-multiple-ipv4-address-blocks-on-the-basis-of-their-country-region",
  "title": "merging of multiple IPv4 address blocks on the basis of their country region"
},
...
}
Andy
  • 49,085
  • 60
  • 166
  • 233
0

I was struggling with this question on how to get relevant results from the API as even after giving relevant questions it was returning irrelevant answers then I flipped the sort option from 'activity' to 'relevance' and voila it was working similarly as the stack overflow search system and was returning same articles.

Use the advanced search option and put your question in the 'q' parameter and change the 'sort' parameter from 'activity' to 'relevance'. To search based on tags put the tags in the 'tagged' parameter, each tag separated by a semicolon.

How to get the titles: Now in the JSON response, all the matching objects are inside an array in the 'items' object. each item in the array is a question and each item has a 'title' parameter which holds the title of the question.

Example: If I were to search for the question 'how to center a div in HTML, the link will be like this https://api.stackexchange.com/2.3/search/advanced?order=desc&sort=relevance&q=how%20to%20center%20a%20div%20in%20html&site=stackoverflow

enter image description here

enter image description here

Procrastinator
  • 2,526
  • 30
  • 27
  • 36
ANISH
  • 1
  • 2