This is an automated email from the git hooks/post-receive script. New commit to branch bow-v2-go in repository bow. See https://gitlab.nuiton.org/chorem/bow.git commit e434b91be719efe19469f6aa3d7d587aaefac2a4 Author: Benjamin <poussin@codelutin.com> Date: Thu May 28 02:48:28 2020 +0200 correction pour que le highlight prenne l'ensemble du text --- pkg/repository/bookmarkRepository.go | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/pkg/repository/bookmarkRepository.go b/pkg/repository/bookmarkRepository.go index d212e91..624dd3c 100644 --- a/pkg/repository/bookmarkRepository.go +++ b/pkg/repository/bookmarkRepository.go @@ -39,6 +39,8 @@ func BookmarkJSON(currentUser model.BowUser, id string, uri string, tags []strin orderDirection = "desc" } + tagsJoined := strings.Join(tags, ",") + log.Printf("search bookmark id: %v, uri: %v, tags: '%v', fulltext: '%v', orderBy: %v, orderAsc: %v, first:%v", id, uri, tags, fulltext, orderBy, orderAsc, first) var mainQuery string if id != "" { @@ -48,18 +50,29 @@ func BookmarkJSON(currentUser model.BowUser, id string, uri string, tags []strin } else { // si fulltext and vide, aucun resultat n'est retourne, ce n'est pas ce qu'on veut // dans ce cas, on souhaite que la recherche ne porte que sur les tags - var queryEmptyFulltext string - // highlighted description => hldescription - var hl string - if (fulltext == "") { + queryEmptyFulltext := "" + if fulltext == "" { queryEmptyFulltext = "true OR " - hl = "" - } else { - queryEmptyFulltext = "" - hl = `, - ts_headline(description, websearch_to_tsquery($2)) AS hldescription, - ts_headline(text(tags), websearch_to_tsquery($2))::text[] AS hltags` } + + // highlighted description => hldescription + hl := "" + // il faut que fulltext ou tags soit non vide pour mettre en highlighted les tags + hitags := make([]string, 0, 2) + if fulltext != "" { + hl = `, ts_headline(description, websearch_to_tsquery($2), 'HighlightAll=true') AS hldescription` + hitags = append(hitags, `websearch_to_tsquery($2)`) + } + + if tagsJoined != "" { + hitags = append(hitags, `plainto_tsquery($1)`) + } + + hitagsJoined := strings.Join(hitags, " || ") + if hitagsJoined != "" { + hl = fmt.Sprintf(`%s, string_to_array(ts_headline(array_to_string(tags, ','), %s, 'HighlightAll=true'), ',') AS hltags`, hl, hitagsJoined) + } + // vu qu'on veut utiliser l'index fulltext créer, il faut les meme champs dans la requete (to_tsvector) mainQuery = fmt.Sprintf(`select *%s @@ -70,7 +83,6 @@ func BookmarkJSON(currentUser model.BowUser, id string, uri string, tags []strin `, hl, queryEmptyFulltext) } - tagsJoined := strings.Join(tags, ",") q := &query{sql: fmt.Sprintf(`WITH __query AS (%[5]s), __info AS (select %[3]d as first, %[4]d as limit, count(id) as total, '%[1]s' as orderby, to_json('%[2]s' <> 'desc') as orderasc, string_to_array($1, ',') as tags, $2::TEXT as fulltext, $3::TEXT as uri, $4::TEXT as id from __query), -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.