{"_id":"swiftype-autocomplete-jquery","_rev":"2-86a8cf6dedd4603a755c0feca68356fa","name":"swiftype-autocomplete-jquery","description":"The official Swiftype jQuery plugin for adding autocomplete functionality to a search input field","dist-tags":{"latest":"1.2.0"},"versions":{"1.2.0":{"name":"swiftype-autocomplete-jquery","version":"1.2.0","description":"The official Swiftype jQuery plugin for adding autocomplete functionality to a search input field","main":"jquery.swiftype.autocomplete.js","repository":{"type":"git","url":"https://github.com/integrallis/swiftype-autocomplete-jquery"},"author":{"name":"Swiftype"},"license":"MIT","licenseText":"Copyright 2012-2014 Swiftype, Inc.\nhttp://swiftype.com/\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"swiftype-autocomplete-jquery@1.2.0","dist":{"shasum":"24d1d03a3f7953a652ceb6e91feb39163f06a418","tarball":"https://registry.npmjs.org/swiftype-autocomplete-jquery/-/swiftype-autocomplete-jquery-1.2.0.tgz","integrity":"sha512-fwWXVmn5LcXKbpEYsSK60WhSfYC/Vcj/NRQf+MDQVuW5pA1VLYEhqkCdg4muG7RmezQx9Czx1CgZKY4joq6gsg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFA9tDddqRuhWywmGX7dzLn44AM/kz25kFROicBV3QezAiEA0lXce/s9g98SdGpkc2UIpQKWkfsEuR1W9KShD+5Qvro="}]},"maintainers":[{"name":"bsbodden","email":"bsbodden@integrallis.com"}],"_npmUser":{"name":"bsbodden","email":"bsbodden@integrallis.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/swiftype-autocomplete-jquery-1.2.0.tgz_1515350198304_0.4135534088127315"}}},"readme":"Swiftype jQuery Autocomplete Plugin\n=========\n\nThe official [Swiftype](http://www.swiftype.com) jQuery plugin for adding autocomplete functionality to a search input field, backed by data from the Swiftype Search API. Learn more about Swiftype by visiting [swiftype.com](http://www.swiftype.com) and creating an account.\n\nPrerequisites\n------------\n1. A Swiftype account. Sign up at [swiftype.com](http://www.swiftype.com).\n2. A Swiftype search engine with some data in it.\n\n\nInstallation\n------------\n\nInclude the following in the header of your webpage:\n\n* the latest version of jQuery\n* the Swiftype jQuery plugin\n* (optional) the Swiftype Autocomplete stylesheet\n\nAll together it should look like this:\n\n\t<script type=\"text/javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js\"></script>\n\t<script type=\"text/javascript\" src=\"jquery.swiftype.autocomplete.js\"></script>\n\t<link type=\"text/css\" rel=\"stylesheet\" href=\"autocomplete.css\" media=\"all\" />\n\n\nBasic Usage\n-----\n\nSimply apply the swiftype method to an existing search input field on your webpage. For example, add it to a search input field with id `st-search-input` as follows:\n\n\t$('#st-search-input').swiftype({ \n\t  engineKey: 'jaDGyzkR6iYHkfNsPpNK'\n\t});\n\nBe sure to change the `engineKey` attribute shown above to match the one assigned to your Swiftype search engine. If you are using the web interface, the search engine key is listed on the first page of your dashboard.\n\nThis simple installation will by default match the string a user is typing into your search input to any of the items indexed in your search engine. By default, the string is matched against any fields you have indexed with type `string`.\n\n\nCustomization Tutorial\n-------------\n\nThis plugin is written to be flexible based on your specific use-case. \nFor example you might want to retrieve more data for each element in the dropdown, customize\nthe way data is display to the user, or restrict the autocomplete query to certain elements of your search engine. \n\nLet's go through an example that does all of this. For this example, let's assume you followed the QuickStart tutorial for our [Ruby Gem](https://github.com/swiftype/swiftype-rb), and now you have data for a Bookstore indexed in your example search engine.\n\n#### Changing the number of results\n\nTo specify the number of results you would like returned from the API, set the `resultLimit` attribute as follows:\n\n\t$('#st-search-input').swiftype({ \n\t\tengineKey: 'jaDGyzkR6iYHkfNsPpNK',\n\t\tresultLimit: 20\n\t});\n\n\n#### Fetching only the fields you specify\n\nTo specify the fields you would like returned from the API, set the `fetchFields` attribute to a hash containing an array listing the fields you want returned for each document type. For example, if you have indexed `title`, `genre`, and `published_on` fields for each document, you can have them returned as follows:\n\n\t$('#st-search-input').swiftype({ \n\t\tfetchFields: {'books': ['title','genre','published_on']},\n\t\tengineKey: 'jaDGyzkR6iYHkfNsPpNK'\n\t});\n\nThese additional fields will be returned with each item in the autocomplete, and they can be accessed in the rendering function as shown in the next section.\n\n#### Customizing the display\n\nNow that you have more data for each autocomplete item, you'll want to customize the item rendering function to make use of them.\n\nThe default rendering function is shown below:\n\n\tvar defaultRenderFunction = function(document_type, item) {\n\t\treturn '<p class=\"title\">' + item['title'] + '</p>';\n\t};\n\nThe additional fields are available as keys in the item dictionary, so you could customize this to make use of the `genre` field as follows:\n\n\tvar customRenderFunction = function(document_type, item) {\n\t\tvar out = '<p class=\"title\">' + item['title'] + '</p>';\n\t\treturn out.concat('<p class=\"genre\">' + item['genre'] + '</p>');\n\t};\n\nNow simply set the `renderFunction` attribute in the options dictionary to your `customRenderFunction` to tell our plugin to use your function to render results:\n\n\t$('#st-search-input').swiftype({ \n\t\trenderFunction: customRenderFunction,\n\t\tfetchFields: {'books': ['title','genre','published_on']},\n\t\tengineKey: 'jaDGyzkR6iYHkfNsPpNK'\n\t});\n\n\n#### Restricting matching to particular fields\n\nBy default, the Swiftype autocomplete library will match the string the user is typing to any `string` field indexed for your documents. So if you would like to ensure that it only matches entries in the `title` field, for example, you can specify the `searchFields` option:\n\n\t$('#st-search-input').swiftype({ \n\t\trenderFunction: customRenderFunction,\n\t\tfetchFields: {'books': ['title','genre','published_on']},\n\t\tsearchFields: {'books': ['title']},\n\t\tengineKey: 'jaDGyzkR6iYHkfNsPpNK'\n\t});\n\nSimilarly to the `fetchFields` option, `searchFields` accepts a hash containing an array of fields for each document_type on which you would like the user's query to match. \n\n#### Specifying additional query conditions\n\nNow let's say you only want your autocomplete to display books that are of the **fiction** `genre` and are **in_stock**. In order to restrict search results, you can pass additional query conditions to the search API by specifying them as a dictionary in the `filters` field. Multiple clauses in the filters field are combined with AND logic:\n\n\n\t$('#st-search-input').swiftype({ \n\t\trenderFunction: customRenderFunction,\n\t\tfetchFields: {'books': ['title','genre','published_on']},\n\t\tfilters: {'books': {'genre': 'fiction', 'in_stock': true}},\n\t\tsearchFields: {'books': ['title']},\n\t\tengineKey: 'jaDGyzkR6iYHkfNsPpNK'\n\t});\n\n\n\nQuestions?\n----------\nGet in touch! We would be happy to help you get up and running. ","maintainers":[{"name":"bsbodden","email":"bsbodden@integrallis.com"}],"time":{"modified":"2022-06-27T02:57:26.328Z","created":"2018-01-07T18:36:38.397Z","1.2.0":"2018-01-07T18:36:38.397Z"},"repository":{"type":"git","url":"https://github.com/integrallis/swiftype-autocomplete-jquery"},"author":{"name":"Swiftype"},"license":"MIT","readmeFilename":"README.md"}