Mattermost-server: Search terms with underscore using PostgreSQL engine should work

Created on 30 Apr 2020  Â·  8Comments  Â·  Source: mattermost/mattermost-server

Right we’re using to_tsquery in the Postgresql search but when the word has underscore is returning more results than it should.

The problem is that to_tsquery for a word with an underscore is splitting that word into multiple parts:

mattermost_test=# select to_tsquery('english', '("test_with_underscore")');
      to_tsquery      
----------------------
 'test' & 'underscor'
(1 row)

Using for example something like:

mattermost*test=# select $$test_with*underscore$$::tsquery;
        tsquery         
~~----------------------~~
 'test_with_underscore'
(1 row)

could work but we are losing the dictionary option (the ‘English’ part in to_tsquery)


If you're interested please comment here and come join our "Contributors" community channel on our daily build server, where you can discuss questions with community members and the Mattermost core team. For technical advice or questions, please join our "Developers" community channel.

New contributors, please see our Developer's Guide.

JIRA: https://mattermost.atlassian.net/browse/MM-24530

AreDB Hard Help Wanted TecGo

Most helpful comment

I can take this one!

All 8 comments

I can take this one!

Would you please elaborate on "when the word has underscore is returning more results than it should" @amyblais ?

@ethervoid ^

@ethervoid what do you think about replacing this line with:
searchClause := fmt.Sprintf("AND to_tsvector('english', replace(%s, '_', '/')) @@ to_tsquery('english', replace(:Terms, '_', '/'))", searchType)

I've tested it out and it works, but not sure if I'm missing something...

@fedealconada Could you please share here what kind of tests are you doing? I'm asking for this because what we want to achieve is to search for terms with underscores but the way we're creating the index is storing those terms splitted

@fedealconada Are you still interested in this issue? I not we can let another user work on it ;)

This issue appears stale and I’m adding the Up For Grabs label. If work is ongoing, please remove the label. If there is an existing PR, please also link it to the issue. Thanks!

@amyblais I would love to give it a shot.

Was this page helpful?
0 / 5 - 0 ratings