7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
10 # FOR A PARTICULAR PURPOSE. |
10 # FOR A PARTICULAR PURPOSE. |
11 # |
11 # |
12 from pyams_content.component.theme import ICollectionsTarget, ICollectionsInfo |
|
13 |
12 |
14 __docformat__ = 'restructuredtext' |
13 __docformat__ = 'restructuredtext' |
15 |
14 |
16 |
15 from elasticsearch_dsl import Q |
17 # import standard library |
|
18 |
|
19 # import interfaces |
|
20 from pyams_content.component.theme.interfaces import ITagsTarget, ITagsInfo, IThemesTarget, IThemesInfo |
|
21 from pyams_content.shared.view.interfaces import IWfView, IViewQueryEsParamsExtension, IViewThemesSettings, \ |
|
22 IViewTagsSettings, IViewCollectionsSettings |
|
23 from pyams_content_es.interfaces import IDocumentIndexInfo |
|
24 from zope.intid.interfaces import IIntIds |
16 from zope.intid.interfaces import IIntIds |
25 |
17 |
26 # import packages |
18 from pyams_content.component.theme import ICollectionsInfo, ICollectionsTarget, ITagsManager |
27 from elasticsearch_dsl import Q |
19 from pyams_content.component.theme.interfaces import ITagsInfo, ITagsTarget, IThemesInfo, IThemesTarget |
28 from pyams_utils.adapter import adapter_config, ContextAdapter |
20 from pyams_content.shared.view.interfaces import IViewCollectionsSettings, IViewQueryEsParamsExtension, \ |
|
21 IViewTagsSettings, IViewThemesSettings, IViewUserQuery, IWfView |
|
22 from pyams_content_es.interfaces import IDocumentIndexInfo |
|
23 from pyams_content_es.shared.view import EsSearchFolderQuery |
|
24 from pyams_thesaurus.interfaces.thesaurus import IThesaurus |
|
25 from pyams_utils.adapter import ContextAdapter, adapter_config |
29 from pyams_utils.list import unique |
26 from pyams_utils.list import unique |
30 from pyams_utils.registry import get_utility |
27 from pyams_utils.registry import get_utility, query_utility |
31 |
28 |
32 |
29 |
33 # |
30 # |
34 # Tags index |
31 # Tags index |
35 # |
32 # |
52 |
49 |
53 def get_es_params(self, context): |
50 def get_es_params(self, context): |
54 settings = IViewTagsSettings(self.context) |
51 settings = IViewTagsSettings(self.context) |
55 tags = settings.get_tags_index(context) |
52 tags = settings.get_tags_index(context) |
56 if tags: |
53 if tags: |
57 return Q('terms', **{'tags': tags}) |
54 yield Q('terms', **{'tags': tags}) |
|
55 |
|
56 |
|
57 @adapter_config(name='tag', context=EsSearchFolderQuery, provides=IViewUserQuery) |
|
58 class EsSearchFolderTagQuery(ContextAdapter): |
|
59 """Search folder tag query for Elasticsearch""" |
|
60 |
|
61 @staticmethod |
|
62 def get_user_params(request): |
|
63 tag = request.params.get('tag') |
|
64 if tag: |
|
65 manager = ITagsManager(request.root, None) |
|
66 if manager is None: |
|
67 raise StopIteration |
|
68 thesaurus = query_utility(IThesaurus, name=manager.thesaurus_name) |
|
69 if thesaurus is None: |
|
70 raise StopIteration |
|
71 term = thesaurus.terms.get(tag) |
|
72 if term is not None: |
|
73 intids = query_utility(IIntIds) |
|
74 yield Q('term', **{'tags': intids.queryId(term)}) |
58 |
75 |
59 |
76 |
60 # |
77 # |
61 # Themes index |
78 # Themes index |
62 # |
79 # |