搜索句子 [英] Search through sentences

查看:43
本文介绍了搜索句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 rails 应用程序并决定进行搜索.我有一个搜索文本字段,控制器负责一切.在我的搜索方法中

I have a rails app and have decided to have a search. I have a search textfield and the controller takes care of everything. In my search method

def self.search(search)
    if search
      str = []
      search.split.each do |s|
        a = find(:all, :conditions => ['title or content LIKE ?', "%#{s}%" ])
        str = (str + a).uniq
      end

    else
      find(:all)
    end
  end

我希望能够处理多个单词搜索.如果您删除 each...loop,它可以在 1 个单词搜索中正常工作.无论如何,我想为每个搜索到的词找到相关的帖子并返回一个组合.

I want to be able to handle multiple word searches. If you remove the each...loop it works fine with 1 word searches. Anyways, I would like to find the related posts for each word that is searched and return a combination of that.

例如.如果有人搜索最伟大的球员",它将返回标题或内容为最伟大"的帖子的所有实例以及任何标题或内容为球员"的帖子

Ex. If someone searches "Greatest Player" it will return all instances of posts that have the title or content "Greatest" and any that have the title or content "Player"

推荐答案

您很可能应该查看全文搜索:

You most likely should be looking at full text searching:

这篇关于搜索句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆