から予期しない結果をもたらすスフィンクス範囲を考える:私はsphinx_scopeに複製しようとしていますアクティブなレコードの範囲を持っている範囲の入力
scope :active, -> (date) { where("DATE(?) BETWEEN active_date AND hide_date-1 ", date) } # between is inclusive
誰かがより良い私を見ることができない限り、これは、政府の仕事のために十分に近いですアプローチ:
sphinx_scope(:search_active) { |today|
{:with => {:active_date => 100.years.ago.to_i..today.to_s.to_time.to_i, :hide_date => today.to_s.to_time.to_i..100.years.from_now.to_i}
}
(はい、today.to_s.to_time.to_iは少し厄介です...)
私の問題は、結果が正確であると思われないということです。たとえば、スコープのないクエリが
sphinxQL> SELECT weight(),* FROM `standard_core` WHERE MATCH('1910.15') AND `sphinx_deleted` = 0 LIMIT 0, 10 OPTION field_weights=(section_number=2);
+----------+------+----------------+--------------------+-------------+-----------+------------+------------+-----------------------+-----------------------------------------------------------------------------------+---------------------+
| weight() | id | sphinx_deleted | sphinx_internal_id | active_date | hide_date | created_at | updated_at | sphinx_internal_class | title_sort | section_number_sort |
+----------+------+----------------+--------------------+-------------+-----------+------------+------------+-----------------------+-----------------------------------------------------------------------------------+---------------------+
| 8557 | 3633 | 0 | 908 | 1436936400 | 297642704 | 1451164539 | 1451164539 | Standard | § 1910.15 Shipyard employment. | 1910.15 |
| 6549 | 3637 | 0 | 909 | 1436936400 | 297642704 | 1451164539 | 1451164539 | Standard | § 1910.15(a) Adoption and extension of established safety and health... | 1910.15(a) |
| 6549 | 3641 | 0 | 910 | 1436936400 | 297642704 | 1451164539 | 1451164539 | Standard | § 1910.15(b) Definitions. For purposes of this section: | 1910.15(b) |
を生み出すしかしスコープで、最も関連性の高い結果が不足している:
sphinxQL> SELECT weight() as weight,* FROM `standard_core` WHERE MATCH('1910.15') AND `active_date` BETWEEN -1672108252 AND 1482127200 AND `hide_date` BETWEEN 1482127200 AND 4639325348 AND `sphinx_deleted` = 0 ORDER BY weight DESC LIMIT 0, 10 OPTION field_weights=(section_number=2);
+--------+------+----------------+--------------------+-------------+------------+------------+------------+-----------------------+-----------------------------------------------------------------------------------+---------------------+
| weight | id | sphinx_deleted | sphinx_internal_id | active_date | hide_date | created_at | updated_at | sphinx_internal_class | title_sort | section_number_sort |
+--------+------+----------------+--------------------+-------------+------------+------------+------------+-----------------------+-----------------------------------------------------------------------------------+---------------------+
| 4566 | 5469 | 0 | 1367 | 1436936400 | 1484632800 | 1451167759 | 1451167759 | Standard | § 1910.27(d)(1)(vi) Ladder wells shall have a clear width of at least 15... | 1910.27(d)(1)(vi) |
| 4549 | 5413 | 0 | 1353 | 1436936400 | 1484632800 | 1451167757 | 1451167757 | Standard | § 1910.27(c)(2) Ladders without cages or wells. A clear width of at least 15... | 1910.27(c)(2) |
| 4549 | 5453 | 0 | 1363 | 1436936400 | 1484632800 | 1451167758 | 1451167758 | Standard | § 1910.27(d)(1)(ii) Cages or wells (except as provided in subparagraph (5) of... | 1910.27(d)(1)(ii) |
を私はむしろ、これは実際に考えてスフィンクス誤りであると思いますが、しないでくださいスフィンクス自体のものまたは、おそらく...私が誤解しているもの:
ここで何が起こっているのか誰かが分かりますか?
[編集] ------------------------------------------- --------------
@DGMでは、hide_dateの値がsphinxデータベースレコードで正しくないことがわかりました。レコードID 3633の場合、mysqlデータベースレコード908は、日付値が2115-07-15です。
'2115-07-15'.to_time.to_i
=> 4592610000
明らかに、297642704
と4592610000
の間の不一致のビットがあります。
私は範囲を誤って計算しているか、またはスフィンクスデータベースにエラーが発生しています。
インデックス/ standard_index.rb
ThinkingSphinx::Index.define :standard, :with => :real_time do
# fields
indexes title, :sortable => true
indexes content
indexes section_number, :sortable => true
# attributes
has active_date, :type => :timestamp
has hide_date, :type => :timestamp
has created_at, :type => :timestamp
has updated_at, :type => :timestamp
end
するMySQL日付フィールドとスフィンクスのタイムスタンプの間の変換では、この負け何か?
すてきな回避策!そうすれば**トラブルシューティングがもっと簡単になります**。私はmysqlの 'date'フィールドを使用していますが、モデルの文字列でなければなりません。ほとんどのフォーマットでは失敗するため、並べ替えのための文字列として日付を使用しないようにしようとしているので、むしろ面白いです...しかし、それはこの場合の解決策の一部です。 –
RailsとTS/Riddleの両方でDateインスタンスとして処理する必要があることは、正直言ってどこかの文字列として扱われることに少し驚いています。それでも、これは今のことが期待どおりに機能しているのでしょうか? – pat
整数に変換すると、期待どおりに動作し、わかりやすくなります。 win-win。何が嫌なのか分かりませんが、これはうまくいきます:) –