0

Is it possible to intersect two ThinkingSphinx results?

For example, I have the results of two queries with the same object types: result_1 = [A1, A2] and result_2 = [A2, A3]. How can I get the intersection result_1 & result_2 (which should be [A2]), as I can with regular ruby arrays?

I'm using Thinking Sphinx version 3.0.6.

Thanks.

Jonathan
  • 7,349
  • 5
  • 29
  • 35

1 Answers1

1

If you want to combine the raw arrays from two searches, you can do this using the to_a method:

result_1.to_a & result_2.to_a

The catch here, though, is you lose all pagination information, and the ordering of results may not be ideal. Is there a reason why you can't run a single query that gets the combined results?

pat
  • 16,116
  • 5
  • 40
  • 46
  • Yes, I have the same problem as in question http://stackoverflow.com/questions/8824767/searching-multiple-polymorphic-items-using-thinking-sphinx. My idea is to get all the key-value pairs, then find all the attachments with those pairs, and then intersect all those results. – Jonathan May 19 '15 at 05:05
  • It's actually the same problem as this question of mine: http://stackoverflow.com/q/30287788/1772 – Jonathan May 19 '15 at 05:33