Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.87k stars 1.1k forks source link

query = "*" doesn't work in advanced search #1938

Open mtgovjesse opened 3 weeks ago

mtgovjesse commented 3 weeks ago

Describe the bug with arcgis enterprise 11.3

In regards to ContentManager.advanced_search:

I'm coming from this issue: https://github.com/Esri/arcgis-python-api/issues/499, where advanced_search raises an error if you give it an empty query (query=""), which still happens, but it was closed because using a wildcard doesn't raise an error (query = "*").

The problem is that using a wildcard doesn't seem to work with advanced_search. Nothing is returned.

.search(query="*") works. Everything up to max_items is returned.

.advanced_search(query="*") doesn't return anything.

result: {'total': 0, 'start': 1, 'num': 100, 'nextStart': -1, 'results': []}

To Reproduce Try running an advanced search with the query: query="*"

print(gis.content.advanced_search(query="*"))

Expected behavior Should return everything, up to max_items.

Platform (please complete the following information):

Additional context

achapkowski commented 3 weeks ago

This isn't a bug, the * is something special added onto search whereas advanced search means you have to craft everything on your own.

mtgovjesse commented 3 weeks ago

What about #499? Is an empty query string not allowed in advanced search?

It looks like the given reason for it being closed wasn't valid if "*" isn't supported by advanced search.

mtgovjesse commented 3 weeks ago

An empty query string still causes the same error.

mtgovjesse commented 3 weeks ago

How do you query all items in your server, with advanced_search so that you can use pagination?

nanaeaubry commented 3 weeks ago

"1=1" is the best way to query everything. It is equivalent to "*". Pagination may be needed

mtgovjesse commented 3 weeks ago

When I tried it, 1=1 didn't return everything. I'm not sure why, but after looking through the source code, I found out the only way (in my case at least) to return everything from advanced search is this:

gis = GIS(...)
accountid = gis.properties.id
gis.content.advanced_search(f"accountid:{accountid})

Which is actually what search does if you give it an empty string, if you don't set outside_org to True.

if not outside_org:
    accountid = self._gis.properties.get("id")
    if accountid and query:
        query += " accountid:" + accountid
    elif accountid:
        query = "accountid:" + accountid

itemlist = self.advanced_search(
    query=query,
    max_items=max_items,
    categories=categories,
    start=1,
    sort_field=sort_field,
    sort_order=sort_order,
    enrich=enrich,
    filter=filter,
)["results"]