README.md in autosuggest-0.1.3 vs README.md in autosuggest-0.2.0
- old
+ new
@@ -2,18 +2,20 @@
Generate autocomplete suggestions based on what your users search
:tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
+Autosuggest 0.2 was recently released! See [how to upgrade](#upgrading)
+
[![Build Status](https://github.com/ankane/autosuggest/workflows/build/badge.svg?branch=master)](https://github.com/ankane/autosuggest/actions)
## Installation
Add this line to your application’s Gemfile:
```ruby
-gem 'autosuggest'
+gem "autosuggest"
```
## Getting Started
#### Prepare your data
@@ -36,20 +38,26 @@
```
Then pass them to Autosuggest.
```ruby
-autosuggest = Autosuggest.new(top_queries)
+autosuggest = Autosuggest::Generator.new(top_queries)
```
#### Filter duplicates
[Stemming](https://en.wikipedia.org/wiki/Stemming) is used to detect duplicates like `apple` and `apples`.
-The most popular query is preferred by default. To override this, use:
+Specify the stemming language (defaults to `english`) with:
```ruby
+autosuggest = Autosuggest::Generator.new(top_queries, language: "spanish")
+```
+
+The most popular query is preferred by default. To override this, use:
+
+```ruby
autosuggest.prefer ["apples"]
```
To fix false positives, use:
@@ -88,11 +96,11 @@
#### Generate suggestions
Generate suggestions with:
```ruby
-suggestions = autosuggest.suggestions(filter: true)
+suggestions = autosuggest.suggestions
```
#### Save suggestions
Save suggestions in your database or another data store.
@@ -150,22 +158,22 @@
#### Additional considerations
You may want to have someone manually approve suggestions:
```ruby
-Autosuggest::Suggestion.where(approved: true)
+Autosuggest::Suggestion.where(status: "approved")
```
Or filter suggestions without results:
```ruby
Autosuggest::Suggestion.find_each do |suggestion|
- suggestion.has_results = Product.search(suggestion.query, load: false, limit: 1).any?
+ suggestion.results_count = Product.search(suggestion.query, load: false).count
suggestion.save! if suggestion.changed?
end
-Autosuggest::Suggestion.where(has_results: true)
+Autosuggest::Suggestion.where("results_count > 0")
```
You can add additional fields to your model/data store to accomplish this.
## Example
@@ -174,24 +182,34 @@
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 = Autosuggest::Generator.new(top_queries)
autosuggest.parse_words product_names
autosuggest.add_concept "brand", brand_names
autosuggest.prefer brand_names
autosuggest.not_duplicates [["straws", "straus"]]
autosuggest.block_words ["boom"]
-suggestions = autosuggest.suggestions(filter: true)
+suggestions = autosuggest.suggestions
now = Time.now
records = suggestions.map { |s| s.slice(:query, :score).merge(updated_at: now) }
Autosuggest::Suggestion.transaction do
Autosuggest::Suggestion.upsert_all(records, unique_by: :query)
Autosuggest::Suggestion.where("updated_at < ?", now).delete_all
end
+```
+
+## Upgrading
+
+### 0.2.0
+
+Suggestions are now filtered by default, and only the query and score are returned. To get all queries and fields, use:
+
+```ruby
+autosuggest.suggestions(filter: false)
```
## History
View the [changelog](https://github.com/ankane/autosuggest/blob/master/CHANGELOG.md)