The Swiftype Blog / Month: August 2014

Feature Announcement: Cross Origin Resource Sharing


We’ve got some exciting news: we now offer Cross Origin Resource Sharing (CORS) for our public API. For a detailed explanation, the linked Wikipedia page is a good place to start. In layman’s terms, you can now access our read-only public API using Javascript from another site. In other words, your website can now pull information from our public API for use on that website without using JSONP. We’ve had a few customers request this instead of the previous JSONP method to deal with situations where the request is too large for a GET. It’s also bit cleaner of an implementation, so we went ahead and rolled it out across the board. It shouldn’t change anything on your end if you weren’t having issues with JSONP before.

Here’s an example of how to execute a search query with the Swiftype Public API with JSONP with jQuery:

var params = {
  q: "your search terms",    
  engine_key: "YOUR_ENGINE_KEY"

function handleSearchResults(data) {
  // do something with the search results  

$.getJSON("", params).success(handleSearchResults);

And here is the same query using CORS:

$.getJSON("", params).success(handleSearchResults);

(Note there is no callback parameter.)

We hope this makes using the Swiftype public API easier for those of you who can rely on it. JSONP will continue to be supported, of course!

NOTE: Like JSONP, CORS is only supported from our public API, as it isn’t secure to use your secret API key in front-end JavaScript.

Keep an eye on the blog for more engineering features, and as always, feel free to reach out for support.

We’ve Updated the Swiftype WordPress Search Plugin


We’ve released another new version of the Swiftype Search WordPress plugin. This release has two new features that will make Swiftype WordPress Search work even better.

First, we’ve added support for WP-CLI. This is great especially for those of you with 10,000+ posts, because indexing from the command line is much faster. You can increase the post batch size to get more posts indexed at once.

wp swiftype sync --index-batch-size=100

You can also quickly re-index by destructively dropping all the documents that have been indexed (great for development).

wp swiftype sync --destructive --index-batch-size=100

If you’ve got WP-CLI installed (and if you don’t, why not?), type wp swiftype in your WordPress directory to see help text for the available commands.

Second, we’ve merged an open source contribution by Paul Morisson to make it easier to modify the query before passing it to Swiftype. The new swiftype_search_query_string filter allows you to pre-process the search query. Add or strip quote marks, remove words from the query, or add them. For example, if you know that your visitors search for phrases more often than combinations of words, you could pre-process all your queries as phrase match to increase the likelihood that your visitors find what they are looking for.

We hope this improves the flexibility and usefulness of our WordPress plugin for all our users. As always, feel free to reach out for help.

Subscribe to our blog