예제 #1
0
 async def unindex_all_childs(self, resource, response=None, future=True):
     if type(resource) is str:
         path = resource
         depth = path.count('/') + 1
     else:
         path = get_content_path(resource)
         depth = get_content_depth(resource)
         depth += 1
     if response is not None:
         response.write(b'Removing all childs of %s' % path.encode('utf-8'))
     request = get_current_request()
     index_name = self.get_index_name(request.site)
     path_query = {
         'query': {
             'bool': {
                 'must': [
                 ]
             }
         }
     }
     if path != '/':
         path_query['query']['bool']['must'].append({
             'term':
                 {'path': path}
         })
     path_query['query']['bool']['must'].append({
         'range':
             {'depth': {'gte': depth}}
     })
     logger.warn('Going to delete all in %s %d' % (path, depth))
     if future:
         _id = 'unindex_all_childs-' + uuid.uuid4().hex
         request._futures.update({_id: self.call_unindex_all_childs(index_name, path_query)})
     else:
         await self.call_unindex_all_childs(index_name, path_query)
예제 #2
0
    async def get_by_path(
            self, site, path, depth=-1, query={}, doc_type=None, size=10):
        if type(path) is not str:
            path = get_content_path(path)

        if path is not None and path != '/':
            path_query = {
                'query': {
                    'bool': {
                        'must': [
                            {
                                'match':
                                    {'path': path}
                            }
                        ]
                    }
                }
            }
            if depth > -1:
                query['query']['bool']['must'].append({
                    'range':
                        {'depth': {'gte': depth}}
                })
            query = rec_merge(query, path_query)
            # We need the local roles

        return await self.query(site, query, doc_type, size=size)
예제 #3
0
async def search_get(context, request):
    q = request.GET.get('q')
    search = queryUtility(ICatalogUtility)
    if search is None:
        return {'items_count': 0, 'member': []}

    return await search.get_by_path(site=request.site,
                                    path=get_content_path(context),
                                    query=q)
예제 #4
0
파일: index.py 프로젝트: plone/plone.server
def remove_object(obj, event):
    uid = getattr(obj, 'uuid', None)
    if uid is None:
        return
    portal_type = getattr(obj, 'portal_type', None)
    if portal_type is None or ISite.providedBy(obj):
        return

    content_path = get_content_path(obj)

    hook = get_hook()
    if hook is None:
        return
    hook.remove.append((uid, portal_type, content_path))
    if uid in hook.index:
        del hook.index[uid]
예제 #5
0
 async def unindex_all_childs(self, resource):
     if type(resource) is str:
         path = resource
         depth = path.count('/') + 1
     else:
         path = get_content_path(resource)
         depth = get_content_depth(resource)
         depth += 1
     request = get_current_request()
     index_name = self.get_index_name(request.site)
     path_query = {
         'query': {
             'bool': {
                 'must': [{
                     'term': {
                         'path': path
                     }
                 }, {
                     'range': {
                         'depth': {
                             'gte': depth
                         }
                     }
                 }]
             }
         }
     }
     conn_es = await self.conn.transport.get_connection()
     async with conn_es._session.post(conn_es._base_url + index_name +
                                      '/_delete_by_query',
                                      data=json.dumps(path_query)) as resp:
         result = await resp.json()
         if 'deleted' in result:
             logger.warn('Deleted %d childs' % result['deleted'])
         else:
             logger.warn('Wrong deletion of childs' + json.dumps(result))
예제 #6
0
def get_path(ob):
    return get_content_path(ob)
예제 #7
0
def get_path(ob):
    return get_content_path(ob)