Optimize and fix the Sphinx indexes SQL query.

By taking advantage of cross-linking, we can get both direct and indirect
translations using a single query. We start by querying indirects ones,
and if an indirect one equals the original one, it means we got back to
the starting point, and in this case we keep the direct translation instead.

The only downside of this approach is that it doesn’t work when two
sentences aren’t cross-linked. There are currenly only five such broken
links on the production server, visible by running the follwing query:

select s.sentence_id, s.translation_id
from sentences_translations as s
left join sentences_translations s2
on s.translation_id = s2.sentence_id
and s.sentence_id = s2.translation_id
where s2.sentence_id is NULL;

Some quick comparison of the data returned by this new query shows that
it’s is more accurate. The previous one happened to return the original
sentence language as a translation language from time to time, whereas this
query doesn’t. This problem was visible when running a search with the same
source language as the target one, and a keyword of that language.

  http://tatoeba.org/sentences/search?query=fish&from=eng&to=eng

Such a query returned many English sentences without any translation,
whereas it should only return English sentences translated into English.
So this commit fixes that too.

Some benchmarks.

Running the query to generate indexes for Turkish sentences (about 200k)
on the production server. That’s about 60% faster and uses less memory.

           before      after

          0:54.25    0:33.74
time to   0:54.85    0:40.27
run the   0:59.39    0:33.71
query     0:56.75    0:31.87
          0:54.51    0:35.62

Maximum
resident   213 ko     182 ko
set size