Commit 32a04e55759c761e2148bb3cbde0b383732069e7
1 parent
ac5013c6
Exists in
master
and in
19 other branches
Use movies for autocomplete example [skip ci]
Showing
1 changed file
with
9 additions
and
10 deletions
Show diff stats
README.md
... | ... | @@ -602,15 +602,15 @@ Before getting started, a few good things to know: |
602 | 602 | If the above situations don’t apply, let’s continue. First, specify which fields use this feature. This is necessary since autocomplete can increase the index size significantly, but don’t worry - this gives you blazing faster queries. |
603 | 603 | |
604 | 604 | ```ruby |
605 | -class Book < ActiveRecord::Base | |
606 | - searchkick word_start: [:title, :author] | |
605 | +class Movie < ActiveRecord::Base | |
606 | + searchkick word_start: [:title, :director] | |
607 | 607 | end |
608 | 608 | ``` |
609 | 609 | |
610 | 610 | Reindex and search with: |
611 | 611 | |
612 | 612 | ```ruby |
613 | -Book.search "tipping poi", match: :word_start | |
613 | +Movie.search "jurassic pa", match: :word_start | |
614 | 614 | ``` |
615 | 615 | |
616 | 616 | Typically, you want to use a JavaScript library like [typeahead.js](http://twitter.github.io/typeahead.js/) or [jQuery UI](http://jqueryui.com/autocomplete/). |
... | ... | @@ -620,11 +620,10 @@ Typically, you want to use a JavaScript library like [typeahead.js](http://twitt |
620 | 620 | First, add a route and controller action. |
621 | 621 | |
622 | 622 | ```ruby |
623 | -# app/controllers/books_controller.rb | |
624 | -class BooksController < ApplicationController | |
623 | +class MoviesController < ApplicationController | |
625 | 624 | def autocomplete |
626 | - render json: Book.search(params[:query], { | |
627 | - fields: ["title^5", "author"], | |
625 | + render json: Movie.search(params[:query], { | |
626 | + fields: ["title^5", "director"], | |
628 | 627 | match: :word_start, |
629 | 628 | limit: 10, |
630 | 629 | load: false, |
... | ... | @@ -642,16 +641,16 @@ Then add the search box and JavaScript code to a view. |
642 | 641 | <script src="jquery.js"></script> |
643 | 642 | <script src="typeahead.bundle.js"></script> |
644 | 643 | <script> |
645 | - var books = new Bloodhound({ | |
644 | + var movies = new Bloodhound({ | |
646 | 645 | datumTokenizer: Bloodhound.tokenizers.whitespace, |
647 | 646 | queryTokenizer: Bloodhound.tokenizers.whitespace, |
648 | 647 | remote: { |
649 | - url: '/books/autocomplete?query=%QUERY', | |
648 | + url: '/movies/autocomplete?query=%QUERY', | |
650 | 649 | wildcard: '%QUERY' |
651 | 650 | } |
652 | 651 | }); |
653 | 652 | $('#query').typeahead(null, { |
654 | - source: books | |
653 | + source: movies | |
655 | 654 | }); |
656 | 655 | </script> |
657 | 656 | ``` | ... | ... |