我正在尝试在Rails应用程序中使用pg_search根据用户的查询对零件列表进行排序。不过,我遇到了一些麻烦-升序搜索似乎无法获得正确的结果。
这是我的模特:
class Pcdb::Part < CatalogsRecord
include PgSearch
self.table_name = "parts"
belongs_to :parts_description
pg_search_scope :search_for_parts, against: :part_terminology_name,
using: { tsearch: { dictionary: "simple", prefix: true } }
end
在我的控制器中,我有以下代码:
Pcdb::Part.search_for_parts(query)
,其中query
参数是从用户输入的。
我尝试使用query.order("parts.part_terminology_name ASC")
无济于事。
现在,如果query
参数为“ Windshield Wiper”,这是我得到的结果:
Windshield Wiper Motor And Windshield Washer Pump Assembly
Windshield Wiper Motor Relay
Windshield Wiper Switch
Windshield Wiper Motor
Windshield Wiper Arm
Windshield Wiper Blade
Windshield Wiper Linkage
Windshield Wiper Linkage Pivot
Windshield Wiper Blade Refill
我实际上正在尝试达到这样的结果:
Windshield Wiper Arm
Windshield Wiper Blade
Windshield Wiper Blade Refill
Windshield Wiper Linkage
Windshield Wiper Linkage Pivot
Windshield Wiper Motor
Windshield Wiper Motor And Windshield Washer Pump Assembly
Windshield Wiper Motor Relay
Windshield Wiper Switch
我很高兴能朝正确的方向指出!
尝试使用reorder
代替order
。 reorder
将删除其他地方定义的任何其他顺序,以防万一。