{"_id":"5769bad2f480fb0e004dc11f","parentDoc":null,"project":"56be3387be55991700c3ca0d","category":{"_id":"57698fa2e93bfd190028815c","version":"56be3388be55991700c3ca10","project":"56be3387be55991700c3ca0d","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-06-21T19:04:02.961Z","from_sync":false,"order":1,"slug":"integrations","title":"Guides"},"version":{"_id":"56be3388be55991700c3ca10","project":"56be3387be55991700c3ca0d","__v":8,"createdAt":"2016-02-12T19:33:28.313Z","releaseDate":"2016-02-12T19:33:28.313Z","categories":["56be3389be55991700c3ca11","57646709b0a8be1900fcd0d8","5764671c89da831700590782","57646d30c176520e00ea8fe5","5764715d4f867c0e002bc8e3","57698fa2e93bfd190028815c","576c2af16c24681700c902da","5787da96b008c91900aae865"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":4,"user":"5633ec9b35355017003ca3f2","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-06-21T22:08:18.084Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"In this guide, we're going to cover the basics of setting up a Websolr index to be used with [Wordpress](http://wordpress.org/) and the [Solr for Wordpress](http://wordpress.org/plugins/solr-for-wordpress/) plugin. \n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"IMPORTANT: As of this writing, there is a bug in the Solr for Wordpress plugin. It is a longstanding JavaScript issue which has not been addressed in the past year. This bug is easily fixed, thanks to user ribakker on the wordpress.org forums here: \\n\\n- [http://wordpress.org/support/topic/plugin-solr-for-wordpress-load-all-posts-not-indexing](http://wordpress.org/support/topic/plugin-solr-for-wordpress-load-all-posts-not-indexing)\\n\\nIf the plugin is not working for you, see the Troubleshooting section at the end of this document.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Getting Started\"\n}\n[/block]\nFor the purposes of this tutorial, I set up a vanilla Wordpress install downloaded the [Solr for Wordpress](http://wordpress.org/plugins/solr-for-wordpress/) plugin. Other than that, I did not add or change any settings along the way. Your situation is probably different, but it shouldn't matter at this point.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/0109017-Screenshot_1.png\",\n        \"Screenshot 1.png\",\n        924,\n        593,\n        \"#406d84\"\n      ]\n    }\n  ]\n}\n[/block]\nThe first step is to log into your administrative dashboard, and add a new plugin.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/35b3863-Screenshot_2.png\",\n        \"Screenshot 2.png\",\n        924,\n        713,\n        \"#f2f2f2\"\n      ]\n    }\n  ]\n}\n[/block]\nSearch the repository for `Solr for Wordpress.` The plugin should be the first one listed. Click `Install Now`\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/32efb36-Screenshot_3.png\",\n        \"Screenshot 3.png\",\n        759,\n        575,\n        \"#f6f6f5\"\n      ]\n    }\n  ]\n}\n[/block]\nYou may get the following screen asking you to fill in your FTP credentials. If so, simply add in the information, or ask your internet provider to tell you what it is. You can also [upload manually](http://codex.wordpress.org/Managing_Plugins#Manual_Plugin_Installation). When the installation has finished, activate the new plugin. Make sure you disable any other search plugins you may be using.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/b2fffe8-Screenshot_4.png\",\n        \"Screenshot 4.png\",\n        902,\n        479,\n        \"#dddfdf\"\n      ]\n    }\n  ]\n}\n[/block]\nYou can now edit the plugin settings by navigating to Settings > Solr Options\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/9b4c47a-Screenshot_5.png\",\n        \"Screenshot 5.png\",\n        560,\n        526,\n        \"#ededeb\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Setting up the websolr index\"\n}\n[/block]\nNow that we've prepared with Wordpress app for Solr, we need to set up an index that it can talk to.\n\nYou need to open up Websolr in a new tab and [add a new slice](https://websolr.com/slices/new) to your account. Give your index a descriptive name, select the server group nearest to your application, then select \"Solr for Wordpress\" for the Index type:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/76e2e6e-Screenshot_5a.png\",\n        \"Screenshot 5a.png\",\n        642,\n        367,\n        \"#dceae9\"\n      ]\n    }\n  ]\n}\n[/block]\nWhen this form has been filled out, go ahead and click \"Create.\" Afterwards, you will be redirected to a page that shows the status of your index and will probably show a message about taking a few minutes to complete:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/8f54a7b-Screenshot_6.png\",\n        \"Screenshot 6.png\",\n        646,\n        325,\n        \"#dbeae9\"\n      ]\n    }\n  ]\n}\n[/block]\nThe string of random characters at the end of the URL is your index's secret key. It is unique to this index, and is generally referred to as your \"websolr key.\"\n\nIf you see a message that says your index looks ok, you're done. Occasionally provisioning errors will occur and you will see a message about taking a long time to provision your index. Try appending \"/refreshing\" to the page's URL and give it a minute or two. If that doesn't clear things up, you will need to open a [support ticket](http://help.websolr.com) and have the Support Team take a closer look.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Setting up the Solr for Wordpress plugin\"\n}\n[/block]\nOnce your websolr index is up and running, switch back to your Wordpress tab. If you haven't already, navigate to the Solr options page where you should see something like this:}\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/b47722f-Screenshot_7.png\",\n        \"Screenshot 7.png\",\n        780,\n        436,\n        \"#eeeee5\"\n      ]\n    }\n  ]\n}\n[/block]\nTo connect your Wordpress site to websolr, you will want to configure a single Solr server, and use the information supplied in the image above. The only difference is the \"Solr Path,\" where you will use your unique 11-character key. Scroll down to the bottom of this page and click \"Save Changes.\" You should now get a \"Success!\" message:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/aee0709-Screenshot_8.png\",\n        \"Screenshot 8.png\",\n        756,\n        471,\n        \"#f3f3e5\"\n      ]\n    }\n  ]\n}\n[/block]\nA couple points here. If you click on \"Check Server Settings,\" you will probably get an error that says \"Ping failed!\" That is not a bug or an indication that anything is wrong. It has to do with the plugin trying to access some administrative functions that websolr blocks for security reasons. It will not affect search performance.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Checking on your index\"\n}\n[/block]\nIf you have a plain installation (like me, in this example), go ahead and create a post:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/4e0c391-Screenshot_9.png\",\n        \"Screenshot 9.png\",\n        700,\n        474,\n        \"#eff0e6\"\n      ]\n    }\n  ]\n}\n[/block]\nGive your post some content:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/167edb5-Screenshot_10.png\",\n        \"Screenshot 10.png\",\n        746,\n        518,\n        \"#080908\"\n      ]\n    }\n  ]\n}\n[/block]\nInterestingly, when we were evaluating this plugin, we noticed that it generated network traffic to the Solr instance even before the user clicks on \"Save\" or \"Publish.\" In fact, as of this writing, just giving the post a title is enough to cause the data to be sent to the websolr URL. The document will be updated in the Solr instance whenever the document is autosaved. It's unclear whether this is a bug or a feature, but definitely something to keep in mind.\n\nOnce you have published your work, you can navigate to your websolr index and see something like this:\n\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/2c73881-Screenshot_11.png\",\n        \"Screenshot 11.png\",\n        641,\n        310,\n        \"#dbeae9\"\n      ]\n    }\n  ]\n}\n[/block]\nIf you already have a large number of documents in Wordpress, you can instruct the Solr plugin to synchronize your local database with your websolr index by navigating to Settings > Solr Options and clicking on \"Load All Pages,\" \"Load All Posts,\" then \"Optimize Index.\"\n\nKeep in mind that all indexes on our shared clusters are provisioned with a 60s autoCommit setting. That means it could take up to 60s for your changes to become visible. If you index one or more documents, wait a few minutes before checking to see if they're in your index. Of course, if you have any issues with this, please feel free to open a [support ticket](http://help.websolr.com) and have the Support Team take a closer look.\n\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Troubleshooting\"\n}\n[/block]\n### Nothing happens when I try to load my posts/pages!\n\nNavigate to Plugins > Editor and select the Solr for Wordpress plugin. In the file solr-for-wordpress.php, you will find a jQuery function like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$j(document).ready(function() {\\n    switch1();\\n    $j('[name=s4w_postload]').click(function() {\\n        $j(this).after($percentspan);\\n        disableAll();\\n        doLoad(\\\"post\\\", null);\\n        $j(this).preventDefault();\\n    });\\n    \\n    $j('[name=s4w_pageload]').click(function() {\\n        $j(this).after($percentspan);\\n        disableAll();\\n        doLoad(\\\"page\\\", null);\\n        $j(this).preventDefault();\\n    });\\n});\",\n      \"language\": \"javascript\",\n      \"name\": \"solr-for-wordpress.php\"\n    }\n  ]\n}\n[/block]\nThere is something off about the function `preventDefault();`. Change this whole function to:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$j(document).ready(function() {\\n    switch1();\\n    $j('[name=s4w_postload]').click(function() {\\n        $j(this).after($percentspan);\\n        disableAll();\\n        doLoad(\\\"post\\\", null);\\n        //$j(this).preventDefault();\\n        return false;\\n    });\\n    \\n    $j('[name=s4w_pageload]').click(function() {\\n        $j(this).after($percentspan);\\n        disableAll();\\n        doLoad(\\\"page\\\", null);\\n        //$j(this).preventDefault();\\n        return false;\\n    });\\n});\",\n      \"language\": \"javascript\",\n      \"name\": \"solr-for-wordpress.php\"\n    }\n  ]\n}\n[/block]\nAnd that should fix the issue. Special thanks to ribakker on the [wordpress.org forums](http://wordpress.org/support/topic/plugin-solr-for-wordpress-load-all-posts-not-indexing) for taking the time to figure that out.\n\n### I've done everything right, but docs still aren't indexed!\n\nWe have found that some web hosts like Rackspace are configured in a way that prevents the Solr for Wordpress module from working correctly. It appears to be related to the `max_exec_time` setting for scripts in PHP.ini on the server side.\n\nThis is possibly due to the plugin attempting to index all of the pages/posts simultaneously, which could easily take upwards of 30 seconds (the default value) for even a few hundred documents. Ideally, documents would be sent in batches to avoid this problem, but the plugin doesn't seem to support that yet.\n\n If your documents are not reaching the index, check to see what the PHP error logs say. Chances are simply increasing the `max_exec_time` variable will fix the issue.","excerpt":"Learn how to add fast search to your Wordpress site by integrating it with Solr.","slug":"wordpress-1","type":"basic","title":"Wordpress"}

Wordpress

Learn how to add fast search to your Wordpress site by integrating it with Solr.

In this guide, we're going to cover the basics of setting up a Websolr index to be used with [Wordpress](http://wordpress.org/) and the [Solr for Wordpress](http://wordpress.org/plugins/solr-for-wordpress/) plugin. [block:callout] { "type": "warning", "body": "IMPORTANT: As of this writing, there is a bug in the Solr for Wordpress plugin. It is a longstanding JavaScript issue which has not been addressed in the past year. This bug is easily fixed, thanks to user ribakker on the wordpress.org forums here: \n\n- [http://wordpress.org/support/topic/plugin-solr-for-wordpress-load-all-posts-not-indexing](http://wordpress.org/support/topic/plugin-solr-for-wordpress-load-all-posts-not-indexing)\n\nIf the plugin is not working for you, see the Troubleshooting section at the end of this document." } [/block] [block:api-header] { "type": "basic", "title": "Getting Started" } [/block] For the purposes of this tutorial, I set up a vanilla Wordpress install downloaded the [Solr for Wordpress](http://wordpress.org/plugins/solr-for-wordpress/) plugin. Other than that, I did not add or change any settings along the way. Your situation is probably different, but it shouldn't matter at this point. [block:image] { "images": [ { "image": [ "https://files.readme.io/0109017-Screenshot_1.png", "Screenshot 1.png", 924, 593, "#406d84" ] } ] } [/block] The first step is to log into your administrative dashboard, and add a new plugin. [block:image] { "images": [ { "image": [ "https://files.readme.io/35b3863-Screenshot_2.png", "Screenshot 2.png", 924, 713, "#f2f2f2" ] } ] } [/block] Search the repository for `Solr for Wordpress.` The plugin should be the first one listed. Click `Install Now` [block:image] { "images": [ { "image": [ "https://files.readme.io/32efb36-Screenshot_3.png", "Screenshot 3.png", 759, 575, "#f6f6f5" ] } ] } [/block] You may get the following screen asking you to fill in your FTP credentials. If so, simply add in the information, or ask your internet provider to tell you what it is. You can also [upload manually](http://codex.wordpress.org/Managing_Plugins#Manual_Plugin_Installation). When the installation has finished, activate the new plugin. Make sure you disable any other search plugins you may be using. [block:image] { "images": [ { "image": [ "https://files.readme.io/b2fffe8-Screenshot_4.png", "Screenshot 4.png", 902, 479, "#dddfdf" ] } ] } [/block] You can now edit the plugin settings by navigating to Settings > Solr Options [block:image] { "images": [ { "image": [ "https://files.readme.io/9b4c47a-Screenshot_5.png", "Screenshot 5.png", 560, 526, "#ededeb" ] } ] } [/block] [block:api-header] { "type": "basic", "title": "Setting up the websolr index" } [/block] Now that we've prepared with Wordpress app for Solr, we need to set up an index that it can talk to. You need to open up Websolr in a new tab and [add a new slice](https://websolr.com/slices/new) to your account. Give your index a descriptive name, select the server group nearest to your application, then select "Solr for Wordpress" for the Index type: [block:image] { "images": [ { "image": [ "https://files.readme.io/76e2e6e-Screenshot_5a.png", "Screenshot 5a.png", 642, 367, "#dceae9" ] } ] } [/block] When this form has been filled out, go ahead and click "Create." Afterwards, you will be redirected to a page that shows the status of your index and will probably show a message about taking a few minutes to complete: [block:image] { "images": [ { "image": [ "https://files.readme.io/8f54a7b-Screenshot_6.png", "Screenshot 6.png", 646, 325, "#dbeae9" ] } ] } [/block] The string of random characters at the end of the URL is your index's secret key. It is unique to this index, and is generally referred to as your "websolr key." If you see a message that says your index looks ok, you're done. Occasionally provisioning errors will occur and you will see a message about taking a long time to provision your index. Try appending "/refreshing" to the page's URL and give it a minute or two. If that doesn't clear things up, you will need to open a [support ticket](http://help.websolr.com) and have the Support Team take a closer look. [block:api-header] { "type": "basic", "title": "Setting up the Solr for Wordpress plugin" } [/block] Once your websolr index is up and running, switch back to your Wordpress tab. If you haven't already, navigate to the Solr options page where you should see something like this:} [block:image] { "images": [ { "image": [ "https://files.readme.io/b47722f-Screenshot_7.png", "Screenshot 7.png", 780, 436, "#eeeee5" ] } ] } [/block] To connect your Wordpress site to websolr, you will want to configure a single Solr server, and use the information supplied in the image above. The only difference is the "Solr Path," where you will use your unique 11-character key. Scroll down to the bottom of this page and click "Save Changes." You should now get a "Success!" message: [block:image] { "images": [ { "image": [ "https://files.readme.io/aee0709-Screenshot_8.png", "Screenshot 8.png", 756, 471, "#f3f3e5" ] } ] } [/block] A couple points here. If you click on "Check Server Settings," you will probably get an error that says "Ping failed!" That is not a bug or an indication that anything is wrong. It has to do with the plugin trying to access some administrative functions that websolr blocks for security reasons. It will not affect search performance. [block:api-header] { "type": "basic", "title": "Checking on your index" } [/block] If you have a plain installation (like me, in this example), go ahead and create a post: [block:image] { "images": [ { "image": [ "https://files.readme.io/4e0c391-Screenshot_9.png", "Screenshot 9.png", 700, 474, "#eff0e6" ] } ] } [/block] Give your post some content: [block:image] { "images": [ { "image": [ "https://files.readme.io/167edb5-Screenshot_10.png", "Screenshot 10.png", 746, 518, "#080908" ] } ] } [/block] Interestingly, when we were evaluating this plugin, we noticed that it generated network traffic to the Solr instance even before the user clicks on "Save" or "Publish." In fact, as of this writing, just giving the post a title is enough to cause the data to be sent to the websolr URL. The document will be updated in the Solr instance whenever the document is autosaved. It's unclear whether this is a bug or a feature, but definitely something to keep in mind. Once you have published your work, you can navigate to your websolr index and see something like this: [block:image] { "images": [ { "image": [ "https://files.readme.io/2c73881-Screenshot_11.png", "Screenshot 11.png", 641, 310, "#dbeae9" ] } ] } [/block] If you already have a large number of documents in Wordpress, you can instruct the Solr plugin to synchronize your local database with your websolr index by navigating to Settings > Solr Options and clicking on "Load All Pages," "Load All Posts," then "Optimize Index." Keep in mind that all indexes on our shared clusters are provisioned with a 60s autoCommit setting. That means it could take up to 60s for your changes to become visible. If you index one or more documents, wait a few minutes before checking to see if they're in your index. Of course, if you have any issues with this, please feel free to open a [support ticket](http://help.websolr.com) and have the Support Team take a closer look. [block:api-header] { "type": "basic", "title": "Troubleshooting" } [/block] ### Nothing happens when I try to load my posts/pages! Navigate to Plugins > Editor and select the Solr for Wordpress plugin. In the file solr-for-wordpress.php, you will find a jQuery function like this: [block:code] { "codes": [ { "code": "$j(document).ready(function() {\n switch1();\n $j('[name=s4w_postload]').click(function() {\n $j(this).after($percentspan);\n disableAll();\n doLoad(\"post\", null);\n $j(this).preventDefault();\n });\n \n $j('[name=s4w_pageload]').click(function() {\n $j(this).after($percentspan);\n disableAll();\n doLoad(\"page\", null);\n $j(this).preventDefault();\n });\n});", "language": "javascript", "name": "solr-for-wordpress.php" } ] } [/block] There is something off about the function `preventDefault();`. Change this whole function to: [block:code] { "codes": [ { "code": "$j(document).ready(function() {\n switch1();\n $j('[name=s4w_postload]').click(function() {\n $j(this).after($percentspan);\n disableAll();\n doLoad(\"post\", null);\n //$j(this).preventDefault();\n return false;\n });\n \n $j('[name=s4w_pageload]').click(function() {\n $j(this).after($percentspan);\n disableAll();\n doLoad(\"page\", null);\n //$j(this).preventDefault();\n return false;\n });\n});", "language": "javascript", "name": "solr-for-wordpress.php" } ] } [/block] And that should fix the issue. Special thanks to ribakker on the [wordpress.org forums](http://wordpress.org/support/topic/plugin-solr-for-wordpress-load-all-posts-not-indexing) for taking the time to figure that out. ### I've done everything right, but docs still aren't indexed! We have found that some web hosts like Rackspace are configured in a way that prevents the Solr for Wordpress module from working correctly. It appears to be related to the `max_exec_time` setting for scripts in PHP.ini on the server side. This is possibly due to the plugin attempting to index all of the pages/posts simultaneously, which could easily take upwards of 30 seconds (the default value) for even a few hundred documents. Ideally, documents would be sent in batches to avoid this problem, but the plugin doesn't seem to support that yet. If your documents are not reaching the index, check to see what the PHP error logs say. Chances are simply increasing the `max_exec_time` variable will fix the issue.