-4

Is there any way to search for tags... but for ex "aa bb" so I want back the tag "aa-cc" and tag "aa-ccbb". at the moment the inname searches for "aa bb" so only a tag called "aa bbcc" will be a result. is it possible to do an "or" search?

one solution would be to search for questions and look at which tags they have... but don't like that a lot...

1 Answer 1

1

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.

You must log in to answer this question.

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