branch bow-v2-go updated (578fd07 -> ec307ef)
This is an automated email from the git hooks/post-receive script. New change to branch bow-v2-go in repository bow. See https://gitlab.nuiton.org/chorem/bow.git from 578fd07 ajout des highlighted sur la description et les tags pour expliquer la presence du bookmark dans les resultats new e434b91 correction pour que le highlight prenne l'ensemble du text new ec307ef correction index fulltext The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit ec307efcc9957ceef37c274ff6b9bc1124aac3f7 Author: Benjamin <poussin@codelutin.com> Date: Thu May 28 03:06:27 2020 +0200 correction index fulltext 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 Summary of changes: migrate/001_init_schema.sql | 2 +- pkg/repository/bookmarkRepository.go | 36 ++++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 13 deletions(-) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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>.
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 ec307efcc9957ceef37c274ff6b9bc1124aac3f7 Author: Benjamin <poussin@codelutin.com> Date: Thu May 28 03:06:27 2020 +0200 correction index fulltext --- migrate/001_init_schema.sql | 2 +- pkg/repository/bookmarkRepository.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/migrate/001_init_schema.sql b/migrate/001_init_schema.sql index 8585d8c..0d1b79d 100644 --- a/migrate/001_init_schema.sql +++ b/migrate/001_init_schema.sql @@ -103,7 +103,7 @@ CREATE INDEX bookmark_description_idx ON bookmark USING GIN (to_tsvector(lang, d CREATE INDEX bookmark_privateAlias_idx ON bookmark USING gin (privateAlias); CREATE INDEX bookmark_privateAlias_like_idx ON bookmark USING gin (text(privateAlias) gin_trgm_ops); -- index pour la recherche via ilike "%toto%" CREATE INDEX bookmark_publicAlias_idx ON bookmark USING gin (publicAlias); -- TODO garantir l'unicité -CREATE INDEX bookmark_all_ft_idx ON bookmark USING GIN(to_tsvector(lang, text(tags) || ' ' || description || ' ' || uri || ' ' || text(privateAlias) || ' ' || text(publicAlias))); +CREATE INDEX bookmark_all_ft_idx ON bookmark USING GIN(to_tsvector(lang, text(coalesce(tags, '{}'::text[])) || ' ' || coalesce(description, '') || ' ' || coalesce(uri, '') || ' ' || text(coalesce(privateAlias, '{}'::text[])) || ' ' || text(coalesce(publicAlias, '{}'::text[])))); -- penser au nettoyage de cette table, si plus aucun bookmark ne reference cette uri diff --git a/pkg/repository/bookmarkRepository.go b/pkg/repository/bookmarkRepository.go index 624dd3c..e2e04ae 100644 --- a/pkg/repository/bookmarkRepository.go +++ b/pkg/repository/bookmarkRepository.go @@ -79,7 +79,7 @@ func BookmarkJSON(currentUser model.BowUser, id string, uri string, tags []strin FROM bookmark WHERE tags @> string_to_array($1, ',') AND - (%s to_tsvector(lang, text(tags) || ' ' || description || ' ' || uri || ' ' || text(privateAlias) || ' ' || text(publicAlias)) @@ websearch_to_tsquery($2)) + (%s to_tsvector(lang, text(coalesce(tags, '{}'::text[])) || ' ' || coalesce(description, '') || ' ' || coalesce(uri, '') || ' ' || text(coalesce(privateAlias, '{}'::text[])) || ' ' || text(coalesce(publicAlias, '{}'::text[]))) @@ websearch_to_tsquery($2)) `, hl, queryEmptyFulltext) } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm