0
現在,我正在使用寶石https://github.com/seamusabshere/fuzzy_match,但在1個通話時間內只需要1個結果。我該如何獲得5個結果呢? 這是我的代碼:如何從模糊匹配寶石中獲得5個結果?
def related_ques
collect_ques = Question.joins(:question_topics)
.where("topic_id in (?) and questions.id != ?",self.topic_ids, self.id)
results = Array.new
Settings.question_page.num_related_ques.times do
fz = FuzzyMatch.new(collect_ques, read: :title)
question = fz.find(self.title)
results << question unless question.nil?
collect_ques = collect_ques.to_a - [question]
end
results
end
它的聲音很糟糕,現在我必須初始化模糊對象然後找到,然後從集合中取消創建的項並繼續用新集合初始化新的模糊對象。 @ _ @。它有任何選項可以得到5個結果。 –
你可以發佈你的代碼,以更好地瞭解它 – Pramod
是的,我已經編輯它。 –