searchjoy 0.3.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +33 -5
- data/LICENSE.txt +1 -1
- data/README.md +38 -28
- data/app/assets/javascripts/searchjoy.js +2 -0
- data/app/controllers/searchjoy/searches_controller.rb +2 -2
- data/app/models/searchjoy/search.rb +3 -9
- data/app/views/layouts/searchjoy/application.html.erb +1 -1
- data/app/views/searchjoy/searches/stream.html.erb +14 -4
- data/lib/generators/searchjoy/install_generator.rb +3 -20
- data/lib/generators/searchjoy/templates/{install.rb → install.rb.tt} +3 -5
- data/lib/searchjoy.rb +10 -19
- data/lib/searchjoy/engine.rb +13 -0
- data/lib/searchjoy/track.rb +41 -17
- data/lib/searchjoy/version.rb +1 -1
- metadata +41 -22
- data/.gitignore +0 -17
- data/Gemfile +0 -4
- data/Rakefile +0 -8
- data/searchjoy.gemspec +0 -28
- data/test/searchjoy_test.rb +0 -15
- data/test/test_helper.rb +0 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 81afb5da71ed5e2714237809e9dfa472b6e5ac2d285bdd391a635c0cf67a1735
         | 
| 4 | 
            +
              data.tar.gz: 4cc06c6f1c2379e0196655bf4379fe6a43ccafddf96cfeeb035ecae5d78026a4
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a621888af83d4b3e2dc262f82abb0be369bd53c282e06d65b2aa65525f299c6d43a857790170ce03fab55242a2cbc18515e126d776df12f4ab26daa910b17496
         | 
| 7 | 
            +
              data.tar.gz: 0e5bb79620de12393815699a577a1b09a59b7c588249b38e6ba02527285ecaaef1df61a9904cb30f8958581e8d31f37e9381ce7e4825125a75c82c4fdecc6a0b
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,23 +1,51 @@ | |
| 1 | 
            -
            ## 0.3 | 
| 1 | 
            +
            ## 0.4.3 (2020-03-06)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            - Fixed error with Groupdate 5
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## 0.4.2 (2019-10-08)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            - Added support for Sprockets 4
         | 
| 8 | 
            +
            - Require latest version of Chartkick
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            ## 0.4.1 (2019-05-26)
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            - Added support for Rails 6
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            ## 0.4.0 (2019-04-15)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            - Added support for `models` option
         | 
| 17 | 
            +
            - Added tracking for `Searchkick.multi_search`
         | 
| 18 | 
            +
            - Fixed migration for SQLite (again)
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            Breaking
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            - Removed support for Rails < 5
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            ## 0.3.2 (2018-03-26)
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            - Use `references` in migration
         | 
| 27 | 
            +
            - Fixed migration for SQLite
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            ## 0.3.1 (2017-05-12)
         | 
| 2 30 |  | 
| 3 31 | 
             
            - Fixed support for Rails 5.1
         | 
| 4 32 |  | 
| 5 | 
            -
            ## 0.3.0
         | 
| 33 | 
            +
            ## 0.3.0 (2017-05-01)
         | 
| 6 34 |  | 
| 7 35 | 
             
            - Added support for Rails 5.1
         | 
| 8 36 | 
             
            - Fixed `belongs_to` issue with Rails 5
         | 
| 9 37 |  | 
| 10 | 
            -
            ## 0.2.1
         | 
| 38 | 
            +
            ## 0.2.1 (2017-03-19)
         | 
| 11 39 |  | 
| 12 40 | 
             
            - Added `query_url` option
         | 
| 13 41 |  | 
| 14 | 
            -
            ## 0.2.0
         | 
| 42 | 
            +
            ## 0.2.0 (2017-01-05)
         | 
| 15 43 |  | 
| 16 44 | 
             
            - Fixed error with Rails 5
         | 
| 17 45 | 
             
            - Fixed `Index name too long` error with SQLite
         | 
| 18 46 | 
             
            - Added `query_name` option
         | 
| 19 47 | 
             
            - Removed support for Rails 3
         | 
| 20 48 |  | 
| 21 | 
            -
            ## 0.1.0
         | 
| 49 | 
            +
            ## 0.1.0 (2016-08-23)
         | 
| 22 50 |  | 
| 23 51 | 
             
            - Fixed Searchkick integration for `execute: false`
         | 
    
        data/LICENSE.txt
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -12,7 +12,9 @@ Works with any search platform, including Elasticsearch, Sphinx, and Solr | |
| 12 12 |  | 
| 13 13 | 
             
            :cupid: An amazing companion to [Searchkick](https://github.com/ankane/searchkick)
         | 
| 14 14 |  | 
| 15 | 
            -
             | 
| 15 | 
            +
            [](https://travis-ci.org/ankane/searchjoy)
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            ## Installation
         | 
| 16 18 |  | 
| 17 19 | 
             
            Add this line to your application’s Gemfile:
         | 
| 18 20 |  | 
| @@ -24,7 +26,7 @@ And run the generator. This creates a migration to store searches. | |
| 24 26 |  | 
| 25 27 | 
             
            ```sh
         | 
| 26 28 | 
             
            rails generate searchjoy:install
         | 
| 27 | 
            -
             | 
| 29 | 
            +
            rails db:migrate
         | 
| 28 30 | 
             
            ```
         | 
| 29 31 |  | 
| 30 32 | 
             
            Next, add the dashboard to your `config/routes.rb`.
         | 
| @@ -35,7 +37,7 @@ mount Searchjoy::Engine, at: "searchjoy" | |
| 35 37 |  | 
| 36 38 | 
             
            Be sure to protect the endpoint in production - see the [Authentication](#authentication) section for ways to do this.
         | 
| 37 39 |  | 
| 38 | 
            -
             | 
| 40 | 
            +
            ## Track Searches
         | 
| 39 41 |  | 
| 40 42 | 
             
            Track searches by creating a record in the database.
         | 
| 41 43 |  | 
| @@ -51,22 +53,27 @@ Searchjoy::Search.create( | |
| 51 53 | 
             
            With [Searchkick](https://github.com/ankane/searchkick), you can use the `track` option to do this automatically.
         | 
| 52 54 |  | 
| 53 55 | 
             
            ```ruby
         | 
| 54 | 
            -
            Item.search | 
| 56 | 
            +
            Item.search("apple", track: {user_id: 1})
         | 
| 55 57 | 
             
            ```
         | 
| 56 58 |  | 
| 57 59 | 
             
            If you want to track more attributes, add them to the `searchjoy_searches` table.  Then, pass the values to the `track` option.
         | 
| 58 60 |  | 
| 59 61 | 
             
            ```ruby
         | 
| 60 | 
            -
            Item.search | 
| 62 | 
            +
            Item.search("apple", track: {user_id: 1, source: "web"})
         | 
| 61 63 | 
             
            ```
         | 
| 62 64 |  | 
| 63 65 | 
             
            It’s that easy.
         | 
| 64 66 |  | 
| 65 | 
            -
             | 
| 67 | 
            +
            ## Track Conversions
         | 
| 66 68 |  | 
| 67 69 | 
             
            First, choose a conversion metric. At Instacart, an item added to the cart from the search results page counts as a conversion.
         | 
| 68 70 |  | 
| 69 | 
            -
            Next, when a user searches, keep track of the search id. With Searchkick, you can get the id with | 
| 71 | 
            +
            Next, when a user searches, keep track of the search id. With Searchkick, you can get the id with:
         | 
| 72 | 
            +
             | 
| 73 | 
            +
            ```ruby
         | 
| 74 | 
            +
            results = Item.search("apple", track: true)
         | 
| 75 | 
            +
            results.search.id
         | 
| 76 | 
            +
            ```
         | 
| 70 77 |  | 
| 71 78 | 
             
            When a user converts, find the record and call `convert`.
         | 
| 72 79 |  | 
| @@ -78,25 +85,24 @@ search.convert | |
| 78 85 | 
             
            Better yet, record the model that converted.
         | 
| 79 86 |  | 
| 80 87 | 
             
            ```ruby
         | 
| 81 | 
            -
            item = Item.find(params[:item_id])
         | 
| 82 88 | 
             
            search.convert(item)
         | 
| 83 89 | 
             
            ```
         | 
| 84 90 |  | 
| 85 | 
            -
             | 
| 91 | 
            +
            ## Authentication
         | 
| 86 92 |  | 
| 87 93 | 
             
            Don’t forget to protect the dashboard in production.
         | 
| 88 94 |  | 
| 89 | 
            -
             | 
| 95 | 
            +
            ### Devise
         | 
| 90 96 |  | 
| 91 97 | 
             
            In your `config/routes.rb`:
         | 
| 92 98 |  | 
| 93 99 | 
             
            ```ruby
         | 
| 94 | 
            -
            authenticate :user, -> | 
| 100 | 
            +
            authenticate :user, ->(user) { user.admin? } do
         | 
| 95 101 | 
             
              mount Searchjoy::Engine, at: "searchjoy"
         | 
| 96 102 | 
             
            end
         | 
| 97 103 | 
             
            ```
         | 
| 98 104 |  | 
| 99 | 
            -
             | 
| 105 | 
            +
            ### Basic Authentication
         | 
| 100 106 |  | 
| 101 107 | 
             
            Set the following variables in your environment or an initializer.
         | 
| 102 108 |  | 
| @@ -105,45 +111,40 @@ ENV["SEARCHJOY_USERNAME"] = "andrew" | |
| 105 111 | 
             
            ENV["SEARCHJOY_PASSWORD"] = "secret"
         | 
| 106 112 | 
             
            ```
         | 
| 107 113 |  | 
| 108 | 
            -
             | 
| 114 | 
            +
            ## Customize
         | 
| 115 | 
            +
             | 
| 116 | 
            +
            To customize, create an initializer `config/initializers/searchjoy.rb`.
         | 
| 109 117 |  | 
| 110 | 
            -
             | 
| 118 | 
            +
            Change the time zone
         | 
| 111 119 |  | 
| 112 120 | 
             
            ```ruby
         | 
| 113 121 | 
             
            Searchjoy.time_zone = "Pacific Time (US & Canada)" # defaults to Time.zone
         | 
| 114 122 | 
             
            ```
         | 
| 115 123 |  | 
| 116 | 
            -
            Change the number of top searches shown | 
| 124 | 
            +
            Change the number of top searches shown
         | 
| 117 125 |  | 
| 118 126 | 
             
            ```ruby
         | 
| 119 127 | 
             
            Searchjoy.top_searches = 500 # defaults to 100
         | 
| 120 128 | 
             
            ```
         | 
| 121 129 |  | 
| 122 | 
            -
            Link to the search results | 
| 130 | 
            +
            Link to the search results
         | 
| 123 131 |  | 
| 124 132 | 
             
            ```ruby
         | 
| 125 | 
            -
            Searchjoy.query_url = -> | 
| 133 | 
            +
            Searchjoy.query_url = ->(search) { Rails.application.routes.url_helpers.items_path(q: search.query) }
         | 
| 126 134 | 
             
            ```
         | 
| 127 135 |  | 
| 128 | 
            -
            Add additional info to the query in the live stream | 
| 136 | 
            +
            Add additional info to the query in the live stream
         | 
| 129 137 |  | 
| 130 138 | 
             
            ```ruby
         | 
| 131 | 
            -
            Searchjoy.query_name = -> | 
| 139 | 
            +
            Searchjoy.query_name = ->(search) { "#{search.query} #{search.city}" }
         | 
| 132 140 | 
             
            ```
         | 
| 133 141 |  | 
| 134 | 
            -
            Show the conversion name in the live stream | 
| 142 | 
            +
            Show the conversion name in the live stream
         | 
| 135 143 |  | 
| 136 144 | 
             
            ```ruby
         | 
| 137 | 
            -
            Searchjoy.conversion_name = -> | 
| 145 | 
            +
            Searchjoy.conversion_name = ->(model) { model.name }
         | 
| 138 146 | 
             
            ```
         | 
| 139 147 |  | 
| 140 | 
            -
            ## TODO
         | 
| 141 | 
            -
             | 
| 142 | 
            -
            - customize views
         | 
| 143 | 
            -
            - analytics for individual queries
         | 
| 144 | 
            -
            - group similar queries
         | 
| 145 | 
            -
            - track pagination, facets, sorting, etc
         | 
| 146 | 
            -
             | 
| 147 148 | 
             
            ## Contributing
         | 
| 148 149 |  | 
| 149 150 | 
             
            Everyone is encouraged to help improve this project. Here are a few ways you can help:
         | 
| @@ -152,3 +153,12 @@ Everyone is encouraged to help improve this project. Here are a few ways you can | |
| 152 153 | 
             
            - Fix bugs and [submit pull requests](https://github.com/ankane/searchjoy/pulls)
         | 
| 153 154 | 
             
            - Write, clarify, or fix documentation
         | 
| 154 155 | 
             
            - Suggest or add new feature
         | 
| 156 | 
            +
             | 
| 157 | 
            +
            To get started with development and testing:
         | 
| 158 | 
            +
             | 
| 159 | 
            +
            ```sh
         | 
| 160 | 
            +
            git clone https://github.com/ankane/searchjoy.git
         | 
| 161 | 
            +
            cd searchjoy
         | 
| 162 | 
            +
            bundle install
         | 
| 163 | 
            +
            bundle exec rake test
         | 
| 164 | 
            +
            ```
         | 
| @@ -20,8 +20,8 @@ module Searchjoy | |
| 20 20 |  | 
| 21 21 | 
             
                def overview
         | 
| 22 22 | 
             
                  relation = Searchjoy::Search.where(search_type: params[:search_type])
         | 
| 23 | 
            -
                  @searches_by_week = relation.group_by_week(:created_at, Time.zone, @time_range).count
         | 
| 24 | 
            -
                  @conversions_by_week = relation.where("converted_at is not null").group_by_week(:created_at, Time.zone, @time_range).count
         | 
| 23 | 
            +
                  @searches_by_week = relation.group_by_week(:created_at, time_zone: Time.zone, range: @time_range).count
         | 
| 24 | 
            +
                  @conversions_by_week = relation.where("converted_at is not null").group_by_week(:created_at, time_zone: Time.zone, range: @time_range).count
         | 
| 25 25 | 
             
                  @top_searches = @searches.first(5)
         | 
| 26 26 | 
             
                  @bad_conversion_rate = @searches.sort_by { |s| [s["conversion_rate"].to_f, s["query"]] }.first(5).select { |s| s["conversion_rate"] < 50 }
         | 
| 27 27 | 
             
                  @conversion_rate_by_week = {}
         | 
| @@ -1,15 +1,9 @@ | |
| 1 1 | 
             
            module Searchjoy
         | 
| 2 2 | 
             
              class Search < ActiveRecord::Base
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
                  belongs_to :convertable, polymorphic: true, optional: true
         | 
| 5 | 
            -
                else
         | 
| 6 | 
            -
                  belongs_to :convertable, polymorphic: true
         | 
| 7 | 
            -
                end
         | 
| 3 | 
            +
                self.table_name = "searchjoy_searches"
         | 
| 8 4 |  | 
| 9 | 
            -
                 | 
| 10 | 
            -
                 | 
| 11 | 
            -
                  attr_accessible :search_type, :query, :results_count
         | 
| 12 | 
            -
                end
         | 
| 5 | 
            +
                belongs_to :convertable, polymorphic: true, optional: true
         | 
| 6 | 
            +
                belongs_to :user, optional: true
         | 
| 13 7 |  | 
| 14 8 | 
             
                before_save :set_normalized_query
         | 
| 15 9 |  | 
| @@ -280,7 +280,7 @@ | |
| 280 280 | 
             
                  }
         | 
| 281 281 | 
             
                </style>
         | 
| 282 282 |  | 
| 283 | 
            -
                <%= javascript_include_tag " | 
| 283 | 
            +
                <%= javascript_include_tag "searchjoy" %>
         | 
| 284 284 | 
             
              </head>
         | 
| 285 285 | 
             
              <body>
         | 
| 286 286 | 
             
                <div class="container">
         | 
| @@ -3,11 +3,21 @@ | |
| 3 3 | 
             
            <table id="stream"></table>
         | 
| 4 4 |  | 
| 5 5 | 
             
            <script>
         | 
| 6 | 
            +
              function load(element, path) {
         | 
| 7 | 
            +
                var request = new XMLHttpRequest();
         | 
| 8 | 
            +
                request.open("GET", path, true);
         | 
| 9 | 
            +
                request.onload = function() {
         | 
| 10 | 
            +
                  if (request.status >= 200 && request.status < 400) {
         | 
| 11 | 
            +
                    var resp = request.responseText;
         | 
| 12 | 
            +
                    element.innerHTML = resp;
         | 
| 13 | 
            +
                  }
         | 
| 14 | 
            +
                };
         | 
| 15 | 
            +
                request.send();
         | 
| 16 | 
            +
              }
         | 
| 17 | 
            +
             | 
| 6 18 | 
             
              function fetchRecentSearches() {
         | 
| 7 | 
            -
                 | 
| 19 | 
            +
                load(document.getElementById("stream"), "<%= searches_recent_path %>")
         | 
| 8 20 | 
             
                setTimeout(fetchRecentSearches, 5 * 1000);
         | 
| 9 21 | 
             
              }
         | 
| 10 | 
            -
               | 
| 11 | 
            -
                fetchRecentSearches();
         | 
| 12 | 
            -
              });
         | 
| 22 | 
            +
              fetchRecentSearches();
         | 
| 13 23 | 
             
            </script>
         | 
| @@ -1,34 +1,17 @@ | |
| 1 | 
            -
            # taken from https://github.com/collectiveidea/audited/blob/master/lib/generators/audited/install_generator.rb
         | 
| 2 | 
            -
            require "rails/generators"
         | 
| 3 | 
            -
            require "rails/generators/migration"
         | 
| 4 | 
            -
            require "active_record"
         | 
| 5 1 | 
             
            require "rails/generators/active_record"
         | 
| 6 2 |  | 
| 7 3 | 
             
            module Searchjoy
         | 
| 8 4 | 
             
              module Generators
         | 
| 9 5 | 
             
                class InstallGenerator < Rails::Generators::Base
         | 
| 10 | 
            -
                  include  | 
| 11 | 
            -
             | 
| 12 | 
            -
                  source_root File.expand_path("../templates", __FILE__)
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                  # Implement the required interface for Rails::Generators::Migration.
         | 
| 15 | 
            -
                  def self.next_migration_number(dirname) #:nodoc:
         | 
| 16 | 
            -
                    next_migration_number = current_migration_number(dirname) + 1
         | 
| 17 | 
            -
                    if ActiveRecord::Base.timestamped_migrations
         | 
| 18 | 
            -
                      [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
         | 
| 19 | 
            -
                    else
         | 
| 20 | 
            -
                      "%.3d" % next_migration_number
         | 
| 21 | 
            -
                    end
         | 
| 22 | 
            -
                  end
         | 
| 6 | 
            +
                  include ActiveRecord::Generators::Migration
         | 
| 7 | 
            +
                  source_root File.join(__dir__, "templates")
         | 
| 23 8 |  | 
| 24 9 | 
             
                  def copy_migration
         | 
| 25 10 | 
             
                    migration_template "install.rb", "db/migrate/install_searchjoy.rb", migration_version: migration_version
         | 
| 26 11 | 
             
                  end
         | 
| 27 12 |  | 
| 28 13 | 
             
                  def migration_version
         | 
| 29 | 
            -
                     | 
| 30 | 
            -
                      "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
         | 
| 31 | 
            -
                    end
         | 
| 14 | 
            +
                    "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
         | 
| 32 15 | 
             
                  end
         | 
| 33 16 | 
             
                end
         | 
| 34 17 | 
             
              end
         | 
| @@ -1,20 +1,18 @@ | |
| 1 1 | 
             
            class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
         | 
| 2 2 | 
             
              def change
         | 
| 3 3 | 
             
                create_table :searchjoy_searches do |t|
         | 
| 4 | 
            -
                  t. | 
| 4 | 
            +
                  t.references :user
         | 
| 5 5 | 
             
                  t.string :search_type
         | 
| 6 6 | 
             
                  t.string :query
         | 
| 7 7 | 
             
                  t.string :normalized_query
         | 
| 8 8 | 
             
                  t.integer :results_count
         | 
| 9 9 | 
             
                  t.timestamp :created_at
         | 
| 10 | 
            -
                  t. | 
| 11 | 
            -
                  t.string :convertable_type
         | 
| 10 | 
            +
                  t.references :convertable, polymorphic: true, index: {name: "index_searchjoy_searches_on_convertable"}
         | 
| 12 11 | 
             
                  t.timestamp :converted_at
         | 
| 13 12 | 
             
                end
         | 
| 14 13 |  | 
| 15 14 | 
             
                add_index :searchjoy_searches, [:created_at]
         | 
| 16 15 | 
             
                add_index :searchjoy_searches, [:search_type, :created_at]
         | 
| 17 | 
            -
                add_index :searchjoy_searches, [:search_type, :normalized_query, :created_at], name: " | 
| 18 | 
            -
                add_index :searchjoy_searches, [:convertable_id, :convertable_type]
         | 
| 16 | 
            +
                add_index :searchjoy_searches, [:search_type, :normalized_query, :created_at], name: "index_searchjoy_searches_on_search_type_query" # autogenerated name is too long
         | 
| 19 17 | 
             
              end
         | 
| 20 18 | 
             
            end
         | 
    
        data/lib/searchjoy.rb
    CHANGED
    
    | @@ -1,9 +1,8 @@ | |
| 1 | 
            -
            require " | 
| 1 | 
            +
            require "active_support/core_ext/module/attribute_accessors"
         | 
| 2 2 | 
             
            require "chartkick"
         | 
| 3 3 | 
             
            require "groupdate"
         | 
| 4 4 |  | 
| 5 5 | 
             
            require "searchjoy/track"
         | 
| 6 | 
            -
            require "searchjoy/engine" if defined?(Rails)
         | 
| 7 6 | 
             
            require "searchjoy/version"
         | 
| 8 7 |  | 
| 9 8 | 
             
            module Searchjoy
         | 
| @@ -21,24 +20,16 @@ module Searchjoy | |
| 21 20 | 
             
              mattr_accessor :conversion_name
         | 
| 22 21 | 
             
              mattr_accessor :query_name
         | 
| 23 22 | 
             
              mattr_accessor :query_url
         | 
| 24 | 
            -
            end
         | 
| 25 23 |  | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 24 | 
            +
              def self.attach_to_searchkick!
         | 
| 25 | 
            +
                Searchkick::Query.prepend(Searchjoy::Track::Query)
         | 
| 26 | 
            +
                Searchkick::MultiSearch.prepend(Searchjoy::Track::MultiSearch)
         | 
| 27 | 
            +
                Searchkick::Results.send(:attr_accessor, :search)
         | 
| 28 | 
            +
              end
         | 
| 30 29 | 
             
            end
         | 
| 31 30 |  | 
| 32 | 
            -
            if defined?( | 
| 33 | 
            -
               | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
                  define_method(:execute_without_track, instance_method(:execute))
         | 
| 37 | 
            -
                  define_method(:execute, instance_method(:execute_with_track))
         | 
| 38 | 
            -
                end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                class Results
         | 
| 41 | 
            -
                  attr_accessor :search
         | 
| 42 | 
            -
                end
         | 
| 43 | 
            -
              end
         | 
| 31 | 
            +
            if defined?(Rails)
         | 
| 32 | 
            +
              require "searchjoy/engine"
         | 
| 33 | 
            +
            else
         | 
| 34 | 
            +
              Searchjoy.attach_to_searchkick! if defined?(Searchkick)
         | 
| 44 35 | 
             
            end
         | 
    
        data/lib/searchjoy/engine.rb
    CHANGED
    
    | @@ -1,5 +1,18 @@ | |
| 1 1 | 
             
            module Searchjoy
         | 
| 2 2 | 
             
              class Engine < ::Rails::Engine
         | 
| 3 3 | 
             
                isolate_namespace Searchjoy
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                initializer "searchjoy" do |app|
         | 
| 6 | 
            +
                  if app.config.respond_to?(:assets)
         | 
| 7 | 
            +
                    if defined?(Sprockets) && Sprockets::VERSION >= "4"
         | 
| 8 | 
            +
                      app.config.assets.precompile << "searchjoy.js"
         | 
| 9 | 
            +
                    else
         | 
| 10 | 
            +
                      # use a proc instead of a string
         | 
| 11 | 
            +
                      app.config.assets.precompile << proc { |path| path == "searchjoy.js" }
         | 
| 12 | 
            +
                    end
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  Searchjoy.attach_to_searchkick! if defined?(Searchkick)
         | 
| 16 | 
            +
                end
         | 
| 4 17 | 
             
              end
         | 
| 5 18 | 
             
            end
         | 
    
        data/lib/searchjoy/track.rb
    CHANGED
    
    | @@ -1,24 +1,48 @@ | |
| 1 1 | 
             
            module Searchjoy
         | 
| 2 2 | 
             
              module Track
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
                   | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
                     | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
                       | 
| 11 | 
            -
                        klass.name
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                         | 
| 14 | 
            -
             | 
| 15 | 
            -
                         | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 3 | 
            +
                module Query
         | 
| 4 | 
            +
                  def track
         | 
| 5 | 
            +
                    results = @execute
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                    if options[:track] && !results.search
         | 
| 8 | 
            +
                      attributes = options[:track] == true ? {} : options[:track]
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                      search_type =
         | 
| 11 | 
            +
                        if klass.respond_to?(:name) && klass.name.present?
         | 
| 12 | 
            +
                          klass.name
         | 
| 13 | 
            +
                        elsif options[:models]
         | 
| 14 | 
            +
                          Array(options[:models]).map(&:to_s).sort.join(" ")
         | 
| 15 | 
            +
                        elsif options[:index_name]
         | 
| 16 | 
            +
                          Array(options[:index_name]).map(&:to_s).sort.join(" ")
         | 
| 17 | 
            +
                        else
         | 
| 18 | 
            +
                          "All Indices"
         | 
| 19 | 
            +
                        end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                      results.search = Searchjoy::Search.create({search_type: search_type, query: term, results_count: results.total_count}.merge(attributes))
         | 
| 22 | 
            +
                    end
         | 
| 19 23 | 
             
                  end
         | 
| 20 24 |  | 
| 21 | 
            -
                   | 
| 25 | 
            +
                  def execute
         | 
| 26 | 
            +
                    results = super
         | 
| 27 | 
            +
                    track
         | 
| 28 | 
            +
                    results
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  def search
         | 
| 32 | 
            +
                    @execute.search if @execute
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                module MultiSearch
         | 
| 37 | 
            +
                  def perform
         | 
| 38 | 
            +
                    result = super
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    @queries.each do |query|
         | 
| 41 | 
            +
                      query.track
         | 
| 42 | 
            +
                    end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    result
         | 
| 45 | 
            +
                  end
         | 
| 22 46 | 
             
                end
         | 
| 23 47 | 
             
              end
         | 
| 24 48 | 
             
            end
         | 
    
        data/lib/searchjoy/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: searchjoy
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.3 | 
| 4 | 
            +
              version: 0.4.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Andrew Kane
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2020-03-07 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: chartkick
         | 
| @@ -16,14 +16,14 @@ dependencies: | |
| 16 16 | 
             
                requirements:
         | 
| 17 17 | 
             
                - - ">="
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: '2'
         | 
| 19 | 
            +
                    version: '3.2'
         | 
| 20 20 | 
             
              type: :runtime
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 24 | 
             
                - - ">="
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version: '2'
         | 
| 26 | 
            +
                    version: '3.2'
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: groupdate
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -44,14 +44,14 @@ dependencies: | |
| 44 44 | 
             
                requirements:
         | 
| 45 45 | 
             
                - - ">="
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            -
                    version: ' | 
| 47 | 
            +
                    version: '5'
         | 
| 48 48 | 
             
              type: :runtime
         | 
| 49 49 | 
             
              prerelease: false
         | 
| 50 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 52 | 
             
                - - ">="
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            -
                    version: ' | 
| 54 | 
            +
                    version: '5'
         | 
| 55 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 56 | 
             
              name: bundler
         | 
| 57 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -94,19 +94,44 @@ dependencies: | |
| 94 94 | 
             
                - - ">="
         | 
| 95 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 96 | 
             
                    version: '0'
         | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: sqlite3
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - ">="
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: '0'
         | 
| 104 | 
            +
              type: :development
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - ">="
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: '0'
         | 
| 111 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 112 | 
            +
              name: searchkick
         | 
| 113 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - ">="
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: '0'
         | 
| 118 | 
            +
              type: :development
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                requirements:
         | 
| 122 | 
            +
                - - ">="
         | 
| 123 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            +
                    version: '0'
         | 
| 125 | 
            +
            description: 
         | 
| 126 | 
            +
            email: andrew@chartkick.com
         | 
| 100 127 | 
             
            executables: []
         | 
| 101 128 | 
             
            extensions: []
         | 
| 102 129 | 
             
            extra_rdoc_files: []
         | 
| 103 130 | 
             
            files:
         | 
| 104 | 
            -
            - ".gitignore"
         | 
| 105 131 | 
             
            - CHANGELOG.md
         | 
| 106 | 
            -
            - Gemfile
         | 
| 107 132 | 
             
            - LICENSE.txt
         | 
| 108 133 | 
             
            - README.md
         | 
| 109 | 
            -
            -  | 
| 134 | 
            +
            - app/assets/javascripts/searchjoy.js
         | 
| 110 135 | 
             
            - app/controllers/searchjoy/searches_controller.rb
         | 
| 111 136 | 
             
            - app/models/searchjoy/search.rb
         | 
| 112 137 | 
             
            - app/views/layouts/searchjoy/application.html.erb
         | 
| @@ -116,14 +141,11 @@ files: | |
| 116 141 | 
             
            - app/views/searchjoy/searches/stream.html.erb
         | 
| 117 142 | 
             
            - config/routes.rb
         | 
| 118 143 | 
             
            - lib/generators/searchjoy/install_generator.rb
         | 
| 119 | 
            -
            - lib/generators/searchjoy/templates/install.rb
         | 
| 144 | 
            +
            - lib/generators/searchjoy/templates/install.rb.tt
         | 
| 120 145 | 
             
            - lib/searchjoy.rb
         | 
| 121 146 | 
             
            - lib/searchjoy/engine.rb
         | 
| 122 147 | 
             
            - lib/searchjoy/track.rb
         | 
| 123 148 | 
             
            - lib/searchjoy/version.rb
         | 
| 124 | 
            -
            - searchjoy.gemspec
         | 
| 125 | 
            -
            - test/searchjoy_test.rb
         | 
| 126 | 
            -
            - test/test_helper.rb
         | 
| 127 149 | 
             
            homepage: https://github.com/ankane/searchjoy
         | 
| 128 150 | 
             
            licenses:
         | 
| 129 151 | 
             
            - MIT
         | 
| @@ -136,18 +158,15 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 136 158 | 
             
              requirements:
         | 
| 137 159 | 
             
              - - ">="
         | 
| 138 160 | 
             
                - !ruby/object:Gem::Version
         | 
| 139 | 
            -
                  version: ' | 
| 161 | 
            +
                  version: '2.4'
         | 
| 140 162 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 141 163 | 
             
              requirements:
         | 
| 142 164 | 
             
              - - ">="
         | 
| 143 165 | 
             
                - !ruby/object:Gem::Version
         | 
| 144 166 | 
             
                  version: '0'
         | 
| 145 167 | 
             
            requirements: []
         | 
| 146 | 
            -
             | 
| 147 | 
            -
            rubygems_version: 2.6.11
         | 
| 168 | 
            +
            rubygems_version: 3.1.2
         | 
| 148 169 | 
             
            signing_key: 
         | 
| 149 170 | 
             
            specification_version: 4
         | 
| 150 171 | 
             
            summary: Search analytics made easy
         | 
| 151 | 
            -
            test_files:
         | 
| 152 | 
            -
            - test/searchjoy_test.rb
         | 
| 153 | 
            -
            - test/test_helper.rb
         | 
| 172 | 
            +
            test_files: []
         | 
    
        data/.gitignore
    DELETED
    
    
    
        data/Gemfile
    DELETED
    
    
    
        data/Rakefile
    DELETED
    
    
    
        data/searchjoy.gemspec
    DELETED
    
    | @@ -1,28 +0,0 @@ | |
| 1 | 
            -
            # coding: utf-8
         | 
| 2 | 
            -
            lib = File.expand_path("../lib", __FILE__)
         | 
| 3 | 
            -
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            -
            require "searchjoy/version"
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            Gem::Specification.new do |spec|
         | 
| 7 | 
            -
              spec.name          = "searchjoy"
         | 
| 8 | 
            -
              spec.version       = Searchjoy::VERSION
         | 
| 9 | 
            -
              spec.authors       = ["Andrew Kane"]
         | 
| 10 | 
            -
              spec.email         = ["andrew@chartkick.com"]
         | 
| 11 | 
            -
              spec.description   = "Search analytics made easy"
         | 
| 12 | 
            -
              spec.summary       = "Search analytics made easy"
         | 
| 13 | 
            -
              spec.homepage      = "https://github.com/ankane/searchjoy"
         | 
| 14 | 
            -
              spec.license       = "MIT"
         | 
| 15 | 
            -
             | 
| 16 | 
            -
              spec.files         = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
         | 
| 17 | 
            -
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 18 | 
            -
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 19 | 
            -
              spec.require_paths = ["lib"]
         | 
| 20 | 
            -
             | 
| 21 | 
            -
              spec.add_dependency "chartkick", ">= 2"
         | 
| 22 | 
            -
              spec.add_dependency "groupdate", ">= 3"
         | 
| 23 | 
            -
              spec.add_dependency "activerecord", ">= 4"
         | 
| 24 | 
            -
             | 
| 25 | 
            -
              spec.add_development_dependency "bundler"
         | 
| 26 | 
            -
              spec.add_development_dependency "rake"
         | 
| 27 | 
            -
              spec.add_development_dependency "minitest"
         | 
| 28 | 
            -
            end
         | 
    
        data/test/searchjoy_test.rb
    DELETED
    
    | @@ -1,15 +0,0 @@ | |
| 1 | 
            -
            require_relative "test_helper"
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            class SearchjoyTest < Minitest::Test
         | 
| 4 | 
            -
              def test_must_respond_to_top_searches
         | 
| 5 | 
            -
                assert_respond_to Searchjoy, :top_searches
         | 
| 6 | 
            -
              end
         | 
| 7 | 
            -
             | 
| 8 | 
            -
              def test_must_respond_to_conversion_name
         | 
| 9 | 
            -
                assert_respond_to Searchjoy, :conversion_name
         | 
| 10 | 
            -
              end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
              def test_must_respond_to_time_zone
         | 
| 13 | 
            -
                assert_respond_to Searchjoy, :time_zone
         | 
| 14 | 
            -
              end
         | 
| 15 | 
            -
            end
         |