在 Cucumber 功能中使用 ThinkingSphinx 进行搜索不会返回任何结果

发布于 2024-10-06 15:15:35 字数 1282 浏览 0 评论 0原文

我正在尝试运行一个进行搜索的功能。我添加了 ThinkingSphinx 文档建议的必要行

require 'cucumber/thinking_sphinx/external_world'
Cucumber::ThinkingSphinx::ExternalWorld.new

,并且还禁用了事务并使用 DatabaseCleaners 截断。我已经设置了功能,因此在添加用户后,我会更新 Sphinx 的索引,然后进行搜索。

Scenario: Add a client to a project
    Given I have a project named "ProjectXYZ"
    And I have a client named "Tom Client" with an email address "[email protected]"
    And the Sphinx indexes are updated
    And if I search for "Tom" which is a "Client", I have 1 result

即使用户在那里,搜索也始终返回 0 个结果。如果我检查 User.find_by_first_name("Tom").count.should eq(1) 的计数,它会成功。

以下是我的步骤:

更新索引

Given 'the Sphinx indexes are updated' do
    # Update all indexes
    ThinkingSphinx::Test.index
    sleep(1.0) # Wait for Sphinx to catch up
end

搜索和检查结果

Given /^if I search for "([^"]*)" which is a "([^"]*)", I have (\d+) results?$/ do |query,model,count|
    Rails.const_get(model).search_count(query).should == count.to_i
end

我正在使用 Rails 3.0.3、Cucumber 0.9.4 和 Cucumber-Rails 0.3.2

I am trying to run a feature where a search occurs. I added the necessary lines that the ThinkingSphinx documentation recommends

require 'cucumber/thinking_sphinx/external_world'
Cucumber::ThinkingSphinx::ExternalWorld.new

And also disabled using transactions and use DatabaseCleaners truncation instead. I have my feature setup so after I add a user, I update the index for Sphinx, and then I do a search.

Scenario: Add a client to a project
    Given I have a project named "ProjectXYZ"
    And I have a client named "Tom Client" with an email address "[email protected]"
    And the Sphinx indexes are updated
    And if I search for "Tom" which is a "Client", I have 1 result

The search always returns 0 results, even though the user is there. If I check the count for User.find_by_first_name("Tom").count.should eq(1) it succeeds.

Here are my steps:

Updating Index

Given 'the Sphinx indexes are updated' do
    # Update all indexes
    ThinkingSphinx::Test.index
    sleep(1.0) # Wait for Sphinx to catch up
end

Searching and checking results

Given /^if I search for "([^"]*)" which is a "([^"]*)", I have (\d+) results?$/ do |query,model,count|
    Rails.const_get(model).search_count(query).should == count.to_i
end

I am using Rails 3.0.3, Cucumber 0.9.4, and Cucumber-Rails 0.3.2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘逸的'云 2024-10-13 15:15:35

到目前为止,似乎没有什么不合适的地方......如果你还没有,我建议使用 我的博客文章 而不是官方文档作为参考(后者需要更新)。

另外:您是否有使用不同端口的测试/黄瓜环境Sphinx 适合您的开发设置吗?尽管如果 Sphinx 没有在开发环境中运行,那么这应该不会妨碍。

Nothing seems out of place thus far... in case you're not already, I would recommend using my blog post instead of the official docs as a reference (the latter need updating).

Also: do you have the test/cucumber environment using a different port for Sphinx to your development setup? Although if Sphinx isn't running in dev, then that shouldn't get in the way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文