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 2b0614716253838ff069b52890b1c6227f7fdde2 Author: Benjamin <poussin@codelutin.com> Date: Thu May 28 00:28:53 2020 +0200 ajout de la recherche fulltext --- pkg/repository/bookmarkRepository.go | 13 ++++++++++++- web/src/components/SearchInput.vue | 36 +++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/pkg/repository/bookmarkRepository.go b/pkg/repository/bookmarkRepository.go index 6a5244d..bf44774 100644 --- a/pkg/repository/bookmarkRepository.go +++ b/pkg/repository/bookmarkRepository.go @@ -46,7 +46,18 @@ func BookmarkJSON(currentUser model.BowUser, id string, uri string, tags []strin } else if uri != "" { mainQuery = `select * from bookmark where uri=$3` } else { - mainQuery = `select * from bookmark where tags @> string_to_array($1, ',')` + // 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 + preventEmptyFulltext := "" + if (fulltext == "") { + preventEmptyFulltext = "true || " + } + // vu qu'on veut utiliser l'index fulltext créer, il faut les meme champs dans la requete (to_tsvector) + mainQuery = fmt.Sprintf(`select * 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)) + `, preventEmptyFulltext) } tagsJoined := strings.Join(tags, ",") diff --git a/web/src/components/SearchInput.vue b/web/src/components/SearchInput.vue index 18972e3..9d63979 100644 --- a/web/src/components/SearchInput.vue +++ b/web/src/components/SearchInput.vue @@ -6,7 +6,7 @@ </div> <div> <label for="fulltext">fulltext</label> - <input id="fulltext" type="text" v-model="mFulltext" @keyup.enter="searchFulltext" /> + <input id="fulltext" type="text" v-model="fulltext" @keyup.enter="searchFulltext(mFulltext)" /> </div> <form :action="$fetch.createUrl('/opensearch')"> <label for="web">web</label> @@ -16,7 +16,7 @@ </template> <script> -import { Component, Vue, Watch } from 'vue-property-decorator' +import { Component, Vue } from 'vue-property-decorator' import TagsInput from '@/components/common/TagsInput' @Component({ @@ -24,12 +24,18 @@ import TagsInput from '@/components/common/TagsInput' components: { TagsInput } }) class SearchInput extends Vue { - mTags = '' + // mTags = '' mFulltext = '' + timeoutFulltextSearch = 0 + + cancelTimeoutFulltextSearch() { + this.timeoutFulltextSearch && clearTimeout(this.timeoutFulltextSearch) + this.timeoutFulltextSearch = 0 + } - searchFulltext() { - console.log('search', this.mFulltext) - this.changeFulltextAndGo(this.mFulltext) + searchFulltext(value) { + this.cancelTimeoutFulltextSearch() + this.changeFulltextAndGo(value) } get tags() { @@ -49,11 +55,16 @@ class SearchInput extends Vue { return this.queryInfo.fulltext } - // TODO supprimer ce watch faire comme pour les tags mais avec un timer avant le declenchement de la requete de recherche - @Watch('fulltext', { immediate: true, deep: true }) - onFulltextChange(fulltext) { - console.log('onFulltextChange SearchInput', fulltext) - this.mFulltext = this.fulltext + set fulltext(value) { + this.mFulltext = value + this.cancelTimeoutFulltextSearch() + this.timeoutFulltextSearch = setTimeout( + function(ft) { + this.searchFulltext(ft) + }.bind(this), + 1000, + value + ) } } @@ -67,11 +78,10 @@ export default SearchInput flex-direction: row; padding-top: 0; padding-bottom: 0; - } .search > * { - flex-grow: 2; + flex-grow: 2; } .search > * { -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.