[2201] Search Result Links are Wrong

Started by Spuds, July 06, 2010, 08:30:23 AM

Previous topic - Next topic

Spuds

2.0RC3, large custom index

When doing a search with "show results as messages" set the results page has several (not all) invalid links in the results titles where the topic id is set the same as the message id (ie index.php?topic=21867.msg21867;topicseen#msg21867) which when clicked results in a The topic or board you are looking for appears to be either missing or off limits to you.

This is with the fix installed as mentioned here: http://dev.simplemachines.org/mantis/view.php?id=2201

Nao 尚

I confirm I can reproduce... I'll try to fix it immediately.
I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.


Nao 尚

Found the culprit... In Search.php, this line:

$main_query['select']['id_topic'] = 'm.id_msg AS id_topic';

It basically tells SMF to take the message ID and consider it as the topic ID.
It's even preceeded by a 'It's outrageous!' comment... I don't know *why* it's being done, though.
I'll still look into it a bit.

PS: apparently, this is also in SMF 1...

$main_query['select']['ID_TOPIC'] = 'm.ID_MSG AS ID_TOPIC';
I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

Nao 尚

That particular line was added in SMF 1.1 RC2 (it wasn't in RC1, I checked all versions.)
I'll compare the versions and try to find what was the whole point of getting the id_msg in place of id_topic.

It's obviously a hack, so it'd be best to fix it. If it can't be done easily, I'll just make sure to retrieve both the id_msg and the id_topic, and then I'll deal with id_topic separately. Or, I could simply check that id_topic is the same as id_msg, and if it's the case, point to "index.php?msg=1234", which will redirect it properly (too bad this feature isn't used enough IMHO.)
I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

Nao 尚

I really don't see the point in that change... And it's Cinderella time for me so I'll have to wait until tomorrow to look further into it.

Here's the query that generates the strange result:

            INSERT IGNORE INTO smf_log_search_results
                     (id_search, relevance, id_topic, id_msg, num_matches)
                  SELECT
                     55,
                     1000 * (25 * ((m.id_msg - t.id_first_msg) / CASE WHEN t.id_last_msg = t.id_first_msg THEN 1 ELSE t.id_last_msg - t.id_first_msg END) + 10 * CASE WHEN m.id_msg = t.id_first_msg THEN 1 ELSE 0 END + 15 * CASE WHEN MAX(lst.id_topic) IS NULL THEN 0 ELSE 1 END) / 50 AS relevance,
                     m.id_msg AS id_topic,
                     m.id_msg,
                     1 AS num_matches
                  FROM smf_topics AS t
                     INNER JOIN smf_messages AS m ON (m.id_topic = t.id_topic)
                     INNER JOIN smf_members AS bud ON bud.id_member = GREATEST(1, t.id_member_started)
                     LEFT JOIN smf_tmp_log_search_topics AS lst ON (lst.id_topic = t.id_topic)
                  WHERE m.body LIKE '%test%'
                  GROUP BY m.id_msg
                           ORDER BY null
LIMIT 6000


As you can see, "m.id_msg AS id_topic" is a problem here. I don't know why lsr.id_topic is supposed to hold an id_msg instead of an id_topic.
If someone else wants to look into it... Be my guest! Search.php is really not my specialty.
I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

Nao 尚

#6
Okay, last post and I'm gone...

My temp fix works. I don't know if it's the hackiest or least hacky way of fixing it though.

In Search template:

<h5>', $topic['board']['link'], ' / <a href="', $scripturl, '?topic=', $topic['id'], '.', $message['start'], ';topicseen#msg', $message['id'], '">', $message['subject_highlighted'], '</a></h5>

Replace with:

<h5>', $topic['board']['link'], ' / <a href="', $scripturl, $topic['id'] == $message['id'] ? '?msg=' . $message['id'] : '?topic=' . $topic['id'] . '.' . $message['start'] . ';topicseen#msg' . $message['id'], '">', $message['subject_highlighted'], '</a></h5>
I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

Nao 尚

No problem... It's not a beautiful trick, though. I have yet to understand what all of that code means. Ain't got much time today.
I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

kat


Nao 尚

(Fixed in a cleaner way in the latest revisions, BTW.)
I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

live627

Since this bug has been fixed, can someone please move this topic to Fixed Bugs?

Acans

Quote from: live627 on July 13, 2010, 06:46:04 PM
Since this bug has been fixed, can someone please move this topic to Fixed Bugs?

Only happy too.

Just checked the report myself, good job Nao :)
"The Book of Arantor, 17:3-5
  And I said unto him, thy database query shalt always be sent by the messenger of $smcFunc
  And $smcFunc shall protect you against injections and evil
  And so it came to pass that mysql_query was declared deprecated and even though he says he is not
  dead yet, the time was soon to come to pass when mysql_query shall be gone and no more

Nao 尚

I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

Duya

Erm, folks, is this fixed or what? 'Cause I can reproduce it on my forum running SMF 2.0.6. Go to:

forum.srpskijezickiatelje.com/index.php?action=search

and type "Puymorens" (without quotes) in the search box. You get two hits (=threads) where it was mentioned.

Now, click on "Show results as messages" (first check box), which is not supposed to alter the number of hits, right, and you get proper 11 hits.

Advertisement: