Repository: CS-SI/eodag

Issue:
guess_product_type doesn't return all the matching products
The method `Searcher.search()` of *whoosh* [accepts a `limit` parameter](https://whoosh.readthedocs.io/en/latest/searching.html#the-searcher-object) that can be set to `None` to get all the results. By default `limit` is set to 10. I think we should set `limit=None` to make sure that `guess_product_type` returns the best matching products. This limiting parameter is provided by *whoosh* for performance reasons, I don't think performance is a problem for us here.

While I'm at it, should `guess_product_type` be actually part of the public API of eodag? We don't use it in any of the notebooks. It's also difficult to use without looking directly at the source code to find which search keys it supports (e.g. `platformSerialIdentifier`).

Discussion:

Patch:
diff --git a/eodag/api/core.py b/eodag/api/core.py
index 6b84203c..31a214cd 100644
--- a/eodag/api/core.py
+++ b/eodag/api/core.py
@@ -428,7 +428,7 @@ class EODataAccessGateway(object):
                     kwargs[search_key]
                 )
                 if results is None:
-                    results = searcher.search(query)
+                    results = searcher.search(query, limit=None)
                 else:
                     results.upgrade_and_extend(searcher.search(query))
             guesses = [r["ID"] for r in results or []]


Test patch:
diff --git a/tests/units/test_core.py b/tests/units/test_core.py
index 221f70bc..4bde0171 100644
--- a/tests/units/test_core.py
+++ b/tests/units/test_core.py
@@ -520,6 +520,19 @@ class TestCoreSearch(unittest.TestCase):
         with self.assertRaises(NoMatchingProductType):
             self.dag.guess_product_type()
 
+    def test_guess_product_type_has_no_limit(self):
+        """guess_product_type must run a whoosh search without any limit"""
+        # Filter that should give more than 10 products referenced in the catalog.
+        opt_prods = [
+            p for p in self.dag.list_product_types() if p["sensorType"] == "OPTICAL"
+        ]
+        if len(opt_prods) <= 10:
+            self.skipTest("This test requires that more than 10 products are 'OPTICAL'")
+        guesses = self.dag.guess_product_type(
+            sensorType="OPTICAL",
+        )
+        self.assertGreater(len(guesses), 10)
+
     def test__prepare_search_no_parameters(self):
         """_prepare_search must create some kwargs even when no parameter has been provided"""  # noqa
         prepared_search = self.dag._prepare_search()