Coverage for gws-app/gws/base/search/__init__.py: 100%
1 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
1"""Search.
3Searching finds features by a keyword, a geometry or a filter. A search is
4described by a ``gws.SearchQuery`` and run by finders (``gws.Finder``), which are
5configured for layers, projects and the application.
7Submodules:
9- ``finder``: the base class for finders, with the common ``Config`` options
10 (``withKeyword``, ``withGeometry``, ``withFilter``, ``spatialContext`` and others).
11 Concrete finders live in plugins (for example ``postgres``, ``qgis``, ``wms``,
12 ``wfs``, ``nominatim``).
13- ``manager``: the search manager (``gws.SearchManager``), which runs a query
14 through all finders that apply.
15- ``action``: the ``search`` action, whose ``searchFind`` command runs a search
16 for the client and returns the found features with their rendered views.
17- ``filter``: a parser for OGC Filter Encoding 2.0 (FES) filters into
18 ``gws.SearchFilter`` objects, and a ``Matcher`` that evaluates such a filter
19 against Python objects.
21The manager runs the finders of the requested layers first, then the finders of
22the project, then the application finders, and stops when the query limit is
23reached. A finder is skipped if the user may not use it, or if it cannot handle
24the query: every search parameter given in the query (keyword, shape, filter)
25must be supported by the finder and enabled in its config. A finder that fails
26is logged and skipped. Each found feature gets a category: the finder category,
27the finder title, or, if the feature has none, the layer title.
29A finder reads features through a model it finds for itself and the layer.
30Keyword searches without a user geometry are restricted to the area given by
31``spatialContext``: the whole map or the current client view.
33The ``filter`` module supports the minimum standard filter (``PropertyIsEqualTo``,
34``PropertyIsNotEqualTo``, ``PropertyIsLessThan``, ``PropertyIsGreaterThan``,
35``PropertyIsLessThanOrEqualTo``, ``PropertyIsGreaterThanOrEqualTo``) with the
36logical operators ``And``, ``Or`` and ``Not``, and, of the spatial operators,
37only ``BBOX``. Property names can be plain or namespace-prefixed. See the
38`OGC Filter Encoding 2.0 standard <http://docs.opengeospatial.org/is/09-026r2/09-026r2.html>`_.
40Example::
42 {
43 actions [
44 { type "search" limit 100 tolerance "10px" }
45 ]
46 projects [
47 {
48 uid "project_1"
49 finders [
50 { type "postgres" tableName "public.streets" withGeometry false }
51 ]
52 }
53 ]
54 }
56Example::
58 search = gws.SearchQuery(project=project, keyword='Main street', limit=10)
59 results = root.app.searchMgr.run_search(search, user)
60 for res in results:
61 print(res.feature.uid, res.finder.uid)
63Example::
65 flt = gws.base.search.filter.from_fes_string(xml_string)
66 matcher = gws.base.search.filter.Matcher()
67 found = [obj for obj in objects if matcher.matches(flt, obj)]
68"""
70from . import manager, finder