I'm using Stack Exchange Data Explorer and trying to switch from Web Applications to Stack Overflow.

I enter sta into "Switch sites" field, but search showing unrelated results first (3D Printing, 3D Printing Meta, Software Engineering ...):

enter image description here

  • A quick test shows that this does not happen to all searches. It seems that a number of site names secretly contain the string "stackexchange", and you see the issue because you started "sta". The spurious sites disappear once you get to the space: "stack ". Feb 14, 2018 at 13:06

2 Answers 2


In query.siteswitcher.js the function formatMatch is defined as follows:

formatMatch: function (item) {
    return htmlEncode(item.LongName + " " + item.Url);

It will take from the /sites JSON result the attributes LongName and Url as the data to be searched.

The Url attribute is the one that doesn't play nice here as it contains the url for each site which by definition contains almost always the word stackexchange, therefor matching most items in the list.

Why it selects the few items it did is an implementation detail that can be found in autocomplete,js, specially the populate() function but I leave the analysis of that to the reader.

I would argue it is not a bug but by design.

That said: you're free to offer better logic for that function to match search terms against the collection of site items.

One option to fix this:

formatMatch: function (item) {
    return htmlEncode(item.LongName + " " + item.Url.replace('stackexchange.com',''));

but that might need extra care for meta.stackexchange.com? And by doing this you can never switch on the fully qualified dns name of the site. (unless someone posts a feature request for that)

  • It's by design but the design is also lacking for this reason ;)
    – Tim Stone
    Feb 14, 2018 at 15:32
  • @TimStone well, I can imagine you might want to switch based on the url. A quick hack could be to replace stackexchange.com in the url with an empty string. That solves the issue observed by the OP ... not nice, but hack++;
    – rene
    Feb 14, 2018 at 15:47
  • Yeah, that's probably the best, simple approach
    – Tim Stone
    Feb 14, 2018 at 15:54

Two things discovered from rene's answer:

  • under the hood site is searched by string which is combination of site's LongName and site's Url, that's the reason sites with .stackexchange.com in url are found by sta search;
  • this search uses jQuery Autocomplete plugin.

Possible solution is to use weighted search for two site's fields LongName and Url - if search term will be found in site's LongName, this site will receive more weight "points" and will appear higher in autocomplete list.

But as jQuery Autocomplete plugin has no support of it (and by the way, have been deprecated long time ago, 2010-06-23), it may be effective to use instead search library like Fuse.js:

var sites = [{
    'Url': 'https://3dprinting.stackexchange.com',
    'LongName': '3D Printing'
    'Url': 'https://sports.stackexchange.com',
    'LongName': 'Sports'
    'Url': 'https://stackoverflow.com',
    'LongName': 'Stack Overflow'

var options = {
  keys: [{
    name: 'Url',
    weight: 0.5
    name: 'LongName',
    weight: 1
var fuse = new Fuse(sites, options)

var res = fuse.search('sta');

// Stack Overflow > Sports > 3D Printing
<script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/3.0.4/fuse.min.js"></script>

You must log in to answer this question.

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