1- require 'support/active_record_schema'
2-
3- ar_schema . create_table :books do |t |
4- t . string :name
5- t . string :author
6- t . boolean :premium
7- t . boolean :released
8- t . string :genre
9- end
10-
11- class Book < ActiveRecord ::Base
1+ book_specification = Models ::ModelSpecification . new (
2+ 'Book' ,
3+ fields : [
4+ %i[ name string ] ,
5+ %i[ author string ] ,
6+ %i[ premium boolean ] ,
7+ %i[ released boolean ] ,
8+ %i[ genre string ]
9+ ]
10+ ) do
1211 include Meilisearch ::Rails
1312
1413 meilisearch synchronous : true , index_uid : safe_index_uid ( 'SecuredBook' ) , sanitize : true do
@@ -33,10 +32,37 @@ def public?
3332 end
3433end
3534
36- module TestUtil
37- def self . reset_books!
38- Book . clear_index! ( true )
39- Book . index ( safe_index_uid ( 'BookAuthor' ) ) . delete_all_documents
40- Book . index ( safe_index_uid ( 'Book' ) ) . delete_all_documents
41- end
42- end
35+ Models ::ActiveRecord . initialize_model ( book_specification )
36+
37+ # class Book < ActiveRecord::Base
38+ # include Meilisearch::Rails
39+ #
40+ # meilisearch synchronous: true, index_uid: safe_index_uid('SecuredBook'), sanitize: true do
41+ # searchable_attributes [:name]
42+ # typo_tolerance min_word_size_for_typos: { one_typo: 5, twoTypos: 8 }
43+ # filterable_attributes %i[genre author]
44+ # faceting max_values_per_facet: 3
45+ #
46+ # add_index safe_index_uid('BookAuthor') do
47+ # searchable_attributes [:author]
48+ # end
49+ #
50+ # add_index safe_index_uid('Book'), if: :public? do
51+ # searchable_attributes [:name]
52+ # end
53+ # end
54+ #
55+ # private
56+ #
57+ # def public?
58+ # released && !premium
59+ # end
60+ # end
61+
62+ # module TestUtil
63+ # def self.reset_books!
64+ # Book.clear_index!(true)
65+ # Book.index(safe_index_uid('BookAuthor')).delete_all_documents
66+ # Book.index(safe_index_uid('Book')).delete_all_documents
67+ # end
68+ # end
0 commit comments