Пример #1
0
    def get_objects(cls, search_query, privacy, page_no, page_size,
                    default_max_score, user, tags):
        # def get_objects(cls, search_query, user=None, page_no=PAGE_NO,
        #             page_size=PAGE_SIZE, default_max_score=0.4,
        #             privacy=None,tags=tags):

        start = (page_no - 1) * page_size
        end = page_no * page_size
        # 获取所有的
        if search_query:
            objects = cls.repo.search(search_query, {
                'name': 'icontains',
                'description': 'icontains',
                'tags': 'in'
            })
        else:
            objects = cls.repo.read()
        if privacy:
            objects = objects(privacy=privacy)
        if user:
            objects = objects(user=user)
        if tags:
            # todo 是否有直接的查询语句取代
            for each_tag in tags:
                objects = objects(tags=each_tag)

        count = objects.count()
        return Objects(objects=objects[start:end],
                       count=count,
                       page_no=page_no,
                       page_size=page_size)
Пример #2
0
    def list_projects_chat(cls,
                           search_query,
                           page_no=None,
                           page_size=None,
                           default_max_score=0.4,
                           privacy="public"):
        start = (page_no - 1) * page_size
        end = page_no * page_size

        # all_apps = cls.get_all()
        all_apps = cls.repo.read(query={"privacy": privacy})
        # all_apps = cls.read(query={"privacy": privacy})

        #  比对打分
        for app in all_apps:
            name_score = synonyms.compare(search_query, app.name, seg=True)
            description_score = synonyms.compare(search_query,
                                                 app.description,
                                                 seg=True)
            app.score = (name_score + description_score) / 2
        # 筛选掉小于 description_score
        apps = list(
            filter(lambda app: app.score >= default_max_score, all_apps))

        count = len(apps)
        apps = sorted(apps, key=lambda item: -item.score)
        return Objects(objects=apps[start:end],
                       count=count,
                       page_no=page_no,
                       page_size=page_size)
Пример #3
0
 def get_pagination(cls, query, page_no, page_size):
     start = (page_no - 1) * page_size
     end = page_no * page_size
     objects = cls.repo.read(query=query)
     count = objects.count()
     return Objects(objects=objects[start:end],
                    count=count,
                    page_no=page_no,
                    page_size=page_size)
Пример #4
0
 def get_action_entity(cls, app_obj, page_no, page_size, action_entity):
     start = (page_no - 1) * page_size
     end = page_no * page_size
     objects = getattr(app_obj, action_entity)
     objects.reverse()
     return Objects(objects=objects[start:end],
                    count=len(objects),
                    page_no=page_no,
                    page_size=page_size)
Пример #5
0
 def get_action_entity(cls,
                       user_ID,
                       page_no,
                       page_size,
                       action_entity,
                       type=None,
                       search_query=None):
     user = cls.get_by_user_ID(user_ID=user_ID)
     start = (page_no - 1) * page_size
     end = page_no * page_size
     if action_entity == 'request_star':
         list_objects = getattr(user, action_entity)
         objectsId = [e.id for e in list_objects]
         if search_query:
             objects = UserRequestRepo(UserRequest). \
                 search(search_query,
                        q_dict={
                            'title': 'icontains',
                            'description': 'icontains',
                            'tags': 'icontains'
                        })
         else:
             objects = UserRequest.objects
         objects = objects.filter(id__in=objectsId)
         objects = objects(type=type)
     else:
         if search_query:
             list_objects = getattr(user, action_entity)
             objectsId = [e.id for e in list_objects]
             objects = ProjectRepo(Project). \
                 search(search_query,
                        q_dict={
                            'name': 'icontains',
                            'description': 'icontains',
                            'tags': 'icontains'
                        })
             objects = objects.filter(id__in=objectsId)
         else:
             objects = getattr(user, action_entity)
             objects.reverse()
     return Objects(objects=objects[start:end],
                    count=len(objects),
                    page_no=page_no,
                    page_size=page_size)
Пример #6
0
    def get_objects(cls,
                    search_query,
                    user=None,
                    page_no=PAGE_NO,
                    page_size=PAGE_SIZE,
                    default_max_score=0.4,
                    privacy=None):
        """
        Search for objects

        :param search_query:
        :param user:
        :param page_no:
        :param page_size:
        :param default_max_score:
        :return:
        """

        start = (page_no - 1) * page_size
        end = page_no * page_size
        # 获取所有的
        if search_query:
            objects = cls.repo.search(search_query, {
                'name': 'icontains',
                'description': 'icontains',
                'tags': 'in'
            })
        else:
            objects = cls.repo.read()
        if privacy:
            objects = objects(privacy=privacy)
        if user:
            objects = objects(user=user)
        count = objects.count()
        return Objects(objects=objects[start:end],
                       count=count,
                       page_no=page_no,
                       page_size=page_size)