[{"data":1,"prerenderedAt":483},["ShallowReactive",2],{"docs-cloud/frameworks/rails":3},{"id":4,"title":5,"body":6,"description":473,"extension":474,"meta":475,"navigation":232,"path":476,"seo":477,"seoDescription":478,"seoTitle":479,"sitemap":480,"stem":481,"__hash__":482},"docs/docs/cloud/frameworks/rails.md","Ruby on Rails",{"type":7,"value":8,"toc":465},"minimark",[9,13,25,30,54,70,74,104,184,191,195,301,311,314,329,332,336,417,421,433,437,461],[10,11,5],"h1",{"id":12},"ruby-on-rails",[14,15,16,17,24],"p",{},"The official ",[18,19,23],"a",{"href":20,"rel":21},"https://github.com/meilisearch/meilisearch-rails",[22],"nofollow","meilisearch-rails","\ngem indexes your Active Record models and searches them. Point it at your\nCelerSearch instance and it works as it would with any Meilisearch.",[26,27,29],"h2",{"id":28},"_1-install","1. Install",[31,32,38],"pre",{"className":33,"code":34,"filename":35,"language":36,"meta":37,"style":37},"language-ruby shiki shiki-themes github-light github-dark","gem 'meilisearch-rails'\n","Gemfile","ruby","",[39,40,41],"code",{"__ignoreMap":37},[42,43,46,50],"span",{"class":44,"line":45},"line",1,[42,47,49],{"class":48},"sVt8B","gem ",[42,51,53],{"class":52},"sZZnC","'meilisearch-rails'\n",[31,55,59],{"className":56,"code":57,"language":58,"meta":37,"style":37},"language-bash shiki shiki-themes github-light github-dark","bundle install\n","bash",[39,60,61],{"__ignoreMap":37},[42,62,63,67],{"class":44,"line":45},[42,64,66],{"class":65},"sScJk","bundle",[42,68,69],{"class":52}," install\n",[26,71,73],{"id":72},"_2-configure","2. Configure",[14,75,76,77,81,82,85,86,89,90,95,96,99,100,103],{},"Copy the ",[78,79,80],"strong",{},"Endpoint URL"," and ",[78,83,84],{},"API key"," from your instance's ",[78,87,88],{},"Connection\ndetails"," at ",[18,91,94],{"href":92,"rel":93},"https://app.celersearch.com",[22],"app.celersearch.com",", and expose\nthem as environment variables (",[39,97,98],{},"MEILISEARCH_HOST",", ",[39,101,102],{},"MEILISEARCH_API_KEY",") or\nRails credentials.",[31,105,108],{"className":33,"code":106,"filename":107,"language":36,"meta":37,"style":37},"Meilisearch::Rails.configuration = {\n  meilisearch_url: ENV.fetch('MEILISEARCH_HOST'),\n  meilisearch_api_key: ENV.fetch('MEILISEARCH_API_KEY')\n}\n","config/initializers/meilisearch.rb",[39,109,110,135,158,178],{"__ignoreMap":37},[42,111,112,116,119,122,125,128,132],{"class":44,"line":45},[42,113,115],{"class":114},"sj4cs","Meilisearch",[42,117,118],{"class":48},"::",[42,120,121],{"class":114},"Rails",[42,123,124],{"class":48},".",[42,126,127],{"class":65},"configuration",[42,129,131],{"class":130},"szBVR"," =",[42,133,134],{"class":48}," {\n",[42,136,138,141,144,146,149,152,155],{"class":44,"line":137},2,[42,139,140],{"class":114},"  meilisearch_url:",[42,142,143],{"class":114}," ENV",[42,145,124],{"class":48},[42,147,148],{"class":65},"fetch",[42,150,151],{"class":48},"(",[42,153,154],{"class":52},"'MEILISEARCH_HOST'",[42,156,157],{"class":48},"),\n",[42,159,161,164,166,168,170,172,175],{"class":44,"line":160},3,[42,162,163],{"class":114},"  meilisearch_api_key:",[42,165,143],{"class":114},[42,167,124],{"class":48},[42,169,148],{"class":65},[42,171,151],{"class":48},[42,173,174],{"class":52},"'MEILISEARCH_API_KEY'",[42,176,177],{"class":48},")\n",[42,179,181],{"class":44,"line":180},4,[42,182,183],{"class":48},"}\n",[185,186,188],"warning",{"title":187},"Server-side only",[14,189,190],{},"The API key has full access to your instance. Keep it in your server's\nenvironment or credentials. Never render it into views or JavaScript.",[26,192,194],{"id":193},"_3-index-a-model","3. Index a model",[31,196,199],{"className":33,"code":197,"filename":198,"language":36,"meta":37,"style":37},"class Book \u003C ApplicationRecord\n  include Meilisearch::Rails\n\n  meilisearch enqueue: true do\n    attribute :title, :author, :genre\n    filterable_attributes [:genre]\n    sortable_attributes [:title]\n  end\nend\n","app/models/book.rb",[39,200,201,215,228,234,248,267,279,289,295],{"__ignoreMap":37},[42,202,203,206,209,212],{"class":44,"line":45},[42,204,205],{"class":130},"class",[42,207,208],{"class":65}," Book",[42,210,211],{"class":48}," \u003C ",[42,213,214],{"class":65},"ApplicationRecord\n",[42,216,217,220,223,225],{"class":44,"line":137},[42,218,219],{"class":130},"  include",[42,221,222],{"class":114}," Meilisearch",[42,224,118],{"class":48},[42,226,227],{"class":114},"Rails\n",[42,229,230],{"class":44,"line":160},[42,231,233],{"emptyLinePlaceholder":232},true,"\n",[42,235,236,239,242,245],{"class":44,"line":180},[42,237,238],{"class":48},"  meilisearch ",[42,240,241],{"class":114},"enqueue:",[42,243,244],{"class":114}," true",[42,246,247],{"class":130}," do\n",[42,249,251,254,257,259,262,264],{"class":44,"line":250},5,[42,252,253],{"class":48},"    attribute ",[42,255,256],{"class":114},":title",[42,258,99],{"class":48},[42,260,261],{"class":114},":author",[42,263,99],{"class":48},[42,265,266],{"class":114},":genre\n",[42,268,270,273,276],{"class":44,"line":269},6,[42,271,272],{"class":48},"    filterable_attributes [",[42,274,275],{"class":114},":genre",[42,277,278],{"class":48},"]\n",[42,280,282,285,287],{"class":44,"line":281},7,[42,283,284],{"class":48},"    sortable_attributes [",[42,286,256],{"class":114},[42,288,278],{"class":48},[42,290,292],{"class":44,"line":291},8,[42,293,294],{"class":130},"  end\n",[42,296,298],{"class":44,"line":297},9,[42,299,300],{"class":130},"end\n",[14,302,303,306,307,310],{},[39,304,305],{},"enqueue: true"," moves indexing into Active Job (on a ",[39,308,309],{},"meilisearch"," queue), so\nsaving a record never waits on a network call. Drop it to index inline.",[14,312,313],{},"Import the records you already have:",[31,315,317],{"className":33,"code":316,"language":36,"meta":37,"style":37},"Book.reindex!\n",[39,318,319],{"__ignoreMap":37},[42,320,321,324,326],{"class":44,"line":45},[42,322,323],{"class":114},"Book",[42,325,124],{"class":48},[42,327,328],{"class":65},"reindex!\n",[14,330,331],{},"New, changed and deleted records are synced automatically after that.",[26,333,335],{"id":334},"_4-search","4. Search",[31,337,339],{"className":33,"code":338,"language":36,"meta":37,"style":37},"# Typo-tolerant search, returning Book records\nBook.search('harry pottre')\n\n# Filter, sort and page size\nBook.search('harry', filter: ['genre = fantasy'], sort: ['title:asc'], hits_per_page: 10)\n",[39,340,341,347,363,367,372],{"__ignoreMap":37},[42,342,343],{"class":44,"line":45},[42,344,346],{"class":345},"sJ8bj","# Typo-tolerant search, returning Book records\n",[42,348,349,351,353,356,358,361],{"class":44,"line":137},[42,350,323],{"class":114},[42,352,124],{"class":48},[42,354,355],{"class":65},"search",[42,357,151],{"class":48},[42,359,360],{"class":52},"'harry pottre'",[42,362,177],{"class":48},[42,364,365],{"class":44,"line":160},[42,366,233],{"emptyLinePlaceholder":232},[42,368,369],{"class":44,"line":180},[42,370,371],{"class":345},"# Filter, sort and page size\n",[42,373,374,376,378,380,382,385,387,390,393,396,399,402,404,407,409,412,415],{"class":44,"line":250},[42,375,323],{"class":114},[42,377,124],{"class":48},[42,379,355],{"class":65},[42,381,151],{"class":48},[42,383,384],{"class":52},"'harry'",[42,386,99],{"class":48},[42,388,389],{"class":114},"filter:",[42,391,392],{"class":48}," [",[42,394,395],{"class":52},"'genre = fantasy'",[42,397,398],{"class":48},"], ",[42,400,401],{"class":114},"sort:",[42,403,392],{"class":48},[42,405,406],{"class":52},"'title:asc'",[42,408,398],{"class":48},[42,410,411],{"class":114},"hits_per_page:",[42,413,414],{"class":114}," 10",[42,416,177],{"class":48},[26,418,420],{"id":419},"plans-and-limits","Plans and limits",[14,422,423,424,428,429,124],{},"Each indexed record is one document toward your plan's\n",[18,425,427],{"href":426},"/docs/cloud/plans","document limit",". Searches are always unlimited. At the\nlimit, new writes are refused until you delete documents or move to a larger\nplan. See ",[18,430,432],{"href":431},"/docs/cloud/connect-any-app#when-you-reach-the-document-limit","Connect Any App",[26,434,436],{"id":435},"next-steps","Next steps",[438,439,440,447,454],"ul",{},[441,442,443,446],"li",{},[18,444,432],{"href":445},"/docs/cloud/connect-any-app",": connection details, platform responses and browser search",[441,448,449,453],{},[18,450,452],{"href":451},"/docs/cloud/migrate","Migrate to CelerSearch",": move an existing index from another Meilisearch",[441,455,456,460],{},[18,457,459],{"href":458},"/pricing","Pricing",": plans by document count",[462,463,464],"style",{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":37,"searchDepth":137,"depth":137,"links":466},[467,468,469,470,471,472],{"id":28,"depth":137,"text":29},{"id":72,"depth":137,"text":73},{"id":193,"depth":137,"text":194},{"id":334,"depth":137,"text":335},{"id":419,"depth":137,"text":420},{"id":435,"depth":137,"text":436},"Use the meilisearch-rails gem with a managed CelerSearch instance. Point the initializer at your endpoint, declare what to index on your models, and search Active Record with typo tolerance.","md",{},"/docs/cloud/frameworks/rails",{"title":5,"description":473},"Connect the meilisearch-rails gem to a managed Meilisearch instance. Configure the initializer, index Active Record models, reindex and search.","Ruby on Rails Search with Managed Meilisearch",{"loc":476},"docs/cloud/frameworks/rails","d5oPc_QVcrmQWiC9qqLqHr6IREPLwxosIU6Qkj1n8d0",1792316274557]