[ホーム]
[最新エントリー]
[あすなろBLOG]
[あすなろNEXTBLOG]
[あすなろカウンセラーBLOG]
[インタビュー]
[スペシャルコンテンツ]
[テックスペース]
家で働くママ日記
日比 知子
2007年07月05日
acts_as_searchableのfulltext_searchの:findオプション
acts_as_searchableを使っているのですが、「ぉ!」と思った検索オプションがあった(そして日本語ではまだ知られていないぽい?)ので紹介しておきます。また使い倒していないので、勘違いがあるかもしれませんが。
http://poocs.net/2006/4/6/introducing-acts-as-searchablehttp://ar-searchable.rubyforge.org/
fulltext_search(query = "", options = {})
- limit - Maximum number of records to retrieve (default:
100)
- offset - Number of records to skip (default: 0)
- order - Hyper Estraier expression to sort the results (example:
@title STRA, default: ordering by score)
- attributes - String to append to Hyper Estraier search query
- raw_matches - Returns raw Hyper Estraier documents instead of
instantiated AR objects
- find - Options to pass on to the ActiveRecord::Base#find
call
Article.fulltext_search("biscuits AND gravy")
Article.fulltext_search("biscuits AND gravy", :limit => 15, :offset => 14)
Article.fulltext_search("biscuits AND gravy", :attributes => "tag STRINC food")
Article.fulltext_search("biscuits AND gravy", :attributes => ["tag STRINC food", "@title STRBW Biscuit"])
Article.fulltext_search("biscuits AND gravy", :order => "@title STRA")
Article.fulltext_search("biscuits AND gravy", :raw_matches => true)
Article.fulltext_search("biscuits AND gravy", :find => { :order => :title, :include => :comments })
:findオプションや、:offsetもちゃんとあるんですね。
:findオプションはドキュメント内のソースを見る限り、Hyperestraiyer(HE)で検索してから、ヒットしたARのIDを元にARのfind検索をしていて、その際の:findオプション条件として渡せるようです。ただ:conditioinsを渡した場合、その条件での結果と、HEでマッチした結果が一致しない場合は、”ActiveRecord::RecordNotFound: Couldn't find all Items with IDs”というエラーが帰ってきます。:order、:includeぐらいにしておいた方がいいかもですね。
- 日比 知子
2011年03月02日
金柑の甘露煮、作りました+お勧めレシピリンク有り
- 日比 知子
2011年02月21日
手袋編みました(かぎ針+細編み)
- 日比 知子
2011年02月09日
iTunesで映画に字幕付きかどうかは、価格のボタンの下に cc があるかどうか
- 日比 知子
2011年02月03日
節分の日。豆富本舗の節分豆が美味しい。
- 日比 知子
2011年01月31日
小川 糸さんの「食堂かたつむり」読みました
バックナンバー
ページトップ
[ホーム]
[ブログコンセプト]
[個人情報]
[著作権]
Copyright(C)2006-2011
Pasona Tech. inc.
All Rights Reserved.