簡體   English   中英

如何使用Sequel full_text_search對超過一個詞的短語進行全文搜索?

[英]How can I do a full text search with a phrase of more than one word, using Sequel full_text_search?

我正在使用ruby,Sequel和postgres。 我已經實現了全文搜索,如下所示:

get '/full_text_search' do
search_term = params[:search_term] 

result = DB[:candidates].full_text_search(:experience, search_term).map do |row|
 { :id => row[:id], :first => row[:first], :last => row[:last], :designation => row[:designation], :company => row[:company], :email => row[:email], :phone => row[:phone], :city => row[:city], :country => row[:country], :industry => row[:industry], :status => row[:status], :remarks => row[:remarks], :experience => row[:experience] }
    end
  halt 200, result.to_json
end

這是通過通過ajax調用從文本框中傳遞搜索詞來執行的,因此:

$(document).ready(function(){
$("#full_text_search").click(function(){ 
var search_term = $("#search_box").val();
    $.getJSON("/full_text_search?search_term="+search_term, function(data) {
        $.each( data, function( key, value ) {  
        //do something with returned data here
         });//end each
          });//end getJSON
     });//end click
});//end doc

如果我的搜索詞只是一個詞,例如“ private”,那么我沒有問題,但是如果我嘗試使用2個詞(或更多)的搜索詞“ private Equity”,我得到了一個錯誤,而沒有數據返回。

所以我的問題是如何用兩個或更多單詞組成的短語執行全文搜索(如上所述)?

我已經嘗試用''和“”封裝傳遞的參數,但未成功。

感謝所有的幫助。 謝謝。

PostgreSQL的全文本搜索不能本地處理短語搜索。 最好的辦法是使用&查找包含兩個單詞的條目,使用&full_text_search(:experience, 'term1 & term2') ,然后如果要進行實際的短語搜索,則使用LIKE '%term1 term2%'

我將研究在full_text_search中添加:phrase=>true選項,以使其用作短語搜索。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM