core-geonetwork icon indicating copy to clipboard operation
core-geonetwork copied to clipboard

Search reset button not working properly

Open josegar74 opened this issue 1 year ago • 3 comments

Describe the bug Search reset button should clean up the search fields and trigger a search to show all the results.

In some cases, the button is clicked and nothing happens. Clicking it a second time, works fine.

The issue happens in 3.12.x and main branches.

To Reproduce Steps to reproduce the behavior:

Case 1:

  1. In the home page, filter by a topic category.
  2. In the search page, click the reset button --> Search is executed and shows all results
  3. Go (with the application logo in the top bar) to the home page and select the same topic category
  4. In the search page, click the Reset button, nothing happens.
  5. Click the Reset button a second time and then it works

Case 2:

  1. In the search page, click the search button for an empty search
  2. Write a search filter and click the search button
  3. Click reset --> First time doesn't work, second works

Expected behavior Clicking the Reset button once, cleanups the search fields and executes an empty search to return all the results.

Additional context

The code involved it's https://github.com/geonetwork/core-geonetwork/blob/2731e560fd9e3a8cea16047082cf557d3c0978c5/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L321-L325

When it doesn't work, executes:

https://github.com/geonetwork/core-geonetwork/blob/2731e560fd9e3a8cea16047082cf557d3c0978c5/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L324

the next time, that works, enters in:

https://github.com/geonetwork/core-geonetwork/blob/2731e560fd9e3a8cea16047082cf557d3c0978c5/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L322

But if you go directly to the search page, do a search and click reset (that seems working), executes also:

https://github.com/geonetwork/core-geonetwork/blob/2731e560fd9e3a8cea16047082cf557d3c0978c5/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L324

A bit unclear what is causing this wrong behaviour.

josegar74 avatar Mar 07 '23 15:03 josegar74

@fxprunayre

I have done some tests, changing this code:

https://github.com/geonetwork/core-geonetwork/blob/2731e560fd9e3a8cea16047082cf557d3c0978c5/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L321-L325

Test 1:

if (angular.equals(params, gnSearchLocation.getParams())) {
  triggerSearchFn(false);
} else {
  triggerSearchFn(false);
  //gnSearchLocation.setSearch(params);
}

When clicking the Reset button, this seems working cleaning the search fields in the form and issuing a new search, but the URL hash keeps old values.

Doing a search, looks ok.

Test 2:

if (angular.equals(params, gnSearchLocation.getParams())) {
  triggerSearchFn(false);
} else {
  triggerSearchFn(false);
  gnSearchLocation.setSearch(params);
}

When clicking the Reset button, this seems working cleaning the search fields in the form and issuing a new search, updates the URL hash value. And only issues 1 search to the backend (A bit surprising as initially I was expecting 2).

But doing a search, issues 2 searches to the backend.


It's a bit unclear why it seems sometimes the search triggers a function that prepares and executes the query to ElasticSearch:

https://github.com/geonetwork/core-geonetwork/blob/2731e560fd9e3a8cea16047082cf557d3c0978c5/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L143-L283

And in some other cases, it seems doing that using the $location directive. What is the criteria for this?

josegar74 avatar Mar 07 '23 15:03 josegar74

I would reset lastSearchUrl

gnSearchLocation.lastSearchUrl = null;

in https://github.com/geonetwork/core-geonetwork/blob/main/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L357

to avoid https://github.com/geonetwork/core-geonetwork/blob/main/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L332-L333

What do you think ?

fxprunayre avatar Mar 08 '23 12:03 fxprunayre

@fxprunayre I've tried and it seems working.

I don't fully understand the logic to handle this, but apparently the change works.

josegar74 avatar Mar 09 '23 10:03 josegar74