geonetwork / core-geonetwork

GeoNetwork is a catalog application to manage spatially referenced resources. It provides powerful metadata editing and search functions as well as an interactive web map viewer. It is currently used in numerous Spatial Data Infrastructure initiatives across the world.
http://geonetwork-opensource.org/
GNU General Public License v2.0
412 stars 487 forks source link

Search reset button not working properly #6892

Open josegar74 opened 1 year ago

josegar74 commented 1 year ago

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 commented 1 year ago

@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?

fxprunayre commented 1 year ago

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 ?

josegar74 commented 1 year ago

@fxprunayre I've tried and it seems working.

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