Rails sunspot 要如何設定才能令在隨 ubuntu 11.10 伺服器一併起動,不用再去應用程式輸入命令?

idarfan · 2012年04月20日 · 最后由 idarfan 回复于 2012年04月23日 · 2536 次阅读

各位大俠大家好:

看著老外的教程把 sunspot 搭配著 slor 搞了起來,可有件事我很納悶 目前我還是跑著 rails 內鍵的伺服器,可是每次我把應用程式跑起來 就要再應用程式的目錄下執行下述指令。

rake sunspot:solr:start 有什麼法子該它能隨伺服器一併啟動,懇請賜教

另外我知道在做全文檢索時只能應對一個欄位,我的資料量也不是很多 有時想要連 int 的欄位像是 student_id 也想要讓它也一併搜索一下 有誰知道這解法嗎?

自动调动在/etc/init.d 里加 欄位是啥么意思,字段?可以加很多欄位还可以加权重。


searchable(:ignore_attribute_changes_of=>ignored_index_attributes,
             :if => proc { |model|  !model.deleted_at  }) do
    text :name, :stored => true,:more_like_this=>true
    text :token_name do
      Topic.tokens(name)   
    end
    #text :content
    string :user_id
    time :created_at
  end


hits= Sunspot.search([Question,Topic,User]) do
      keywords params[:query] do
       # fields(:conent, :name => 2.0)
        boost_fields :name => 2.0
        query_phrase_slop 1
      end
      adjust_solr_params do |sunspot_params|
        sunspot_params[:start] = 0
        sunspot_params[:rows] = 9
      end
    end.hits

https://github.com/sunspot/sunspot

kehao 您好: 是的,欄位在內地稱之為字段。上面這兩段程式是寫在 Student 資料模型裏?全然不明白其作用 能請您解釋一下嗎?我的設置如下:

searchable do
    text :cname, :ename, :email, :student_id,:telephone, :mobile_phone, :parents_phone, :company_phone, :jobs, :session_description
  end

就是那個學生 id 是 int 字段長度 11.

另外您說把這 rake sunspot:solr:start 扔進 /etc/init.d 這部份好像要寫 shell script 吧?這我就不會了 orz

#2 楼 @idarfan 不一定要写 script 的。比如你编辑/etc/rc.local (ubuntu,每个 linux 都有这样一个文件,可能具体的名字有点变化,rc.start, rc.local),假定你的 rails app 的目录是 /webapps/myrailsapps, 在exit 0前加入 cd /webapps/myrailsapps; rake sunspot:solr:start

#2 楼 @idarfan id 需要搜索么,完全不需要吧。为啥要加那么多欄位,只要加你要搜索的字段。然后

Sunspot.search([Question,Topic,User]) do
#......
end.results




他会自动去数据库取一遍你要的 record,如果像上面一样用 hit 他就不会去数据库取,你仅能得到加了:stored => true 的字段的内容

#3 楼 @bwlinux 这头像哪看过,是啥么?

這頭像是佛教的護法明王,不動明王 右手持劍,劍名日智慧斬斷迷惘 左手持索綑縛心魔 五大明王之首,類似警察的地位

哈。看錯了 ..原來不是問我 抱歉

感謝 bwlinux 關於 script 部份我明白了

kehao 您好: 會想要加入搜尋學生欄位,是因為作業人員懶得再去點 search from。想說全文檢索都那麼便利了 我單位的學生數也不到 2 千人,就問了我把它塞進去成不成?反正筆數沒那麼多純然就是圖個方便就是了

kehao 您好:關於您上述的解說我還是難以理解,請問您這些資訊是去那看到的可否告之 我再去研讀一下,感謝

需要 登录 后方可回复, 如果你还没有账号请 注册新账号