Example #1
0
 def search(self, keyword, index, size):
     """
     Search users with keyword.
     :param keyword: {string} The keyword.
     :param index: {int} The page index.
     :param size: {int} The page size.
     :return: ({list}, {int})
         The UserModel list.
         The number found.
     """
     plus, minus = utils.parse_keyword(keyword)
     query_string = ''
     if len(plus) > 0:
         keyword = ' '.join(plus)
         query_string += '((name:{1}) OR (email:{1}))'.replace('{1}', keyword)
     if len(minus) > 0:
         keyword = ' '.join(minus)
         query_string += 'NOT ((name:{1}) OR (email:{1}))'.replace('{1}', keyword)
     name_asc = search.SortExpression(
         expression='name',
         direction=search.SortExpression.ASCENDING,
         default_value=0,
     )
     options = search.QueryOptions(
         offset=size * index,
         limit=size,
         sort_options=search.SortOptions(expressions=[name_asc], limit=1000),
         returned_fields=['doc_id'],
     )
     query = search.Query(query_string=query_string, options=options)
     search_result = utils.get_index_users().search(query)
     total = search_result.number_found
     users = UserModel.get_by_id([long(x.doc_id) for x in search_result])
     return [x for x in users if not x is None], total
Example #2
0
 def test_utils_parse_keyword(self):
     keyword = 'apple -banana index'
     plus, minus = utils.parse_keyword(keyword)
     self.assertListEqual(plus, [
         'apple',
         'index',
     ])
     self.assertListEqual(minus, [
         'banana'
     ])
Example #3
0
    def search(cls, project_id, keyword, index, size, floor_lowest=None, floor_highest=None, label_ids=[]):
        """
        Search issues with keyword.
        :param project_id: {long} The project id.
        :param keyword: {string} The keyword.
        :param index: {int} The page index.
        :param size: {int} The page size.
        :param floor_lowest: {int}
        :param floor_highest: {int}
        :param label_ids: {list}
        :return: ({list}, {int})
            The IssueModel list.
            The number found.
        """
        plus, minus = utils.parse_keyword(keyword)
        query_string = ""
        if len(plus) > 0:
            keyword = " ".join(plus)
            query_string += "((title:{1}) OR (content:{1}))".replace("{1}", keyword)
        if len(minus) > 0:
            keyword = " ".join(minus)
            query_string += " NOT ((title:{1}) OR (content:{1}))".replace("{1}", keyword)
        if not floor_lowest is None:
            query_string += " AND (floor >= %s)" % floor_lowest
        if not floor_highest is None:
            query_string += " AND (floor <= %s)" % floor_highest
        for label_id in label_ids:
            if label_id:
                query_string += " AND (label_ids:%s)" % label_id

        create_time_desc = search.SortExpression(
            expression="create_time", direction=search.SortExpression.DESCENDING, default_value=0
        )
        options = search.QueryOptions(
            offset=size * index,
            limit=size,
            sort_options=search.SortOptions(expressions=[create_time_desc], limit=1000),
            returned_fields=["doc_id"],
        )
        query = search.Query(query_string=query_string, options=options)
        search_result = utils.get_index_issues(project_id).search(query)
        total = search_result.number_found
        issues = IssueModel.get_by_id([long(x.doc_id) for x in search_result])
        return [x for x in issues if not x is None], total