Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Rename multi_search → search across API, SDK, models, and docs

Damian Legawiec136148c74a6a
diff --git a/docs/api-reference/store-api/querying.mdx b/docs/api-reference/store-api/querying.mdx
index 47723ee3a3..7755f76461 100644
--- a/docs/api-reference/store-api/querying.mdx
+++ b/docs/api-reference/store-api/querying.mdx
@@ -146,7 +146,7 @@ curl -G 'http://localhost:3000/api/v3/store/products' \
| `with_option_value_ids` | Filter by option value IDs | `with_option_value_ids: ['optval_abc']` | `q[with_option_value_ids][]=optval_abc` |
| `in_stock` | Only in-stock products | `in_stock: true` | `q[in_stock]=true` |
| `out_of_stock` | Only out-of-stock products | `out_of_stock: true` | `q[out_of_stock]=true` |
-| `multi_search` | Full-text search | `multi_search: 'shirt'` | `q[multi_search]=shirt` |
+| `search` | Full-text search | `search: 'shirt'` | `q[search]=shirt` |
## Sorting
diff --git a/docs/developer/core-concepts/products.mdx b/docs/developer/core-concepts/products.mdx
index a84cf11499..815b602744 100644
--- a/docs/developer/core-concepts/products.mdx
+++ b/docs/developer/core-concepts/products.mdx
@@ -96,7 +96,7 @@ const filtered = await client.products.list({
// Search by keyword
const results = await client.products.list({
- multi_search: 'tote bag',
+ search: 'tote bag',
})
// Sort products
@@ -115,7 +115,7 @@ curl 'https://api.mystore.com/api/v3/store/products?q[price_gte]=10&q[price_lte]
-H 'Authorization: Bearer spree_pk_xxx'
# Search
-curl 'https://api.mystore.com/api/v3/store/products?q[multi_search]=tote+bag' \
+curl 'https://api.mystore.com/api/v3/store/products?q[search]=tote+bag' \
-H 'Authorization: Bearer spree_pk_xxx'
```
diff --git a/docs/developer/core-concepts/search-filtering.mdx b/docs/developer/core-concepts/search-filtering.mdx
index fd0d956d79..8e3fb268fe 100644
--- a/docs/developer/core-concepts/search-filtering.mdx
+++ b/docs/developer/core-concepts/search-filtering.mdx
@@ -15,19 +15,19 @@ Spree provides powerful search, filtering, and sorting capabilities for products
## Product Search
-Use the `multi_search` parameter for full-text search across product fields:
+Use the `search` parameter for full-text search across product fields:
<CodeGroup>
```typescript SDK
const { data: products } = await client.products.list({
- multi_search: 'tote bag',
+ search: 'tote bag',
limit: 12,
})
```
```bash cURL
-curl 'https://api.mystore.com/api/v3/store/products?q[multi_search]=tote+bag&limit=12' \
+curl 'https://api.mystore.com/api/v3/store/products?q[search]=tote+bag&limit=12' \
-H 'Authorization: Bearer spree_pk_xxx'
```
@@ -234,7 +234,22 @@ curl 'https://api.mystore.com/api/v3/store/products?page=1&limit=24' \
See [Querying](/api-reference/store-api/querying) for the full list of filtering, sorting, and pagination options.
+## Search Providers
+
+Spree uses a pluggable search provider architecture. The default provider uses SQL (ILIKE + Ransack). For production catalogs with 1,000+ products, we recommend switching to [Meilisearch](/integrations/search/meilisearch) for typo tolerance, relevance ranking, and faster faceted search.
+
+```ruby
+# config/initializers/spree.rb
+Spree.search_provider = 'Spree::SearchProvider::Meilisearch'
+```
+
+No client-side or API changes are needed — the same `q[search]`, filter params, and sort options work with any provider.
+
+See [Search Providers](/developer/customization/search-providers) for architecture details and how to build custom providers.
+
## Related Documentation
- [Products](/developer/core-concepts/products) — Product catalog and listing
- [Querying](/api-reference/store-api/querying) — API filtering, sorting, and pagination reference
+- [Search Providers](/developer/customization/search-providers) — Architecture and custom providers
+- [Meilisearch Integration](/integrations/search/meilisearch) — Setup guide
diff --git a/docs/developer/sdk/store/products.mdx b/docs/developer/sdk/store/products.mdx
index 9c692740e7..303bd6ac4c 100644
--- a/docs/developer/sdk/store/products.mdx
+++ b/docs/developer/sdk/store/products.mdx
@@ -26,7 +26,7 @@ const products = await client.products.list({
price_lte: 100, // Max price
with_option_value_ids: ['optval_abc', 'optval_def'], // By option values
in_stock: true, // In stock only
- multi_search: 'blue shirt', // Full-text search
+ search: 'blue shirt', // Full-text search
});
```
diff --git a/packages/sdk/src/types/index.ts b/packages/sdk/src/types/index.ts
index 05f3b51141..3043931ff8 100644
--- a/packages/sdk/src/types/index.ts
+++ b/packages/sdk/src/types/index.ts
@@ -173,7 +173,7 @@ export interface ProductListParams extends ListParams {
/** Sort: 'price', '-price', 'best_selling', 'name', '-name', '-available_on', 'available_on' */
sort?: string;
/** Full-text search across name and SKU */
- multi_search?: string;
+ search?: string;
/** Filter: name contains */
name_cont?: string;
/** Filter: price >= value */
@@ -207,7 +207,7 @@ export interface OrderListParams extends ListParams {
/** Sort order, e.g. 'completed_at desc' */
sort?: string;
/** Full-text search across number, email, customer name */
- multi_search?: string;
+ search?: string;
state_eq?: string;
completed_at_gte?: string;
completed_at_lte?: string;
diff --git a/packages/sdk/tests/params.test.ts b/packages/sdk/tests/params.test.ts
index fe9f3b644d..b11ac0f8c3 100644
--- a/packages/sdk/tests/params.test.ts
+++ b/packages/sdk/tests/params.test.ts
@@ -45,9 +45,9 @@ describe('transformListParams', () => {
});
});
- it('transforms multi_search', () => {
- const result = transformListParams({ multi_search: 'shirt' });
- expect(result).toEqual({ 'q[multi_search]': 'shirt' });
+ it('transforms search', () => {
+ const result = transformListParams({ search: 'shirt' });
+ expect(result).toEqual({ 'q[search]': 'shirt' });
});
it('passes through already-wrapped q[...] keys (backward compat)', () => {
diff --git a/spree/admin/app/controllers/spree/admin/products_controller.rb b/spree/admin/app/controllers/spree/admin/products_controller.rb
index 127b36a0f9..ca3ee1044a 100644
--- a/spree/admin/app/controllers/spree/admin/products_controller.rb
+++ b/spree/admin/app/controllers/spree/admin/products_controller.rb
@@ -35,7 +35,7 @@ module Spree
scope = current_store.products.not_archived.accessible_by(current_ability, :index)
scope = scope.where.not(id: params[:omit_ids].split(',')) if params[:omit_ids].present?
- @products = scope.includes(:primary_media).multi_search(query).limit(params[:limit] || 10)
+ @products = scope.includes(:primary_media).search(query).limit(params[:limit] || 10)
respond_to do |format|
format.turbo_stream do
diff --git a/spree/admin/app/controllers/spree/admin/users_controller.rb b/spree/admin/app/controllers/spree/admin/users_controller.rb
index 3da7c17a39..fdf422053f 100644
--- a/spree/admin/app/controllers/spree/admin/users_controller.rb
+++ b/spree/admin/app/controllers/spree/admin/users_controller.rb
@@ -29,7 +29,7 @@ module Spree
scope = model_class.accessible_by(current_ability, :index)
scope = scope.where.not(id: params[:omit_ids].split(',')) if params[:omit_ids].present?
@users = scope.includes(:bill_address, :ship_address, avatar_attachment: :blob)
- .multi_search(query)
+ .search(query)
.limit(params[:limit] || 10)
respond_to do |format|
diff --git a/spree/admin/app/controllers/spree/admin/variants_controller.rb b/spree/admin/app/controllers/spree/admin/variants_controller.rb
index 8d317c05be..e1cdf3e040 100644
--- a/spree/admin/app/controllers/spree/admin/variants_controller.rb
+++ b/spree/admin/app/controllers/spree/admin/variants_controller.rb
@@ -37,7 +37,7 @@ module Spree
@variants = scope.
eligible.
- multi_search(query).
+ search(query).
includes(:images, :prices, :stock_items, :stock_locations, :product, option_values: :option_type).
limit(params[:limit] || 20).
reorder('').
diff --git a/spree/admin/config/initializers/spree_admin_tables.rb b/spree/admin/config/initializers/spree_admin_tables.rb
index 803a6c755c..84b1eb18aa 100644
--- a/spree/admin/config/initializers/spree_admin_tables.rb
+++ b/spree/admin/config/initializers/spree_admin_tables.rb
@@ -12,7 +12,7 @@
Rails.application.config.after_initialize do
# Register Products table
- Spree.admin.tables.register(:products, model_class: Spree::Product, search_param: :multi_search)
+ Spree.admin.tables.register(:products, model_class: Spree::Product, search_param: :search)
# Product name with image (custom partial)
Spree.admin.tables.products.add :name,
@@ -190,7 +190,7 @@ Rails.application.config.after_initialize do
condition: -> { can?(:manage_tags, Spree::Product) }
# Register Orders table
- Spree.admin.tables.register(:orders, model_class: Spree::Order, search_param: :multi_search, date_range_param: :completed_at)
+ Spree.admin.tables.register(:orders, model_class: Spree::Order, search_param: :search, date_range_param: :completed_at)
Spree.admin.tables.orders.add :number,
label: :number,
@@ -351,7 +351,7 @@ Rails.application.config.after_initialize do
search_url: ->(view_context) { view_context.spree.select_options_admin_promotions_path(format: :json) }
# Register Checkouts table (draft orders)
- Spree.admin.tables.register(:checkouts, model_class: Spree::Order, search_param: :multi_search, date_range_param: :created_at, new_resource: false)
+ Spree.admin.tables.register(:checkouts, model_class: Spree::Order, search_param: :search, date_range_param: :created_at, new_resource: false)
Spree.admin.tables.checkouts.add :number,
label: :number,
@@ -427,7 +427,7 @@ Rails.application.config.after_initialize do
position: 80
# Register Users table
- Spree.admin.tables.register(:users, model_class: Spree.user_class, search_param: :multi_search, row_actions: false, link_to_action: :show)
+ Spree.admin.tables.register(:users, model_class: Spree.user_class, search_param: :search, row_actions: false, link_to_action: :show)
# User name with avatar
Spree.admin.tables.users.add :name,
@@ -934,7 +934,7 @@ Rails.application.config.after_initialize do
position: 70
# Register Metafield Definitions table
- Spree.admin.tables.register(:metafield_definitions, model_class: Spree::MetafieldDefinition, search_param: :multi_search, row_actions: true)
+ Spree.admin.tables.register(:metafield_definitions, model_class: Spree::MetafieldDefinition, search_param: :search, row_actions: true)
Spree.admin.tables.metafield_definitions.add :key,
label: :key,
@@ -1433,7 +1433,7 @@ Rails.application.config.after_initialize do
# ==========================================
# Price List Products Table
# ==========================================
- Spree.admin.tables.register(:price_list_products, model_class: Spree::Product, search_param: :multi_search, row_actions: false, new_resource: false)
+ Spree.admin.tables.register(:price_list_products, model_class: Spree::Product, search_param: :search, row_actions: false, new_resource: false)
Spree.admin.tables.price_list_products.add :name,
label: :name,
@@ -1541,7 +1541,7 @@ Rails.application.config.after_initialize do
# ==========================================
# Customer Group Users Table (users within a customer group)
# ==========================================
- Spree.admin.tables.register(:customer_group_users, model_class: Spree.user_class, search_param: :multi_search, row_actions: false, new_resource: false)
+ Spree.admin.tables.register(:customer_group_users, model_class: Spree.user_class, search_param: :search, row_actions: false, new_resource: false)
Spree.admin.tables.customer_group_users.add :name,
label: :name,
diff --git a/spree/admin/spec/controllers/spree/admin/products_controller_spec.rb b/spree/admin/spec/controllers/spree/admin/products_controller_spec.rb
index 381fe72c7d..7e6425efa8 100644
--- a/spree/admin/spec/controllers/spree/admin/products_controller_spec.rb
+++ b/spree/admin/spec/controllers/spree/admin/products_controller_spec.rb
@@ -30,7 +30,7 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
it 'can find a product by variant sku' do
variant = create(:variant, sku: 'ABC123', is_master: false)
product = create(:product, stores: [store], variants: [variant])
- get :index, params: { q: { multi_search: 'ABC123' } }
+ get :index, params: { q: { search: 'ABC123' } }
expect(assigns[:collection]).not_to be_empty
expect(assigns[:collection]).to include(product)
end
@@ -60,11 +60,11 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
context 'with views' do
render_views
- it 'can perform multi search' do
+ it 'can perform search' do
get :index, params: {
'q' => {
'status_eq' => 'active',
- 'multi_search' => 'anchor',
+ 'search' => 'anchor',
'classifications_taxon_id_in' => ['8b03b40e-094f-4803-8704-20ac02f9c167', '42e63c13-dbe7-483f-8237-3b0207145fed'],
'shipping_category_id_eq' => '8b03b40e-094f-4803-8704-20ac02f9c167',
'tags_name_in' => ['awesome'],
@@ -77,7 +77,7 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
end
it 'renders the export dialog inside the table turbo frame with search params' do
- get :index, params: { q: { multi_search: 'test-filter' } }
+ get :index, params: { q: { search: 'test-filter' } }
doc = Nokogiri::HTML(response.body)
table_frame = doc.at_css('turbo-frame#products')
diff --git a/spree/admin/spec/controllers/spree/admin/users_controller_spec.rb b/spree/admin/spec/controllers/spree/admin/users_controller_spec.rb
index 5e48f7ebe8..8225c9d477 100644
--- a/spree/admin/spec/controllers/spree/admin/users_controller_spec.rb
+++ b/spree/admin/spec/controllers/spree/admin/users_controller_spec.rb
@@ -41,11 +41,11 @@ RSpec.describe Spree::Admin::UsersController, type: :controller do
expect(assigns(:collection).to_a).to eq([user_2])
end
- describe 'multi_search' do
- subject { get :index, params: { q: { multi_search: multi_search_param } } }
+ describe 'search' do
+ subject { get :index, params: { q: { search: search_param } } }
context 'when searching by email' do
- let(:multi_search_param) { '[email protected]' }
+ let(:search_param) { '[email protected]' }
it 'returns users based on an email' do
subject
@@ -54,7 +54,7 @@ RSpec.describe Spree::Admin::UsersController, type: :controller do
end
context 'when searching by the first name' do
- let(:multi_search_param) { 'john' }
+ let(:search_param) { 'john' }
it 'returns users based on the first name' do
subject
@@ -63,7 +63,7 @@ RSpec.describe Spree::Admin::UsersController, type: :controller do
end
context 'when searching by the last name' do
- let(:multi_search_param) { 'doe' }
+ let(:search_param) { 'doe' }
it 'returns users based on the last name' do
subject
@@ -72,7 +72,7 @@ RSpec.describe Spree::Admin::UsersController, type: :controller do
end
context 'when searching by the full name' do
- let(:multi_search_param) { 'joh do' }
+ let(:search_param) { 'joh do' }
it 'returns users based on the full name' do
subject
diff --git a/spree/core/app/finders/spree/products/find.rb b/spree/core/app/finders/spree/products/find.rb
index 2791b45178..d7e6fddf78 100644
--- a/spree/core/app/finders/spree/products/find.rb
+++ b/spree/core/app/finders/spree/products/find.rb
@@ -112,7 +112,7 @@ module Spree
def by_query(products)
return products unless query?
- products.multi_search(query)
+ products.search(query)
end
def by_ids(products)
diff --git a/spree/core/app/models/concerns/spree/multi_searchable.rb b/spree/core/app/models/concerns/spree/searchable.rb
similarity index 55%
rename from spree/core/app/models/concerns/spree/multi_searchable.rb
rename to spree/core/app/models/concerns/spree/searchable.rb
index 1abe41a96c..3b886f4e22 100644
--- a/spree/core/app/models/concerns/spree/multi_searchable.rb
+++ b/spree/core/app/models/concerns/spree/searchable.rb
@@ -1,13 +1,13 @@
module Spree
- module MultiSearchable
+ module Searchable
extend ActiveSupport::Concern
included do
- def self.sanitize_query_for_multi_search(query)
+ def self.sanitize_query_for_search(query)
ActiveRecord::Base.sanitize_sql_like(query.to_s.downcase.strip)
end
- def self.multi_search_condition(model_class, attribute, query)
+ def self.search_condition(model_class, attribute, query)
encrypted_attributes = model_class.encrypted_attributes.presence || []
if encrypted_attributes.include?(attribute.to_sym)
@@ -16,6 +16,13 @@ module Spree
model_class.arel_table[attribute.to_sym].lower.matches("%#{query}%")
end
end
+
+ # Backward compatibility aliases — remove in Spree 6.0
+ def self.sanitize_query_for_multi_search(query) = sanitize_query_for_search(query)
+ def self.multi_search_condition(model_class, attribute, query) = search_condition(model_class, attribute, query)
end
end
+
+ # Backward compatibility alias — remove in Spree 6.0
+ MultiSearchable = Searchable
end
diff --git a/spree/core/app/models/concerns/spree/user_methods.rb b/spree/core/app/models/concerns/spree/user_methods.rb
index 5074893fd9..f23c96b4d2 100644
--- a/spree/core/app/models/concerns/spree/user_methods.rb
+++ b/spree/core/app/models/concerns/spree/user_methods.rb
@@ -9,7 +9,7 @@ module Spree
include Spree::UserReporting
include Spree::UserRoles
include Spree::RansackableAttributes
- include Spree::MultiSearchable
+ include Spree::Searchable
include Spree::Publishable
included do
@@ -74,28 +74,31 @@ module Spree
find_by_token_for!(:password_reset, token)
end
- def self.multi_search(query)
- sanitized_query = sanitize_query_for_multi_search(query)
+ def self.search(query)
+ sanitized_query = sanitize_query_for_search(query)
return none if query.blank?
name_conditions = []
- name_conditions << multi_search_condition(self, :first_name, sanitized_query)
- name_conditions << multi_search_condition(self, :last_name, sanitized_query)
+ name_conditions << search_condition(self, :first_name, sanitized_query)
+ name_conditions << search_condition(self, :last_name, sanitized_query)
full_name = NameOfPerson::PersonName.full(sanitized_query)
if full_name.first.present? && full_name.last.present?
- name_conditions << multi_search_condition(self, :first_name, full_name.first)
- name_conditions << multi_search_condition(self, :last_name, full_name.last)
+ name_conditions << search_condition(self, :first_name, full_name.first)
+ name_conditions << search_condition(self, :last_name, full_name.last)
end
where(arel_table[:email].lower.eq(query.downcase)).or(where(name_conditions.reduce(:or)))
end
+ # Backward compatibility alias — remove in Spree 6.0
+ def self.multi_search(query) = search(query)
+
self.whitelisted_ransackable_associations = %w[bill_address ship_address addresses tags spree_roles]
self.whitelisted_ransackable_attributes = %w[id email first_name last_name accepts_email_marketing]
- self.whitelisted_ransackable_scopes = %w[multi_search]
+ self.whitelisted_ransackable_scopes = %w[search multi_search]
def self.with_email(query)
where("#{table_name}.email LIKE ?", "%#{query}%")
diff --git a/spree/core/app/models/spree/metafield_definition.rb b/spree/core/app/models/spree/metafield_definition.rb
index 7c7a1c1694..97c09275a1 100644
--- a/spree/core/app/models/spree/metafield_definition.rb
+++ b/spree/core/app/models/spree/metafield_definition.rb
@@ -23,10 +23,10 @@ module Spree
# Scopes
#
scope :for_resource_type, ->(resource_type) { where(resource_type: resource_type) }
- scope :multi_search, ->(search) do
- return all if search.blank?
+ scope :search, ->(query) do
+ return all if query.blank?
- search_term = "%#{search.downcase}%"
+ search_term = "%#{query.downcase}%"
namespace_condition = arel_table[:namespace].lower.matches(search_term)
key_condition = arel_table[:key].lower.matches(search_term)
name_condition = arel_table[:name].lower.matches(search_term)
@@ -34,6 +34,9 @@ module Spree
where(namespace_condition.or(key_condition).or(name_condition))
end
+ # Backward compatibility alias — remove in Spree 6.0
+ scope :multi_search, ->(*args) { search(*args) }
+
#
# Callbacks
#
@@ -46,7 +49,7 @@ module Spree
# Ransack
#
self.whitelisted_ransackable_attributes = %w[key namespace name resource_type display_on]
- self.whitelisted_ransackable_scopes = %w[multi_search]
+ self.whitelisted_ransackable_scopes = %w[search multi_search]
# Returns the full key with namespace
# @return [String] eg. custom.id
diff --git a/spree/core/app/models/spree/order.rb b/spree/core/app/models/spree/order.rb
index 07d1946b1f..69020539cb 100644
--- a/spree/core/app/models/spree/order.rb
+++ b/spree/core/app/models/spree/order.rb
@@ -32,7 +32,7 @@ module Spree
include Spree::MemoizedData
include Spree::Metafields
include Spree::Metadata
- include Spree::MultiSearchable
+ include Spree::Searchable
if defined?(Spree::Security::Orders)
include Spree::Security::Orders
end
@@ -87,7 +87,7 @@ module Spree
completed_at email number state payment_state shipment_state
total item_total item_count considered_risky channel
]
- self.whitelisted_ransackable_scopes = %w[refunded partially_refunded multi_search]
+ self.whitelisted_ransackable_scopes = %w[refunded partially_refunded search multi_search]
attr_reader :coupon_code
attr_accessor :temporary_address
@@ -220,8 +220,8 @@ module Spree
# shows completed orders first, by their completed_at date, then uncompleted orders by their created_at
scope :reverse_chronological, -> { order(Arel.sql('spree_orders.completed_at IS NULL'), completed_at: :desc, created_at: :desc) }
- def self.multi_search(query)
- sanitized_query = sanitize_query_for_multi_search(query)
+ def self.search(query)
+ sanitized_query = sanitize_query_for_search(query)
return none if query.blank?
query_pattern = "%#{sanitized_query}%"
@@ -229,19 +229,22 @@ module Spree
conditions = []
conditions << arel_table[:number].lower.matches(query_pattern)
- conditions << multi_search_condition(Spree::Address, :firstname, sanitized_query)
- conditions << multi_search_condition(Spree::Address, :lastname, sanitized_query)
+ conditions << search_condition(Spree::Address, :firstname, sanitized_query)
+ conditions << search_condition(Spree::Address, :lastname, sanitized_query)
full_name = NameOfPerson::PersonName.full(sanitized_query)
if full_name.first.present? && full_name.last.present?
- conditions << multi_search_condition(Spree::Address, :firstname, full_name.first)
- conditions << multi_search_condition(Spree::Address, :lastname, full_name.last)
+ conditions << search_condition(Spree::Address, :firstname, full_name.first)
+ conditions << search_condition(Spree::Address, :lastname, full_name.last)
end
left_joins(:bill_address).where(arel_table[:email].lower.eq(query.downcase)).or(where(conditions.reduce(:or)))
end
+ # Backward compatibility alias — remove in Spree 6.0
+ def self.multi_search(query) = search(query)
+
# Find an order by prefixed ID first, falling back to number, then integer id for backwards compatibility
# @param param [String] the prefixed ID, number, or integer id to search for
# @return [Spree::Order, nil] the found order or nil
diff --git a/spree/core/app/models/spree/variant.rb b/spree/core/app/models/spree/variant.rb
index 9dae271f3f..d24d8309a9 100644
--- a/spree/core/app/models/spree/variant.rb
+++ b/spree/core/app/models/spree/variant.rb
@@ -129,33 +129,14 @@ module Spree
scope :with_digital_assets, -> { joins(:digitals) }
- if defined?(PgSearch)
- include PgSearch::Model
+ scope :search, ->(query) {
+ next none if query.blank? || query.length < 3
- pg_search_scope :search_by_sku, against: :sku, using: { tsearch: { prefix: true } }
-
- pg_search_scope :search_by_sku_or_options,
- against: :sku,
- using: { tsearch: { prefix: true } },
- associated_against: { option_values: %i[presentation] }
-
- pg_search_scope :search_by_name_sku_or_options, against: :sku, associated_against: {
- product: %i[name],
- option_values: %i[presentation]
- }, using: { tsearch: { prefix: true } }
-
- scope :multi_search, lambda { |query|
- return none if query.blank? || query.length < 3
-
- search_by_name_sku_or_options(query)
- }
- else
- scope :multi_search, lambda { |query|
- return none if query.blank? || query.length < 3
+ product_name_or_sku_cont(query)
+ }
- product_name_or_sku_cont(query)
- }
- end
+ # Backward compatibility alias — remove in Spree 6.0
+ scope :multi_search, ->(*args) { search(*args) }
# FIXME: cost price should be represented with DisplayMoney class
LOCALIZED_NUMBERS = %w(cost_price weight depth width height)
diff --git a/spree/core/spec/models/spree/concerns/user_methods_spec.rb b/spree/core/spec/models/spree/concerns/user_methods_spec.rb
index 1ff4e0689b..c7c338b0e8 100644
--- a/spree/core/spec/models/spree/concerns/user_methods_spec.rb
+++ b/spree/core/spec/models/spree/concerns/user_methods_spec.rb
@@ -115,7 +115,7 @@ describe Spree::UserMethods do
end
end
- describe '.multi_search' do
+ describe '.search' do
let!(:user_1) { create(:user, email: '[email protected]', first_name: 'John', last_name: 'Doe') }
let!(:user_2) { create(:user, email: '[email protected]', first_name: 'Jane', last_name: 'Gone') }
let!(:user_3) { create(:user, email: '[email protected]', first_name: 'Mary', last_name: 'Moe') }
@@ -123,35 +123,35 @@ describe Spree::UserMethods do
let!(:user_5) { create(:user, email: '[email protected]', first_name: 'John', last_name: 'Doe') }
it 'returns users based on an email' do
- expect(Spree.user_class.multi_search('[email protected]')).to eq([user_1])
- expect(Spree.user_class.multi_search('[email protected]')).to eq([user_2])
- expect(Spree.user_class.multi_search('[email protected]')).to eq([user_4])
- expect(Spree.user_class.multi_search('[email protected]')).to eq([user_5])
- expect(Spree.user_class.multi_search('mary.moe@')).to eq([])
+ expect(Spree.user_class.search('[email protected]')).to eq([user_1])
+ expect(Spree.user_class.search('[email protected]')).to eq([user_2])
+ expect(Spree.user_class.search('[email protected]')).to eq([user_4])
+ expect(Spree.user_class.search('[email protected]')).to eq([user_5])
+ expect(Spree.user_class.search('mary.moe@')).to eq([])
end
it 'returns users based on the first name' do
- expect(Spree.user_class.multi_search('joh')).to include(user_1, user_5)
- expect(Spree.user_class.multi_search('jan')).to include(user_2)
- expect(Spree.user_class.multi_search('jan')).not_to include(user_1, user_3, user_4, user_5)
- expect(Spree.user_class.multi_search('greg')).not_to include(user_1, user_2, user_3, user_4, user_5)
+ expect(Spree.user_class.search('joh')).to include(user_1, user_5)
+ expect(Spree.user_class.search('jan')).to include(user_2)
+ expect(Spree.user_class.search('jan')).not_to include(user_1, user_3, user_4, user_5)
+ expect(Spree.user_class.search('greg')).not_to include(user_1, user_2, user_3, user_4, user_5)
end
it 'returns users based on the last name' do
- expect(Spree.user_class.multi_search('do')).to include(user_1, user_5)
- expect(Spree.user_class.multi_search('moe')).to include(user_3)
- expect(Spree.user_class.multi_search('moe')).not_to include(user_1, user_2, user_4, user_5)
- expect(Spree.user_class.multi_search('smith')).not_to include(user_1, user_2, user_3, user_4, user_5)
+ expect(Spree.user_class.search('do')).to include(user_1, user_5)
+ expect(Spree.user_class.search('moe')).to include(user_3)
+ expect(Spree.user_class.search('moe')).not_to include(user_1, user_2, user_4, user_5)
+ expect(Spree.user_class.search('smith')).not_to include(user_1, user_2, user_3, user_4, user_5)
end
it 'returns users based on the full name' do
- expect(Spree.user_class.multi_search('joh do')).to include(user_1, user_5)
- expect(Spree.user_class.multi_search('ane gon')).to include(user_2)
- expect(Spree.user_class.multi_search('ane gon')).not_to include(user_1, user_3, user_4, user_5)
- expect(Spree.user_class.multi_search('mary moe')).to include(user_3)
- expect(Spree.user_class.multi_search('mary moe')).not_to include(user_1, user_2, user_4, user_5)
- expect(Spree.user_class.multi_search('jane moe')).to include(user_2, user_3)
- expect(Spree.user_class.multi_search('greg smith')).not_to include(user_1, user_2, user_3, user_4, user_5)
+ expect(Spree.user_class.search('joh do')).to include(user_1, user_5)
+ expect(Spree.user_class.search('ane gon')).to include(user_2)
+ expect(Spree.user_class.search('ane gon')).not_to include(user_1, user_3, user_4, user_5)
+ expect(Spree.user_class.search('mary moe')).to include(user_3)
+ expect(Spree.user_class.search('mary moe')).not_to include(user_1, user_2, user_4, user_5)
+ expect(Spree.user_class.search('jane moe')).to include(user_2, user_3)
+ expect(Spree.user_class.search('greg smith')).not_to include(user_1, user_2, user_3, user_4, user_5)
end
end
diff --git a/spree/core/spec/models/spree/order_spec.rb b/spree/core/spec/models/spree/order_spec.rb
index baed27fdf8..50dab536c6 100644
--- a/spree/core/spec/models/spree/order_spec.rb
+++ b/spree/core/spec/models/spree/order_spec.rb
@@ -37,7 +37,7 @@ describe Spree::Order, type: :model do
it { expect(Spree::Order.not_canceled).not_to include canceled_order }
end
- describe '.multi_search' do
+ describe '.search' do
let!(:order_1) { create(:order, number: 'R100', user: create(:user, email: '[email protected]'), bill_address: create(:address, first_name: 'Don', last_name: 'Roe')) }
let!(:order_2) { create(:order, number: 'R101', user: create(:user, email: '[email protected]'), bill_address: create(:address, first_name: 'Jane', last_name: 'Gone')) }
let!(:order_3) { create(:order, number: 'R200', user: create(:user, email: '[email protected]'), bill_address: create(:address, first_name: 'Mary', last_name: 'Moe')) }
@@ -45,31 +45,31 @@ describe Spree::Order, type: :model do
let!(:order_5) { create(:order, number: 'R400', user: create(:user, email: '[email protected]'), bill_address: create(:address, first_name: 'John', last_name: 'Doe')) }
it 'returns orders based on an email' do
- expect(described_class.multi_search('[email protected]')).to eq([order_1])
- expect(described_class.multi_search('[email protected]')).to eq([order_2])
- expect(described_class.multi_search('[email protected]')).to eq([order_4])
- expect(described_class.multi_search('[email protected]')).to eq([order_5])
- expect(described_class.multi_search('mary.moe@')).to eq([])
+ expect(described_class.search('[email protected]')).to eq([order_1])
+ expect(described_class.search('[email protected]')).to eq([order_2])
+ expect(described_class.search('[email protected]')).to eq([order_4])
+ expect(described_class.search('[email protected]')).to eq([order_5])
+ expect(described_class.search('mary.moe@')).to eq([])
end
it 'returns orders based on the first name' do
- expect(described_class.multi_search('don')).to eq([order_1])
- expect(described_class.multi_search('jan')).to eq([order_2])
- expect(described_class.multi_search('greg')).to eq([])
+ expect(described_class.search('don')).to eq([order_1])
+ expect(described_class.search('jan')).to eq([order_2])
+ expect(described_class.search('greg')).to eq([])
end
it 'returns orders based on the last name' do
- expect(described_class.multi_search('ro')).to eq([order_1])
- expect(described_class.multi_search('moe')).to eq([order_3])
- expect(described_class.multi_search('smith')).to eq([])
+ expect(described_class.search('ro')).to eq([order_1])
+ expect(described_class.search('moe')).to eq([order_3])
+ expect(described_class.search('smith')).to eq([])
end
it 'returns orders based on the full name' do
- expect(described_class.multi_search('don ro')).to eq([order_1])
- expect(described_class.multi_search('ane gon')).to eq([order_2])
- expect(described_class.multi_search('mary moe')).to eq([order_3])
- expect(described_class.multi_search('jane moe')).to eq([order_2, order_3])
- expect(described_class.multi_search('greg smith')).to eq([])
+ expect(described_class.search('don ro')).to eq([order_1])
+ expect(described_class.search('ane gon')).to eq([order_2])
+ expect(described_class.search('mary moe')).to eq([order_3])
+ expect(described_class.search('jane moe')).to eq([order_2, order_3])
+ expect(described_class.search('greg smith')).to eq([])
end
end
end