Thinking sphinx sorting on multiple fields
I am searching for the model Projects. Projects belongs_to Companies, so all Projects in the list can have the same Company attached to it. An example of a result list:
CompanyA - ProjectA
CompanyA - ProjectO
CompanyA - ProjectC
CompanyA - ProjectB
CompanyB - ProjectU
CompanyB - ProjectI
I can sort on Project name, but then the Company name column can be random like above. I would like to sort this column as secondary field. Can this be done? I have read that Sphinx is converting the fields sorting to an id, probably to save memory, b开发者_运维知识库ut this can't possibly limit the sorting in this way?
You can use SPH_SORT_EXTENDED mode for this:
$sph->SetSortMode(SPH_SORT_EXTENDED, "Project ASC, Company ASC");
(sort mode docs)
Edit: above example is PHP but it appears that Thinking Sphinx exposes the feature similarly:
Article.search "term", :sort_mode => :extended,
:order => "Project ASC, Company ASC"
精彩评论