README.md in autosuggest-0.1.1 vs README.md in autosuggest-0.1.2
- old
+ new
@@ -12,20 +12,34 @@
```ruby
gem 'autosuggest'
```
-## How It Works
+## Getting Started
-#### Start with the most popular queries
+#### Prepare your data
+Start with a hash of queries and their popularity, like the number of users who have searched it.
+
```ruby
-top_queries = Search.group("LOWER(query)")
- .having("COUNT(DISTINCT user_id) >= 5")
- .count("DISTINCT user_id")
-# {"bananas" => 353, "apples" => 213, ...
+top_queries = {
+ "bananas" => 353,
+ "apples" => 213,
+ "oranges" => 140
+}
+```
+With [Searchjoy](https://github.com/ankane/searchjoy), you can do:
+
+```ruby
+top_queries = Searchjoy::Search.group(:normalized_query)
+ .having("COUNT(DISTINCT user_id) >= 5").distinct.count(:user_id)
+```
+
+Then pass them to Autosuggest.
+
+```ruby
autosuggest = Autosuggest.new(top_queries)
```
#### Filter duplicates
@@ -74,21 +88,20 @@
#### Profit
Get suggestions with:
```ruby
-autosuggest.suggestions
+autosuggest.suggestions(filter: true)
```
Filter queries without results and you’re set. We also prefer to have someone manually approve them by hand.
## Full Example
```ruby
-top_queries = Search.group("LOWER(query)")
- .having("COUNT(DISTINCT user_id) >= 5")
- .count("DISTINCT user_id")
+top_queries = Searchjoy::Search.group(:normalized_query)
+ .having("COUNT(DISTINCT user_id) >= 5").distinct.count(:user_id)
product_names = Product.pluck(:name)
brand_names = Brand.pluck(:name)
autosuggest = Autosuggest.new(top_queries)
autosuggest.parse_words product_names
@@ -97,10 +110,10 @@
autosuggest.not_duplicates [["straws", "straus"]]
autosuggest.block_words ["boom"]
puts autosuggest.pretty_suggestions
# or
-suggestions = autosuggest.suggestions
+suggestions = autosuggest.suggestions(filter: true)
```
## History
View the [changelog](https://github.com/ankane/autosuggest/blob/master/CHANGELOG.md)