1906 FIX search form autocomplete multi terms

This commit is contained in:
Bachir Soussi Chiadmi 2022-08-15 16:57:57 +02:00
parent 1993f80d8d
commit db6a82f7f7
9 changed files with 29 additions and 19 deletions

View File

@ -53,7 +53,7 @@ class Base extends ControllerBase {
$this->and_query->setParseMode($parse_mode); $this->and_query->setParseMode($parse_mode);
// Set fulltext search keywords and fields. // Set fulltext search keywords and fields.
if ($this->keys) { if ($this->keys) {
$this->and_query->keys($this->keys); $this->and_query->keys(implode(' ', $this->keys));
} }
// in case of term id provided restrict the keys to taxo fields // in case of term id provided restrict the keys to taxo fields
@ -166,7 +166,7 @@ class Base extends ControllerBase {
// Set fulltext search keywords and fields. // Set fulltext search keywords and fields.
if ($this->keys) { if ($this->keys) {
$this->or_query->keys($this->keys); $this->or_query->keys(implode(' ', $this->keys));
} }
// exclude results from and_query // exclude results from and_query
@ -176,7 +176,7 @@ class Base extends ControllerBase {
} }
$this->or_query->addConditionGroup($exclude_and_results_conditions); $this->or_query->addConditionGroup($exclude_and_results_conditions);
if (preg_match_all('/[WTRPCMFGSO]\d{4}/i', $this->keys, $matches)) { if (preg_match_all('/[WTRPCMFGSO]\d{4}/i', implode(' ', $this->keys), $matches)) {
// in case we search for material references like W0117 // in case we search for material references like W0117
$ref_conditions = $this->or_query->createConditionGroup('OR'); $ref_conditions = $this->or_query->createConditionGroup('OR');
foreach ($matches[0] as $key => $value) { foreach ($matches[0] as $key => $value) {
@ -264,8 +264,8 @@ class Base extends ControllerBase {
$this->keys = $request->query->get('keys'); $this->keys = $request->query->get('keys');
if($this->keys){ if($this->keys){
$this->keys = mb_strtolower($this->keys); $this->keys = mb_strtolower($this->keys);
// $this->keys = Tags::explode($this->keys); $this->keys = Tags::explode($this->keys);
\Drupal::logger('materio_sapi')->notice($this->keys); // \Drupal::logger('materio_sapi')->notice($this->keys);
} }
// get the exacte term id in case of autocomplete // get the exacte term id in case of autocomplete
// $this->terms = $request->query->get('terms'); // $this->terms = $request->query->get('terms');
@ -301,7 +301,7 @@ class Base extends ControllerBase {
$this->sapiQuery(); $this->sapiQuery();
$resp['keys'] = $this->keys; $resp['keys'] = json_encode($this->keys);
$resp['terms'] = json_encode($this->terms); $resp['terms'] = json_encode($this->terms);
$resp['filters'] = $this->filters; $resp['filters'] = $this->filters;
// $resp['count'] = $this->results->getResultCount(); // $resp['count'] = $this->results->getResultCount();
@ -313,7 +313,7 @@ class Base extends ControllerBase {
)); ));
if ($this->keys) { if ($this->keys) {
$resp['infos'] .= t(' keywords @keys', array( $resp['infos'] .= t(' keywords @keys', array(
"@keys" => $this->keys "@keys" => implode(', ', $this->keys)
)); ));
} }
if ($this->keys && $this->filters) { if ($this->keys && $this->filters) {
@ -389,7 +389,7 @@ class Base extends ControllerBase {
]; ];
if ($this->keys) { if ($this->keys) {
$resp['#title'] = $this->keys; $resp['#title'] = implode(', ', $this->keys);
// $this->sapiQuery(); // $this->sapiQuery();

File diff suppressed because one or more lines are too long

View File

@ -124,7 +124,7 @@ export default {
watch: { watch: {
typed(n, o){ typed(n, o){
console.log('watch typed changed o:' + o + ' n:' +n) console.log('watch typed changed o:' + o + ' n:' +n)
// todo remove terms from autocomplete if removed from typed // remove terms from autocomplete if removed from typed
const r = /,\s?$/ const r = /,\s?$/
let tag_list = n.replace(r,'').split(', ') let tag_list = n.replace(r,'').split(', ')
console.log('watch typed tag_list', tag_list) console.log('watch typed tag_list', tag_list)
@ -149,7 +149,8 @@ export default {
}, },
created() { created() {
// fill component values with store values in case of direct page loading // fill component values with store values in case of direct page loading
this.typed = this.keys console.log('SearchForm created, this.keys', this.keys)
this.typed = this.keys.length ? this.keys.join(', ') + ', ' : ''
this.autocomplete = this.terms this.autocomplete = this.terms
}, },
mounted(){ mounted(){

View File

@ -66,8 +66,11 @@ export default {
console.log('Base created() location',window.location) console.log('Base created() location',window.location)
let params = new URLSearchParams(window.location.search) let params = new URLSearchParams(window.location.search)
if (params.has('keys')) { if (params.has('keys')) {
this.$store.commit('Search/setKeys', params.get('keys')) const r = /,\s?$/
this.pagetitle = params.get('keys') let keys = params.get('keys').replace(r,'').split(', ')
console.log('Base created, keys', keys)
this.$store.commit('Search/setKeys', keys)
this.pagetitle = keys.join(', ') //params.get('keys')
} else { } else {
this.$store.commit('Search/setKeys', '') this.$store.commit('Search/setKeys', '')
this.pagetitle = 'Base' this.pagetitle = 'Base'
@ -92,7 +95,13 @@ export default {
beforeRouteUpdate (to, from, next) { beforeRouteUpdate (to, from, next) {
// when query change launch a new search // when query change launch a new search
console.log('Base beforeRouteUpdate', to, from, next) console.log('Base beforeRouteUpdate', to, from, next)
this.$store.commit('Search/setKeys', to.query.keys)
// this.$store.commit('Search/setKeys', to.query.keys)
const r = /,\s?$/
let keys = to.query.keys.replace(r,'').split(', ')
console.log('Base created, keys', keys)
this.$store.commit('Search/setKeys', keys)
this.$store.commit('Search/setTerms', to.query.terms) this.$store.commit('Search/setTerms', to.query.terms)
this.$store.commit('Search/setFilters', to.query.filters) this.$store.commit('Search/setFilters', to.query.filters)
this.pagetitle = to.query.keys this.pagetitle = to.query.keys

View File

@ -104,15 +104,15 @@ export default {
// actions // actions
actions: { actions: {
newSearch ({ dispatch, commit, state }) { newSearch ({ dispatch, commit, state }) {
console.log('Search newSearch') console.log('Search newSearch, state.keys', state.keys)
commit('resetUuids') commit('resetUuids')
commit('resetItems') commit('resetItems')
commit('resetCount') commit('resetCount')
commit('resetNoresults') commit('resetNoresults')
commit('resetOffset') commit('resetOffset')
commit('resetInfos') commit('resetInfos')
if (state.keys || state.terms) { if (state.keys || state.terms.length) {
this.commit('Common/setPagetitle', state.keys) this.commit('Common/setPagetitle', state.keys.join(', '))
} else { } else {
this.commit('Common/setPagetitle', 'Base') this.commit('Common/setPagetitle', 'Base')
} }