Search code examples
rubythinking-sphinx

Intersect thinking sphinx results


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.


Solution

  • 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?