使用Solr拼写检查器检测不存在的单词(Detecting nonexistent words with Solr spell checker)
为简单起见,我们假设我们的Solr索引包含单个词:
"test"
。我们的搜索查询是
"test someNonExistentWord"
。使用Solr的拼写检查器,我们将获得以下结果:
"response": { "numFound": 1, "start": 0, "docs": [ { ... } ] }, "spellcheck": { "suggestions": [ "correctlySpelled", true ] }
所以,我的问题是:如何知道查询中的一个单词实际上不存在?
当然,存在直截了当的方式 - 手动查询标记化,然后分别对每个单词进行搜索,但是有更好的解决方案吗?
For simplicity reasons we suppose that our Solr index contains single word:
"test"
.And our search query is
"test someNonExistentWord"
.Using Solr's spell checker we will get following result:
"response": { "numFound": 1, "start": 0, "docs": [ { ... } ] }, "spellcheck": { "suggestions": [ "correctlySpelled", true ] }
So, my question is: How to know that one of word within query is actually doesn't exists?
Sure, straightforward way exists - manual query tokenizing followed by serach for each word separately, but is there a better solution?
原文:https://stackoverflow.com/questions/21378404
最满意答案
查看数据库表我找到了解决方案:
首先,我们获取与已登录用户关联的employee_id
employee_id = {} cr.execute('SELECT hr.id \ FROM resource_resource AS res JOIN hr_employee AS hr \ ON res.id = hr.resource_id \ WHERE res.user_id = %s',[uid]) for res in cr.fetchall(): employee_id = res[0]
然后,我们得到employee_id的最后一个动作
last_action = {} cr.execute('SELECT hr_attendance.action \ FROM hr_attendance \ WHERE employee_id = %s',[employee_id]) for res in cr.fetchall(): last_action = res[0]
'last_action'现在有“sign_in”或“sign_out”(当前用户在考勤模块中完成的最后一个操作)
Looking the database tables I found the solution:
First we obtain the employee_id associated to the logged user
employee_id = {} cr.execute('SELECT hr.id \ FROM resource_resource AS res JOIN hr_employee AS hr \ ON res.id = hr.resource_id \ WHERE res.user_id = %s',[uid]) for res in cr.fetchall(): employee_id = res[0]
Then, we get the last action of the employee_id
last_action = {} cr.execute('SELECT hr_attendance.action \ FROM hr_attendance \ WHERE employee_id = %s',[employee_id]) for res in cr.fetchall(): last_action = res[0]
'last_action' has now "sign_in" or "sign_out" (The last action done by the current user in the attendance module)
相关问答
更多-
我想到了。 在我的@checkout表单对象中,当我调用@checkout.save时,我更新了guest_user的属性并保存它。 我认为设计必须登录guest_user的最新版本,所以我必须在sign_in(guest_user)之前添加guest_user.reload , 简而言之,在签user.reload之前重新加载用户( user.reload )。 I figured it out. In my @checkout form object, I update the guest_users ...
-
对动作应用自定义布局的另一种方法如下。 根据如何:创建自定义布局 “您还可以使用config / environment.rb(rails 2)或config / application.rb(rails 3)中的回调设置特定Devise控制器的布局,这需要在to_prepare回调,因为它在生产中执行一次,并且在每个开发中的请求之前执行。 config.to_prepare do Devise::SessionsController.layout "devise" Devise::Regi ...
-
没有路线匹配“/ users / sign_out”devise rails 3(No route matches “/users/sign_out” devise rails 3)[2023-09-25]
我认为退出的路由是DELETE方法。 这意味着您的登出链接需要如下所示: <%= link_to "Sign out", destroy_user_session_path, :method => :delete %> 你的不包括:method => :delete part。 另外,请注意,为了使其工作,您还必须在布局文件( application.html.erb )中包含<%= javascript_include_tag :defaults %> 。 I think the route for s ... -
Rails - 为什么在sign_in方法中使用self.current_user = user(Rails - Why use self.current_user = user in sign_in method)[2022-05-22]
你是对的,重定向后没有设置@current_user。 @current_user ||= User.find_by_remember_token(cookies[:remember_token]) 此语句有助于避免重复调用数据库,但仅在单个用户请求多次使用current_user变量时才有用。 因此,设置当前用户仅在单个呼叫期间有用。 同样,在sign_out期间将当前用户设置为nil并从cookie中删除令牌可确保后续处理将考虑签名。 否则,存在其他方法引用当前用户变量并认为用户仍然登录的风险。 Yo ... -
match "sign_in" => "sessions#new", :as => :new_session match "sign_in" => "sessions#new", :as => :new_session
-
Devise有文档向您展示如何在此处覆盖其默认重定向: https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in 基本上你会进入你的application_controller.rb,例如写这样的东西 def after_sign_in_path_for(resource) request.env['omniauth.origin'] || stored_l ...
-
根据你分享的内容跳出来的唯一的事情是,当我使用控制器规范中的Devise的sign_in帮助器时,我把它封装在一个before块(或大括号)中,类似于下面的和类似的到您在login_in模块中拥有的login_in 。 也许尝试摆脱(:each) 。 此外,您可以在您的login_user方法中使用login_user或byebug来查看当您运行控制器规格时是否login_user该方法。 let!(:user) { create(:user) } context 'user is logged in' ...
-
为什么错误“没有路由匹配[GET]”/ users / sign_out“?(Why the error “No route matches [GET] ”/users/sign_out"?)[2022-07-22]
尝试下面的内容 将下面的代码粘贴到您的routes.rb中 devise_scope :user do get 'users/sign_out' => "devise/sessions#destroy" end Try the below Paste the below code in your routes.rb devise_scope :user do get 'users/sign_out' => "devise/sessions#destroy" end -
查看数据库表我找到了解决方案: 首先,我们获取与已登录用户关联的employee_id employee_id = {} cr.execute('SELECT hr.id \ FROM resource_resource AS res JOIN hr_employee AS hr \ ON res.id = hr.resource_id \ WHERE res.user_id = %s',[uid]) for res in cr.fet ...
-
我喜欢做的一件事 /config/initializers/devise.rb是从config.sign_out_via = :delete更改为config.sign_out_via = [:delete, :get]所以你有两个方案覆盖删除方法没有命中。 打开您的控制台并确保jquery和jquery_ujs正确加载 让我与你分享我的设置 在我的资产application.js我有 #app/assets/javascripts/application.js //= require jquery //= ...