I am using Thinking Sphinx with rails 5.2.2. I need to give preference to data of one index than the other, while searching through multiple indices, in the final output.
For example I have an index index1 with an attribute attr = foo and an other index index2 with an attribute attr = foo. What I want is, ThinkingSphinx.search should always return data from index2 if attr matches foo(or some other value). If there is no record with attr matching foo in index2 records from index1 should be returned.
Note: I need to group the result on attr
Here is an example of a query I am using.
ThinkingSphinx.search("@attr =foo|foo*", group_by: :attr, middleware: ThinkingSphinx::Middlewares::RAW_ONLY, indices: ['index1', 'index2'])
According to this documentation(Searching Multiple Indexes) data from later index (index2 in this case) should be returned. But some records are being returned from index1 and some are being returned from index2.
Sphinx doesn't have a direct concept of prioritising one index over another, but you could add an attribute to each model to indicate importance, and then sort by that?
In the index definition:
And then searching: