Skip to main content
edited body
Source Link
Brock Adams
  • 13k
  • 5
  • 39
  • 64

There is no need for a special API route, "OR" logic is easy to implement. Merely search for each term separately and then merge the results.

For example, if I wanted tags that had either javascript or for-off, I'd first search for javascript(44 tags), then for for-off(2 tags), and then merge the results to get the 45 unique tag names.

Here's a complete javascript, that you can run right now from your browser's console, that illustrates the process:

let baseSrch = "https://api.stackexchange.com/2.2/tags?pagesize=100&order=asc&sort=name&site=stackoverflow&filter=!-.G.68grSaJo";
var tagNames  = new Set();

function getTagsByName (innameParam) {
    return new Promise (otrResolve => {
        fetch (baseSrch + "&inname=" + innameParam).then (response => response.json() ).then (rJsn => {
            let zTags       = rJsn.items;
            let lclTagNames = [];

            console.log (`Found: ${zTags.length} tags:`);
            for (let tag of zTags) {
                tagNames.add (tag.name);
                lclTagNames.push (tag.name);
            }
            console.log (lclTagNames);
            otrResolve ();
        } );
    } );
}

//-- Chain the API calls, for a consistent report...
getTagsByName ("for-off").then ( () => getTagsByName ("javascript") ).then ( function () {
    console.log (`Final Result, ${ (Array.from (tagNames) ).length} tags:`);
    console.log (tagNames);
} );

This gives results like:
Found: 2 tags: 
Array [ "apps-for-office", "javascript-api-for-office" ] 
Found: 44 tags: 
Array [ "adobe-javascript", "amazon-javascript-sdk", "asynchronous-javascript", "embedded-javascript", ...
Final Result, 45 tags: 
Set [ "apps-for-office", "javascript-api-for-office", "adobe-javascript", "amazon-javascript-sdk", ...




Warning: Demo code only; not for production. Needs checks for XMLXHR errors, API Errors, and API warnings.

There is no need for a special API route, "OR" logic is easy to implement. Merely search for each term separately and then merge the results.

For example, if I wanted tags that had either javascript or for-off, I'd first search for javascript(44 tags), then for for-off(2 tags), and then merge the results to get the 45 unique tag names.

Here's a complete javascript, that you can run right now from your browser's console, that illustrates the process:

let baseSrch = "https://api.stackexchange.com/2.2/tags?pagesize=100&order=asc&sort=name&site=stackoverflow&filter=!-.G.68grSaJo";
var tagNames  = new Set();

function getTagsByName (innameParam) {
    return new Promise (otrResolve => {
        fetch (baseSrch + "&inname=" + innameParam).then (response => response.json() ).then (rJsn => {
            let zTags       = rJsn.items;
            let lclTagNames = [];

            console.log (`Found: ${zTags.length} tags:`);
            for (let tag of zTags) {
                tagNames.add (tag.name);
                lclTagNames.push (tag.name);
            }
            console.log (lclTagNames);
            otrResolve ();
        } );
    } );
}

//-- Chain the API calls, for a consistent report...
getTagsByName ("for-off").then ( () => getTagsByName ("javascript") ).then ( function () {
    console.log (`Final Result, ${ (Array.from (tagNames) ).length} tags:`);
    console.log (tagNames);
} );

This gives results like:
Found: 2 tags: 
Array [ "apps-for-office", "javascript-api-for-office" ] 
Found: 44 tags: 
Array [ "adobe-javascript", "amazon-javascript-sdk", "asynchronous-javascript", "embedded-javascript", ...
Final Result, 45 tags: 
Set [ "apps-for-office", "javascript-api-for-office", "adobe-javascript", "amazon-javascript-sdk", ...




Warning: Demo code only; not for production. Needs checks for XML errors, API Errors, and API warnings.

There is no need for a special API route, "OR" logic is easy to implement. Merely search for each term separately and then merge the results.

For example, if I wanted tags that had either javascript or for-off, I'd first search for javascript(44 tags), then for for-off(2 tags), and then merge the results to get the 45 unique tag names.

Here's a complete javascript, that you can run right now from your browser's console, that illustrates the process:

let baseSrch = "https://api.stackexchange.com/2.2/tags?pagesize=100&order=asc&sort=name&site=stackoverflow&filter=!-.G.68grSaJo";
var tagNames  = new Set();

function getTagsByName (innameParam) {
    return new Promise (otrResolve => {
        fetch (baseSrch + "&inname=" + innameParam).then (response => response.json() ).then (rJsn => {
            let zTags       = rJsn.items;
            let lclTagNames = [];

            console.log (`Found: ${zTags.length} tags:`);
            for (let tag of zTags) {
                tagNames.add (tag.name);
                lclTagNames.push (tag.name);
            }
            console.log (lclTagNames);
            otrResolve ();
        } );
    } );
}

//-- Chain the API calls, for a consistent report...
getTagsByName ("for-off").then ( () => getTagsByName ("javascript") ).then ( function () {
    console.log (`Final Result, ${ (Array.from (tagNames) ).length} tags:`);
    console.log (tagNames);
} );

This gives results like:
Found: 2 tags: 
Array [ "apps-for-office", "javascript-api-for-office" ] 
Found: 44 tags: 
Array [ "adobe-javascript", "amazon-javascript-sdk", "asynchronous-javascript", "embedded-javascript", ...
Final Result, 45 tags: 
Set [ "apps-for-office", "javascript-api-for-office", "adobe-javascript", "amazon-javascript-sdk", ...




Warning: Demo code only; not for production. Needs checks for XHR errors, API Errors, and API warnings.

Source Link
Brock Adams
  • 13k
  • 5
  • 39
  • 64

There is no need for a special API route, "OR" logic is easy to implement. Merely search for each term separately and then merge the results.

For example, if I wanted tags that had either javascript or for-off, I'd first search for javascript(44 tags), then for for-off(2 tags), and then merge the results to get the 45 unique tag names.

Here's a complete javascript, that you can run right now from your browser's console, that illustrates the process:

let baseSrch = "https://api.stackexchange.com/2.2/tags?pagesize=100&order=asc&sort=name&site=stackoverflow&filter=!-.G.68grSaJo";
var tagNames  = new Set();

function getTagsByName (innameParam) {
    return new Promise (otrResolve => {
        fetch (baseSrch + "&inname=" + innameParam).then (response => response.json() ).then (rJsn => {
            let zTags       = rJsn.items;
            let lclTagNames = [];

            console.log (`Found: ${zTags.length} tags:`);
            for (let tag of zTags) {
                tagNames.add (tag.name);
                lclTagNames.push (tag.name);
            }
            console.log (lclTagNames);
            otrResolve ();
        } );
    } );
}

//-- Chain the API calls, for a consistent report...
getTagsByName ("for-off").then ( () => getTagsByName ("javascript") ).then ( function () {
    console.log (`Final Result, ${ (Array.from (tagNames) ).length} tags:`);
    console.log (tagNames);
} );

This gives results like:
Found: 2 tags: 
Array [ "apps-for-office", "javascript-api-for-office" ] 
Found: 44 tags: 
Array [ "adobe-javascript", "amazon-javascript-sdk", "asynchronous-javascript", "embedded-javascript", ...
Final Result, 45 tags: 
Set [ "apps-for-office", "javascript-api-for-office", "adobe-javascript", "amazon-javascript-sdk", ...




Warning: Demo code only; not for production. Needs checks for XML errors, API Errors, and API warnings.