Adding Swiftype search in MadCap Flare output?

jquery

#1

Has anybody had success using Swiftype search in their MadCap Flare output?

The script installation code causes a bug with the TopNav output (the hamburger menu navigation sporadically breaks and so does the native search feature.) It seems to be a Chrome-only bug.

We suspect this might have something to do with require.js which is used by Flare’s website framework. Any information would be helpful.


#2

Like Google Analytics, Swiftype uses an anonymous function call to initialize some global objects to store configuration data. The conflict with RequireJS was that the anonymous function also deploys the swiftype library into the page which use defines for other libraries like jQuery (a lib dependency). We changed the anonymous function to only initialize the objects, then we set the config data, finally loading the Swiftype library using RequireJS.

Here’s the original code:

(function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
  (w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
  e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
  })(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');
  _st('install','YOUR_INSTALL_KEY');

Here’s the modified code that worked with RequireJS:

(function(w, n) {
      w['SwiftypeObject'] = n;
      w[n] = w[n] || function() {
          (w[n].q = w[n].q || []).push(arguments);
      };
})(window,  '_st');
_st('install', 'YOUR_INSTALL_KEY');
require(["//s.swiftypecdn.com/install/v2/st.js"]);

Good luck to other Swiftype users. Hope someone else finds this helpful.


#3

Thank you for sharing this! I’m working to implement Swiftype on a Flare site and was getting frustrated when the menus vanished. It wasn’t limited to Chrome in my tests, either.


#4

Many thanks for posting this.
I’m evaluating Swiftype and intend to use it with Flare, and no doubt would’ve fallen at this hurdle!


#5

@cgulliver have you added faceted/filtered results to a Flare site? I’ve been able to get the basic search working on mine, but haven’t been able to set up filters. I don’t know enough JavaScript to know if it’s another Flare incompatibility, or if it’s something else.