Class: Spree::SearchProvider::Base
- Inherits:
-
Object
- Object
- Spree::SearchProvider::Base
- Defined in:
- app/models/spree/search_provider/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Class Method Summary collapse
-
.indexing_required? ⇒ Boolean
Whether this provider requires background indexing jobs.
Instance Method Summary collapse
-
#ensure_index_settings! ⇒ Object
Configure index settings (filterable, sortable, searchable attributes).
-
#filters(scope:, query: nil, filters: {}) ⇒ FiltersResult
Compute filter facets, sort options, and total count for the given scope.
-
#index(product) ⇒ Object
Index a product — called after product save.
-
#index_batch(documents) ⇒ Object
Index a batch of documents.
-
#initialize(store) ⇒ Base
constructor
A new instance of Base.
- #metafield_schema ⇒ MetafieldSchema
-
#reindex(scope = nil) ⇒ Object
Bulk reindex — full catalog sync.
-
#remove(product) ⇒ Object
Remove a product from the index.
-
#remove_by_id(prefixed_id) ⇒ Object
Remove a document from the index by prefixed ID (used when record is already deleted).
-
#search_and_filter(scope:, query: nil, filters: {}, sort: nil, page: 1, limit: 25) ⇒ SearchResult
Search and paginate products.
Constructor Details
#initialize(store) ⇒ Base
Returns a new instance of Base.
12 13 14 |
# File 'app/models/spree/search_provider/base.rb', line 12 def initialize(store) @store = store end |
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
4 5 6 |
# File 'app/models/spree/search_provider/base.rb', line 4 def store @store end |
Class Method Details
.indexing_required? ⇒ Boolean
Whether this provider requires background indexing jobs. Override in subclasses. Database provider returns false.
8 9 10 |
# File 'app/models/spree/search_provider/base.rb', line 8 def self.indexing_required? false end |
Instance Method Details
#ensure_index_settings! ⇒ Object
Configure index settings (filterable, sortable, searchable attributes). Called by rake task before indexing. No-op for database provider.
76 77 78 |
# File 'app/models/spree/search_provider/base.rb', line 76 def ensure_index_settings! # no-op by default end |
#filters(scope:, query: nil, filters: {}) ⇒ FiltersResult
Compute filter facets, sort options, and total count for the given scope. Called by the dedicated filters endpoint — kept separate from search_and_filter to avoid expensive facet queries on every product listing.
42 43 44 |
# File 'app/models/spree/search_provider/base.rb', line 42 def filters(scope:, query: nil, filters: {}) raise NotImplementedError end |
#index(product) ⇒ Object
Index a product — called after product save. No-op for database provider.
49 50 51 |
# File 'app/models/spree/search_provider/base.rb', line 49 def index(product) # no-op by default end |
#index_batch(documents) ⇒ Object
Index a batch of documents. Called by rake task with pre-serialized documents.
70 71 72 |
# File 'app/models/spree/search_provider/base.rb', line 70 def index_batch(documents) # no-op by default end |
#metafield_schema ⇒ MetafieldSchema
17 18 19 |
# File 'app/models/spree/search_provider/base.rb', line 17 def @metafield_schema ||= MetafieldSchema.new end |
#reindex(scope = nil) ⇒ Object
Bulk reindex — full catalog sync. Called manually or via rake task.
83 84 85 |
# File 'app/models/spree/search_provider/base.rb', line 83 def reindex(scope = nil) # no-op by default end |
#remove(product) ⇒ Object
Remove a product from the index.
56 57 58 |
# File 'app/models/spree/search_provider/base.rb', line 56 def remove(product) # no-op by default end |
#remove_by_id(prefixed_id) ⇒ Object
Remove a document from the index by prefixed ID (used when record is already deleted).
63 64 65 |
# File 'app/models/spree/search_provider/base.rb', line 63 def remove_by_id(prefixed_id) # no-op by default end |
#search_and_filter(scope:, query: nil, filters: {}, sort: nil, page: 1, limit: 25) ⇒ SearchResult
Search and paginate products. Does NOT compute filter facets — use #filters for that.
30 31 32 |
# File 'app/models/spree/search_provider/base.rb', line 30 def search_and_filter(scope:, query: nil, filters: {}, sort: nil, page: 1, limit: 25) raise NotImplementedError end |