Skip to content

Commit b89c5e4

Browse files
committed
Fix custdb-813
1 parent 47dc1f2 commit b89c5e4

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

controller/search.php

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -592,32 +592,39 @@ protected function query_index()
592592

593593
$this->sort->total = $results['total'];
594594

595+
// https://tracker.phpbb.com/projects/CUSTDB/issues/CUSTDB-813
596+
// In Sphinx context ids are incremented with a specific value:
597+
// 20000000 for posts
598+
// 10000000 for FAQ
599+
600+
$is_sphinx = $this->engine->get_name() === 'phpbb.titania.search.driver.fulltext_sphinx';
601+
595602
foreach ($results['documents'] as $data)
596603
{
597604
switch ($data['type'])
598605
{
599606
case ext::TITANIA_CONTRIB:
600607
$contribs[] = $data['id'];
601-
break;
608+
break;
602609

603610
case ext::TITANIA_SUPPORT:
604611
case ext::TITANIA_QUEUE_DISCUSSION:
605612
case ext::TITANIA_QUEUE :
606-
$posts[] = $data['id'];
607-
break;
613+
$posts[] = $is_sphinx ? $data['id'] - 20000000 : $data['id'];
614+
break;
608615

609616
case ext::TITANIA_FAQ:
610-
$faqs[] = $data['id'];
611-
break;
617+
$faqs[] = $is_sphinx ? $data['id'] - 10000000 : $data['id'];
618+
break;
612619
}
613620
}
614621

615622
// Get additional data not included in result.
616623
if ($results['documents'])
617624
{
618625
$results['documents'] = $this->get_contribs($contribs, $results['documents']);
619-
$results['documents'] = $this->get_posts($posts, $results['documents']);
620-
$results['documents'] = $this->get_faqs($faqs, $results['documents']);
626+
$results['documents'] = $this->get_posts($posts, $results['documents'], $is_sphinx);
627+
$results['documents'] = $this->get_faqs($faqs, $results['documents'], $is_sphinx);
621628
}
622629
return $results;
623630
}
@@ -627,9 +634,10 @@ protected function query_index()
627634
*
628635
* @param array $ids
629636
* @param array $documents
637+
* @param bool $is_sphinx
630638
* @return array
631639
*/
632-
protected function get_posts(array $ids, array $documents)
640+
protected function get_posts(array $ids, array $documents, bool $is_sphinx)
633641
{
634642
if (!$ids)
635643
{
@@ -645,11 +653,11 @@ protected function get_posts(array $ids, array $documents)
645653

646654
while ($row = $this->db->sql_fetchrow($result))
647655
{
648-
$id = $row['post_type'] . '_' . $row['id'];
656+
$id = $row['post_type'] . '_' . ($is_sphinx ? $row['id'] + 20000000 : $row['id']);
649657
$row['url'] = serialize(array_merge(unserialize($row['url']), array(
650-
'topic_id' => $row['topic_id'],
651-
'p' => $row['id'],
652-
'#' => 'p' . $row['id'],
658+
'topic_id' => $row['topic_id'],
659+
'p' => $row['id'],
660+
'#' => 'p' . $row['id'],
653661
)));
654662
$documents[$id] = array_merge($documents[$id], $row);
655663
}
@@ -698,9 +706,10 @@ protected function get_contribs(array $ids, array $documents)
698706
*
699707
* @param array $ids
700708
* @param array $documents
709+
* @param bool $is_sphinx
701710
* @return array
702711
*/
703-
protected function get_faqs(array $ids, array $documents)
712+
protected function get_faqs(array $ids, array $documents, bool $is_sphinx)
704713
{
705714
if (!$ids)
706715
{
@@ -718,11 +727,11 @@ protected function get_faqs(array $ids, array $documents)
718727

719728
while ($row = $this->db->sql_fetchrow($result))
720729
{
721-
$id = ext::TITANIA_FAQ . '_' . $row['id'];
730+
$id = ext::TITANIA_FAQ . '_' . ($is_sphinx ? $row['id'] + 10000000 : $row['id']);
722731
$row['url'] = serialize(array(
723-
'contrib_type' => $this->types->get($row['contrib_type'])->url,
724-
'contrib' => $row['contrib_name_clean'],
725-
'id' => $row['id'],
732+
'contrib_type' => $this->types->get($row['contrib_type'])->url,
733+
'contrib' => $row['contrib_name_clean'],
734+
'id' => $row['id'],
726735
));
727736
$documents[$id] = array_merge($documents[$id], $row);
728737
}

0 commit comments

Comments
 (0)