Closed Bug 1091643 Opened 10 years ago Closed 9 years ago

Switch bugscache queries from full-text search to LIKE


(Tree Management :: Treeherder, defect, P1)



(Not tracked)



(Reporter: emorley, Assigned: emorley)




(1 file, 1 obsolete file)

54 bytes, text/x-github-pull-request
: review+
Details | Review
In bug 1057359, it was found that for the failures in bug 1078237 (and likely some of the other missing suggestions issues covered in the dependent bugs), the correct search term was being used (compared to TBPL), however the bugscache API was returning zero results.

For example...

Cleaned error line:
TEST-UNEXPECTED-FAIL | TestSwitchFrame.test_should_be_able_to_carry_on_working_if_the_frame_is_deleted_from_under_us | AssertionError: 0 != 1

Extracted test name (after 100 char truncation): TestSwitchFrame.test_should_be_able_to_carry_on_working_if_the_frame_is_deleted

Search: TestSwitchFrame.test_should_be_able_to_carry_on_working_if_the_frame_is_deleted

I believe this to be since we've truncated the test name after the word "deleted", whereas the bug summary in the DB is: 
Intermittent TestSwitchFrame.test_should_be_able_to_carry_on_working_if_the_frame_is_deleted_from_under_us | AssertionError: 0 != 1

...and thus means the fulltext search doesn't find a match.

I also believe that the fulltext search stopwords are meddling with results in other cases too.

tl;dr: I believe we should be using LIKE rather than fulltext search (at least for the WHERE clause, having a relevance score returned is still useful).
Summary: Switch bugscache queries from fulltext search to LIKE → Switch bugscache queries from full-text search to LIKE
Attached file WIP (obsolete) —
This WIP doesn't work and I'm having trouble figuring out if I should be doing something differently, or if it's a bug in datasource.

The current patch fails with:
ValueError: unsupported format character ''' (0x27) at index 327

And using "%%" instead of "%" returns no matches.

Any ideas? (Travis run at )
Attachment #8514308 - Flags: feedback?(mdoglio)
(In reply to Ed Morley [:edmorley] from comment #1)
> And using "%%" instead of "%" returns no matches.

(Slightly clearer:)
And whilst using "%%" instead of "%" fixes the exception, it returns no bug matches for any of the search terms, including the previously passing ones.
Attachment #8514308 - Attachment mime type: text/plain → text/x-github-pull-request
Did you try to pass "%yourstring%" as a placeholder?
Attached file Final PR
(I pasted the wrong URL)

Travis run with '%':

Travis run with '%%':
Attachment #8514326 - Flags: feedback?(mdoglio)
Attachment #8514308 - Attachment is obsolete: true
Attachment #8514308 - Flags: feedback?(mdoglio)
(Sorry our messages passed each other)

AND `summary` LIKE `%test%`

ValueError: unsupported format character 't' (0x74) at index 319

AND `summary` LIKE `%%test%%`

TypeError: not all arguments converted during string formatting
Blocks: 1072377
Comment on attachment 8514326 [details] [review]
Final PR

So this works now :-)

Few notes:
1) This switches from full-text search to LIKE for the WHERE clause, so we get exact-substring behaviour, even for search terms that were truncated (this still isn't the exact same means of searching as happens with TBPL's use of Bugzilla quicksearch, but it's more predictable, so I think we should just use it).
2) When using LIKE, we need to perform escaping of the search term, otherwise it won't be treated literally. I couldn't find any better way of performing it other than manually.
3) Adds tests for the failing case in comment 0 & also the escaping of the search term. I think we'll need to overhaul the way we do these tests soon, but punting for another bug, since this issue is causing the sheriffs day to day pain.
Attachment #8514326 - Attachment description: WIP → Final PR
Attachment #8514326 - Flags: feedback?(mdoglio) → review?(mdoglio)
Attachment #8514326 - Flags: review?(mdoglio) → review+
Commits pushed to master at
Bug 1091643 - Switch bugscache queries from full-text search to LIKE

Since full-text searches miss cases where the search term was truncated,
but is still a substring of the bug summary.

When using LIKE, any underscores or percent signs will be treated as
wildcards, so we need to escape them, as well as the escape symbol
itself, so the search term is handled literally. A custom escape
symbol is used since the default of backslash leads to less readable
code, given it has to be double escaped.
Bug 1091643 - Add test for truncated test name bug searches
Bug 1091643 - Add tests for SQL LIKE escaping of search_term

Test that we are treating the search term literally in the LIKE
statement, and so have correctly escaped any underscores, percent signs
or escape symbols.
Closed: 9 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.