Exemplo n.º 1
0
def search_blog_comments(env, terms):
    """ Free text search for content of blog posts.
    Input is a list of terms.
    Returns a list of tuples with:
        (post_name, comment_number, comment, comment_author, comment_time) """
    assert terms
    # construct sql + args
    columns = ['author', 'comment']
    if hasattr(env, 'db_query'):
        with env.db_query as db:
            search_clause, args = search_to_sql(db, columns, terms)
    else:
        db = env.get_db_cnx()
        search_clause, args = search_to_sql(db, columns, terms)
    sql = "SELECT name, number, comment, author, time " \
          "FROM fullblog_comments WHERE " + search_clause
    # perform search
    if hasattr(env, 'db_query'):
        cursor = env.db_query(sql, args)
    else:
        db = env.get_db_cnx()
        cursor = db.cursor()
        cursor.execute(sql, args)
    # return found items
    return [(row[0], row[1], row[2], row[3], to_datetime(row[4], utc))
            for row in cursor]
Exemplo n.º 2
0
def search_blog_posts(env, terms):
    """ Free text search for content of blog posts.
    Input is a list of terms.
    Returns a list of tuples with:
        (name, version, publish_time, author, title, body) """
    assert terms
    # construct sql + args
    columns = [
        'bp1.name', 'bp1.title', 'bp1.body', 'bp1.author', 'bp1.categories'
    ]
    if hasattr(env, 'db_query'):
        with env.db_query as db:
            search_clause, args = search_to_sql(db, columns, terms)
    else:
        db = env.get_db_cnx()
        search_clause, args = search_to_sql(db, columns, terms)
    sql = "SELECT bp1.name, bp1.version, bp1.publish_time, bp1.author, " \
               "bp1.title, bp1.body " \
               "FROM fullblog_posts bp1," \
               "(SELECT name, max(version) AS ver " \
               "FROM fullblog_posts GROUP BY name) bp2 " \
               "WHERE bp1.version = bp2.ver AND bp1.name = bp2.name " \
               "AND " + search_clause
    # perform search
    if hasattr(env, 'db_query'):
        cursor = env.db_query(sql, args)
    else:
        db = env.get_db_cnx()
        cursor = db.cursor()
        cursor.execute(sql, args)
    # return found items
    return [(row[0], row[1], to_datetime(row[2], utc), row[3], row[4], row[5])
            for row in cursor]
Exemplo n.º 3
0
def search_blog_posts(env, terms):
    """ Free text search for content of blog posts.
    Input is a list of terms.
    Returns a list of tuples with:
        (name, version, publish_time, author, title, body) """
    assert terms
    # construct sql + args
    columns = ['bp1.name', 'bp1.title', 'bp1.body',
               'bp1.author', 'bp1.categories']
    if hasattr(env, 'db_query'):
        with env.db_query as db:
            search_clause, args = search_to_sql(db, columns, terms)
    else:
        db = env.get_db_cnx()
        search_clause, args = search_to_sql(db, columns, terms)
    sql = "SELECT bp1.name, bp1.version, bp1.publish_time, bp1.author, " \
               "bp1.title, bp1.body " \
               "FROM fullblog_posts bp1," \
               "(SELECT name, max(version) AS ver " \
               "FROM fullblog_posts GROUP BY name) bp2 " \
               "WHERE bp1.version = bp2.ver AND bp1.name = bp2.name " \
               "AND " + search_clause
    # perform search
    if hasattr(env, 'db_query'):
        cursor = env.db_query(sql, args)
    else:
        db = env.get_db_cnx()
        cursor = db.cursor()
        cursor.execute(sql, args)
    # return found items
    return [(row[0], row[1], to_datetime(row[2], utc), row[3],
            row[4], row[5]) for row in cursor]
Exemplo n.º 4
0
def search_blog_comments(env, terms):
    """ Free text search for content of blog posts.
    Input is a list of terms.
    Returns a list of tuples with:
        (post_name, comment_number, comment, comment_author, comment_time) """
    assert terms
    # construct sql + args
    columns = ['author', 'comment']
    if hasattr(env, 'db_query'):
        with env.db_query as db:
            search_clause, args = search_to_sql(db, columns, terms)
    else:
        db = env.get_db_cnx()
        search_clause, args = search_to_sql(db, columns, terms)
    sql = "SELECT name, number, comment, author, time " \
          "FROM fullblog_comments WHERE " + search_clause
    # perform search
    if hasattr(env, 'db_query'):
        cursor = env.db_query(sql, args)
    else:
        db = env.get_db_cnx()
        cursor = db.cursor()
        cursor.execute(sql, args)
    # return found items
    return [(row[0], row[1], row[2], row[3], to_datetime(row[4], utc))
            for row in cursor]
Exemplo n.º 5
0
    def get_search_results(self, req, terms, filters):
        """Overriding search results for Tickets"""
        if not "ticket" in filters:
            return
        ticket_realm = Resource("ticket")
        with self.env.db_query as db:
            sql, args = search_to_sql(
                db, ["summary", "keywords", "description", "reporter", "cc", db.cast("id", "text")], terms
            )
            sql2, args2 = search_to_sql(db, ["newvalue"], terms)
            sql3, args3 = search_to_sql(db, ["value"], terms)
            ticketsystem = TicketSystem(self.env)
            if req.args.get("product"):
                productsql = "product='%s' AND" % req.args.get("product")
            else:
                productsql = ""

            for summary, desc, author, type, tid, ts, status, resolution in db(
                """SELECT summary, description, reporter, type, id,
                                 time, status, resolution 
                          FROM ticket
                          WHERE (%s id IN (
                              SELECT id FROM ticket WHERE %s
                            UNION
                              SELECT ticket FROM ticket_change
                              WHERE field='comment' AND %s
                            UNION
                              SELECT ticket FROM ticket_custom WHERE %s
                          ))
                          """
                % (productsql, sql, sql2, sql3),
                args + args2 + args3,
            ):
                t = ticket_realm(id=tid)
                if "TICKET_VIEW" in req.perm(t):
                    yield (
                        req.href.ticket(tid),
                        tag_(
                            "%(title)s: %(message)s",
                            title=tag.span(get_resource_shortname(self.env, t), class_=status),
                            message=ticketsystem.format_summary(summary, status, resolution, type),
                        ),
                        from_utimestamp(ts),
                        author,
                        shorten_result(desc, terms),
                    )

        # Attachments
        for result in AttachmentModule(self.env).get_search_results(req, ticket_realm, terms):
            yield result
Exemplo n.º 6
0
    def get_search_results(self, req, terms, filters):
        if not 'discussion' in filters:
            return

        # Create context.
        context = Context.from_request(req)
        context.realm = 'discussion-core'

        # Get database access.
        db = self.env.get_db_cnx()
        cursor = db.cursor()

        # Search in topics.
        query, args = search_to_sql(db, ['author', 'subject', 'body'], terms)
        columns = ('id', 'forum', 'time', 'subject', 'body', 'author')
        sql = ("SELECT id, forum, time, subject, body, author "
               "FROM topic "
               " WHERE %s" % (query, ))
        self.log.debug(sql)
        cursor.execute(sql, args)
        for row in cursor:
            row = dict(zip(columns, row))
            row['time'] = to_datetime(row['time'], utc)
            yield (req.href.discussion('topic', row['id']) + '#-1',
                   "Topic #%d: %s" % (row['id'], shorten_line(row['subject'])),
                   row['time'], row['author'],
                   shorten_result(row['body'], [query]))

        # Search in messages
        query, args = search_to_sql(db, ['m.author', 'm.body', 't.subject'],
                                    terms)
        columns = ('id', 'forum', 'topic', 'time', 'author', 'body', 'subject')
        sql = ("SELECT m.id, m.forum, m.topic, m.time, m.author, m.body, "
               "t.subject "
               "FROM message m "
               "LEFT JOIN "
               "(SELECT subject, id "
               "FROM topic) t "
               "ON t.id = m.topic "
               "WHERE %s" % (query))
        self.log.debug(sql)
        cursor.execute(sql, args)
        for row in cursor:
            row = dict(zip(columns, row))
            row['time'] = to_datetime(row['time'], utc)
            yield (req.href.discussion('message', row['id']) + '#%s' %
                   (row['id']), "Message  #%d: %s" %
                   (row['id'], shorten_line(row['subject'])), row['time'],
                   row['author'], shorten_result(row['body'], [query]))
Exemplo n.º 7
0
    def get_search_results(self, req, terms, filters):
        """Overriding search results for Tickets"""
        if not 'ticket' in filters:
            return
        ticket_realm = Resource('ticket')
        with self.env.db_query as db:
            sql, args = search_to_sql(db, [
                'summary', 'keywords', 'description', 'reporter', 'cc',
                db.cast('id', 'text')
            ], terms)
            sql2, args2 = search_to_sql(db, ['newvalue'], terms)
            sql3, args3 = search_to_sql(db, ['value'], terms)
            ticketsystem = TicketSystem(self.env)
            if req.args.get('product'):
                productsql = "product='%s' AND" % req.args.get('product')
            else:
                productsql = ""

            for summary, desc, author, type, tid, ts, status, resolution in \
                    db("""SELECT summary, description, reporter, type, id,
                                 time, status, resolution
                          FROM ticket
                          WHERE (%s id IN (
                              SELECT id FROM ticket WHERE %s
                            UNION
                              SELECT ticket FROM ticket_change
                              WHERE field='comment' AND %s
                            UNION
                              SELECT ticket FROM ticket_custom WHERE %s
                          ))
                          """ % (productsql, sql, sql2, sql3),
                          args + args2 + args3):
                t = ticket_realm(id=tid)
                if 'TICKET_VIEW' in req.perm(t):
                    yield (req.href.ticket(tid),
                           tag_("%(title)s: %(message)s",
                                title=tag.span(get_resource_shortname(
                                    self.env, t),
                                               class_=status),
                                message=ticketsystem.format_summary(
                                    summary, status, resolution,
                                    type)), from_utimestamp(ts), author,
                           shorten_result(desc, terms))

        # Attachments
        for result in AttachmentModule(self.env) \
                      .get_search_results(req, ticket_realm, terms):
            yield result
Exemplo n.º 8
0
    def get_search_results(self, req, terms, filters):
        if not 'discussion' in filters:
            return

        # Create context.
        context = Context.from_request(req)
        context.realm = 'discussion-core'

        # Get database access.
        db = self.env.get_db_cnx()
        cursor = db.cursor()

        # Search in topics.
        query, args = search_to_sql(db, ['author', 'subject', 'body'], terms)
        columns = ('id', 'forum', 'time', 'subject', 'body', 'author')
        sql = ("SELECT id, forum, time, subject, body, author "
               "FROM topic "
               " WHERE %s" % (query,))
        self.log.debug(sql)
        cursor.execute(sql, args)
        for row in cursor:
            row = dict(zip(columns, row))
            row['time'] = to_datetime(row['time'], utc)
            yield (req.href.discussion('topic', row['id']) + '#-1',
              "Topic #%d: %s" % (row['id'], shorten_line(row['subject'])),
              row['time'], row['author'], shorten_result(row['body'], [query]))

        # Search in messages
        query, args = search_to_sql(db, ['m.author', 'm.body',
          't.subject'],  terms)
        columns = ('id', 'forum', 'topic', 'time', 'author', 'body', 'subject')
        sql = ("SELECT m.id, m.forum, m.topic, m.time, m.author, m.body, "
                 "t.subject "
               "FROM message m "
               "LEFT JOIN "
                 "(SELECT subject, id "
                 "FROM topic) t "
               "ON t.id = m.topic "
               "WHERE %s" % (query))
        self.log.debug(sql)
        cursor.execute(sql, args)
        for row in cursor:
            row = dict(zip(columns, row))
            row['time'] = to_datetime(row['time'], utc)
            yield (req.href.discussion('message', row['id']) + '#%s' % (
              row['id']), "Message  #%d: %s" % (row['id'], shorten_line(
              row['subject'])), row['time'], row['author'], shorten_result(
              row['body'], [query]))
Exemplo n.º 9
0
    def get_search_results(self, req, terms, filters):
        if not 'wiki' in filters:
            return
        with self.env.db_query as db:
            sql_query, args = search_to_sql(
                db, ['w1.name', 'w1.author', 'w1.text'], terms)
            wiki_realm = Resource('wiki')
            for name, ts, author, text in db(
                    """
                    SELECT w1.name, w1.time, w1.author, w1.text
                    FROM wiki w1,(SELECT name, max(version) AS ver
                                  FROM wiki GROUP BY name) w2
                    WHERE w1.version = w2.ver AND w1.name = w2.name
                    AND """ + sql_query, args):
                page = wiki_realm(id=name)
                if 'WIKI_VIEW' in req.perm(page):
                    yield (get_resource_url(self.env, page, req.href),
                           '%s: %s' % (name, shorten_line(text)),
                           from_utimestamp(ts), author,
                           shorten_result(text, terms))

        # Attachments
        for result in AttachmentModule(self.env).get_search_results(
                req, wiki_realm, terms):
            yield result
Exemplo n.º 10
0
    def get_search_results(self, req, terms, filters):
        if not 'wiki' in filters:
            return
        db = self.env.get_db_cnx()
        sql_query, args = search_to_sql(db, ['w1.name', 'w1.author', 'w1.text'],
                                        terms)
        cursor = db.cursor()
        cursor.execute("SELECT w1.name,w1.time,w1.author,w1.text "
                       "FROM wiki w1,"
                       "(SELECT name,max(version) AS ver "
                       "FROM wiki GROUP BY name) w2 "
                       "WHERE w1.version = w2.ver AND w1.name = w2.name "
                       "AND " + sql_query, args)

        wiki_realm = Resource('wiki')
        for name, ts, author, text in cursor:
            page = wiki_realm(id=name)
            if 'WIKI_VIEW' in req.perm(page):
                yield (get_resource_url(self.env, page, req.href),
                       '%s: %s' % (name, shorten_line(text)),
                       datetime.fromtimestamp(ts, utc), author,
                       shorten_result(text, terms))
        
        # Attachments
        for result in AttachmentModule(self.env).get_search_results(
            req, wiki_realm, terms):
            yield result
Exemplo n.º 11
0
    def get_search_results(self, req, terms, filters):
        if not 'milestone' in filters:
            return
        db = self.env.get_db_cnx()
        sql_query, args = search_to_sql(db, ['name', 'description'], terms)
        cursor = db.cursor()
        cursor.execute(
            "SELECT name,due,completed,description "
            "FROM milestone "
            "WHERE " + sql_query, args)

        milestone_realm = Resource('milestone')
        for name, due, completed, description in cursor:
            milestone = milestone_realm(id=name)
            if 'MILESTONE_VIEW' in req.perm(milestone):
                dt = (completed and from_utimestamp(completed)
                      or due and from_utimestamp(due) or datetime.now(utc))
                yield (get_resource_url(self.env, milestone, req.href),
                       get_resource_name(self.env, milestone), dt, '',
                       shorten_result(description, terms))

        # Attachments
        for result in AttachmentModule(self.env).get_search_results(
                req, milestone_realm, terms):
            yield result
Exemplo n.º 12
0
def search_blog_posts(env, terms):
    """ Free text search for content of blog posts.
    Input is a list of terms.
    Returns a list of tuples with:
        (name, version, publish_time, author, title, body) """
    assert terms
    cnx = env.get_db_cnx()
    cursor = cnx.cursor()
    # SQL
    columns = [
        'bp1.name', 'bp1.title', 'bp1.body', 'bp1.author', 'bp1.categories'
    ]
    search_clause, args = search_to_sql(cnx, columns, terms)
    sql = "SELECT bp1.name, bp1.version, bp1.publish_time, bp1.author, " \
               "bp1.title, bp1.body " \
               "FROM fullblog_posts bp1," \
               "(SELECT name, max(version) AS ver " \
               "FROM fullblog_posts GROUP BY name) bp2 " \
               "WHERE bp1.version = bp2.ver AND bp1.name = bp2.name " \
               "AND " + search_clause
    env.log.debug("search_blog_posts() SQL: %r" % sql)
    cursor.execute(sql, args)
    # Return the items we have found
    return [(row[0], row[1], to_datetime(row[2], utc), row[3], row[4], row[5])
            for row in cursor]
 def attr_values_sql(db, attr_values):
     sql_query = ""
     sql_values = []
     for terms in attr_values:
         if sql_query:
             sql_query += ' OR '
         names, values = search_to_sql(db, ['LOWER(val.attr_value)'], terms.split())
         sql_query += names
         sql_values.extend(values)
     return "(" + sql_query + ")", sql_values
Exemplo n.º 14
0
 def attr_values_sql(db, attr_values):
     sql_query = ""
     sql_values = []
     for terms in attr_values:
         if sql_query:
             sql_query += ' OR '
         names, values = search_to_sql(db, ['LOWER(val.attr_value)'],
                                       terms.split())
         sql_query += names
         sql_values.extend(values)
     return "(" + sql_query + ")", sql_values
Exemplo n.º 15
0
 def get_search_results(self,req,terms,filters):
     db = self.env.get_db_cnx()
     sql_query, args = search_to_sql(db, ['owner','proj_name','proj_full_name','description'],terms)
     cursor=db.cursor()
     cursor.execute('select owner, proj_name,proj_full_name,description,exam_time from project where stat=1 and'+ sql_query, args)
     for owner, proj_name, proj_full_name,description,exam_time in cursor:
         yield (
                 self.env.config.get('projectsmanager','base_url')+'/%s'%proj_name,
                 proj_full_name,
                 from_utimestamp(exam_time*1000000),
                 owner,
                 shorten_result("Description: "+description,terms,maxlen=100)
                 )
Exemplo n.º 16
0
 def get_search_results(self, req, terms, filters):
     if not 'ticket' in filters:
         return
     db = self.env.get_db_cnx()
     sql, args = search_to_sql(db, ['b.newvalue'], terms)
     sql2, args2 = search_to_sql(db, ['summary', 'keywords', 'description',
                                      'reporter', 'cc'], terms)
     cursor = db.cursor()
     cursor.execute("SELECT DISTINCT a.summary,a.description,a.reporter, "
                    "a.keywords,a.id,a.time,a.status FROM ticket a "
                    "LEFT JOIN ticket_change b ON a.id = b.ticket "
                    "WHERE (b.field='comment' AND %s ) OR %s" % (sql, sql2),
                    args + args2)
     for summary, desc, author, keywords, tid, date, status in cursor:
         ticket = '#%d: ' % tid
         if status == 'closed':
             ticket = Markup('<span style="text-decoration: line-through">'
                             '#%s</span>: ', tid)
         self.log.debug("get_search_results - %s" % summary )
         yield (req.href.ticket(tid),
               ticket + shorten_line(summary),
                datetime.fromtimestamp(date,utc), author, shorten_result(desc, terms), summary)
    def search(cls, env, terms):
        terms = cls._normalize_terms(terms)

        with env.db_query as db:
            sql_query, args = search_to_sql(db, ['val.attr_value'], terms)

            for a_id, attr_name, attr_value, vid, time, author in db("""
                    SELECT a.id, val.attr_name, val.attr_value, max(v.id), v.time, v.author
                    FROM asa_artifact_value val
                        INNER JOIN asa_version v ON v.id=val.version_id
                        INNER JOIN asa_artifact a ON a.id=val.artifact_id
                    WHERE """ + sql_query +
                    """ GROUP BY a.id""", args):
                yield (a_id, attr_name, attr_value, vid, from_utimestamp(time), author)
Exemplo n.º 18
0
    def search(cls, env, terms):
        terms = cls._normalize_terms(terms)

        with env.db_query as db:
            sql_query, args = search_to_sql(db, ['val.attr_value'], terms)

            for a_id, attr_name, attr_value, vid, time, author in db(
                    """
                    SELECT a.id, val.attr_name, val.attr_value, max(v.id), v.time, v.author
                    FROM asa_artifact_value val
                        INNER JOIN asa_version v ON v.id=val.version_id
                        INNER JOIN asa_artifact a ON a.id=val.artifact_id
                    WHERE """ + sql_query + """ GROUP BY a.id""", args):
                yield (a_id, attr_name, attr_value, vid, from_utimestamp(time),
                       author)
Exemplo n.º 19
0
def search_blog_comments(env, terms):
    """ Free text search for content of blog posts.
    Input is a list of terms.
    Returns a list of tuples with:
        (post_name, comment_number, comment, comment_author, comment_time) """
    assert terms
    columns = ['author', 'comment']
    with env.db_query as db:
        search_clause, args = search_to_sql(db, columns, terms)
        return [(row[0], row[1], row[2], row[3], to_datetime(row[4], utc))
                for row in db(
                    """
                    SELECT name, number, comment, author, time
                    FROM fullblog_comments WHERE %s
                    """ % search_clause, args)]
Exemplo n.º 20
0
 def get_search_results(self, req, terms, filters):
     if not 'changeset' in filters:
         return
     repos = self.env.get_repository(req.authname)
     db = self.env.get_db_cnx()
     sql, args = search_to_sql(db, ['rev', 'message', 'author'], terms)
     cursor = db.cursor()
     cursor.execute("SELECT rev,time,author,message "
                    "FROM revision WHERE " + sql, args)
     for rev, ts, author, log in cursor:
         if not repos.authz.has_permission_for_changeset(rev):
             continue
         yield (req.href.changeset(rev),
                '[%s]: %s' % (rev, shorten_line(log)),
                datetime.fromtimestamp(ts, utc), author,
                shorten_result(log, terms))
Exemplo n.º 21
0
def search_blog_comments(env, terms):
    """ Free text search for content of blog posts.
    Input is a list of terms.
    Returns a list of tuples with:
        (post_name, comment_number, comment, comment_author, comment_time) """
    assert terms
    cnx = env.get_db_cnx()
    cursor = cnx.cursor()
    # SQL
    columns = ['author', 'comment']
    search_clause, args = search_to_sql(cnx, columns, terms)
    sql = "SELECT name, number, comment, author, time " \
          "FROM fullblog_comments WHERE " + search_clause
    env.log.debug("search_blog_comments() SQL: %r" % sql)
    cursor.execute(sql, args)
    # Return the items we have found
    return [(row[0], row[1], row[2], row[3], to_datetime(row[4], utc))
            for row in cursor]
Exemplo n.º 22
0
def search_blog_comments(env, terms):
    """ Free text search for content of blog posts.
    Input is a list of terms.
    Returns a list of tuples with:
        (post_name, comment_number, comment, comment_author, comment_time) """
    assert terms
    cnx = env.get_db_cnx()
    cursor = cnx.cursor()
    # SQL
    columns = ['author', 'comment']
    search_clause, args = search_to_sql(cnx, columns, terms)
    sql = "SELECT name, number, comment, author, time " \
          "FROM fullblog_comments WHERE " + search_clause
    env.log.debug("search_blog_comments() SQL: %r" % sql)
    cursor.execute(sql, args)
    # Return the items we have found
    return [(row[0], row[1], row[2], row[3], to_datetime(row[4], utc))
            for row in cursor]
Exemplo n.º 23
0
def search_testcases(env, terms):
    """ Free text search for content of blog posts.
    Input is a list of terms.
    Returns a list of tuples with: ( ... ) """

    cnx = env.get_db_cnx()
    cursor = cnx.cursor()
    columns = ['title', 'description', 'author', 'acceptance']
    search_clause, args = search_to_sql(cnx, columns, terms)
    sql = """
        SELECT author, title, description
        FROM  qa_testcase
        WHERE """ + search_clause
    env.log.debug("search_testcases() SQL: %r" % sql)
    cursor.execute(sql, args)

    return [(row[0], row[1], to_datetime(row[2], utc), row[3], \
            row[4], row[5]) for row in cursor]
Exemplo n.º 24
0
    def get_search_results(self, req, resource_realm, terms):
        """Return a search result generator suitable for ISearchSource.

        Search results are attachments on resources of the given
        `resource_realm.realm` whose filename, description or author match
        the given terms.
        """
        with self.env.db_query as db:
            sql_query, args = search_to_sql(
                    db, ['filename', 'description', 'author'], terms)
            for id, time, filename, desc, author in db("""
                    SELECT id, time, filename, description, author
                    FROM attachment WHERE type = %s AND """ + sql_query,
                    (resource_realm.realm,) + args):
                attachment = resource_realm(id=id).child(self.realm, filename)
                if 'ATTACHMENT_VIEW' in req.perm(attachment):
                    yield (get_resource_url(self.env, attachment, req.href),
                           get_resource_shortname(self.env, attachment),
                           from_utimestamp(time), author,
                           shorten_result(desc, terms))
    def get_search_results(self, req, terms, filters):
        if not 'mailinglist' in filters:
            return
        mailinglist_realm = Resource('mailinglist')

        lists = {}
        for mailinglist in Mailinglist.select(self.env):
            if "MAILINGLIST_VIEW" in req.perm(mailinglist.resource):         
                lists[mailinglist.id] = mailinglist
                
        if not lists:
            self.log.debug("This user can't view any lists, so not searching.")
            return
        
        db = self.env.get_read_db()
        sql, args = search_to_sql(db, ['subject','body','from_email','from_name'], terms)

        cursor = db.cursor()
        query = """
            SELECT id, subject, body, from_name, from_email, date, list, conversation
            FROM mailinglistmessages
            WHERE list IN (%s) AND %s
            """ % (",".join(map(str,lists.keys())), sql,)
        self.log.debug("Search query: %s", query)
        cursor.execute(query, args)
        for mid, subject, body, from_name, from_email, date, mlist, conversation in cursor:
            # build resource ourself to speed things up
            m = mailinglist_realm(id="%s/%d/%d" % (lists[mlist].emailaddress,
                                                   conversation,
                                                   mid))
            if 'MAILINGLIST_VIEW' in req.perm(m):
                yield (req.href.mailinglist(m.id),
                       tag("%s: %s" % (lists[mlist].name, subject)),
                       datetime.fromtimestamp(date, utc),
                       "%s <%s>" % (from_name, from_email),
                       shorten_result(body, terms))
        
        # Attachments
        for result in AttachmentModule(self.env).get_search_results(
            req, mailinglist_realm, terms):
            yield result        
Exemplo n.º 26
0
def search_blog_posts(env, terms):
    """ Free text search for content of blog posts.
    Input is a list of terms.
    Returns a list of tuples with:
        (name, version, publish_time, author, title, body) """
    columns = [
        'bp1.name', 'bp1.title', 'bp1.body', 'bp1.author', 'bp1.categories'
    ]
    with env.db_query as db:
        search_clause, args = search_to_sql(db, columns, terms)
        return [(row[0], row[1], to_datetime(row[2],
                                             utc), row[3], row[4], row[5])
                for row in db(
                    """
                 SELECT bp1.name, bp1.version, bp1.publish_time, bp1.author,
                  bp1.title, bp1.body
                 FROM fullblog_posts bp1,
                  (SELECT name, max(version) AS ver
                   FROM fullblog_posts GROUP BY name) bp2
                 WHERE bp1.version = bp2.ver AND bp1.name = bp2.name
                 AND %s
                 """ % search_clause, args)]
Exemplo n.º 27
0
    def get_search_results(self, req, terms, filters):
        if not 'milestone' in filters:
            return
        with self.env.db_query as db:
            sql_query, args = search_to_sql(db, ['name', 'description'], terms)

            milestone_realm = Resource('milestone')
            for name, due, completed, description in db("""
                    SELECT name, due, completed, description FROM milestone
                    WHERE """ + sql_query, args):
                milestone = milestone_realm(id=name)
                if 'MILESTONE_VIEW' in req.perm(milestone):
                    dt = (from_utimestamp(completed) if completed else
                          from_utimestamp(due) if due else datetime.now(utc))
                    yield (get_resource_url(self.env, milestone, req.href),
                           get_resource_name(self.env, milestone), dt,
                           '', shorten_result(description, terms))
        
        # Attachments
        for result in AttachmentModule(self.env).get_search_results(
                req, milestone_realm, terms):
            yield result
Exemplo n.º 28
0
    def get_search_results(self, req, terms, filters):
        if 'mailarchive' in filters:
            db = self.env.get_db_cnx()
            sql_query, args = search_to_sql(db,
                                             ['m1.messageid', 'm1.subject', 'm1.fromname', 'm1.fromaddr', 'm1.text'],
                                             terms)
            cursor = db.cursor()
            cursor.execute("SELECT m1.id, m1.subject, m1.fromname, m1.fromaddr, m1.text, m1.utcdate as localdate "
                           "FROM mailarc m1 "
                           "WHERE "
                           "" + sql_query, args)
            mailarchive_realm = Resource('mailarchive')

            for id,subject,fromname,fromaddr, text,localdate in cursor:
                resource = mailarchive_realm(id=id,version=None)
                if 'MAILARCHIVE_VIEW' not in req.perm(resource):
                    continue

                yield (req.href.mailarchive(id),
                       subject,
                       datetime.fromtimestamp(localdate, utc),
                       get_author(fromname,fromaddr),
                       shorten_result(text, terms))
Exemplo n.º 29
0
 def get_search_results(self, req, resource_realm, terms):
     """Return a search result generator suitable for ISearchSource.
     
     Search results are attachments on resources of the given 
     `resource_realm.realm` whose filename, description or author match 
     the given terms.
     """
     db = self.env.get_db_cnx()
     sql_query, args = search_to_sql(db, ['filename', 'description', 
                                     'author'], terms)
     cursor = db.cursor()
     cursor.execute("SELECT id,time,filename,description,author "
                    "FROM attachment "
                    "WHERE type = %s "
                    "AND " + sql_query, (resource_realm.realm, ) + args)
     
     for id, time, filename, desc, author in cursor:
         attachment = resource_realm(id=id).child('attachment', filename)
         if 'ATTACHMENT_VIEW' in req.perm(attachment):
             yield (get_resource_url(self.env, attachment, req.href),
                    get_resource_shortname(self.env, attachment),
                    datetime.fromtimestamp(time, utc), author,
                    shorten_result(desc, terms))
Exemplo n.º 30
0
def search_blog_posts(env, terms):
    """ Free text search for content of blog posts.
    Input is a list of terms.
    Returns a list of tuples with:
        (name, version, publish_time, author, title, body) """
    assert terms
    cnx = env.get_db_cnx()
    cursor = cnx.cursor()
    # SQL
    columns = ['bp1.name', 'bp1.title', 'bp1.body',
               'bp1.author', 'bp1.categories']
    search_clause, args = search_to_sql(cnx, columns, terms)
    sql = "SELECT bp1.name, bp1.version, bp1.publish_time, bp1.author, " \
               "bp1.title, bp1.body " \
               "FROM fullblog_posts bp1," \
               "(SELECT name, max(version) AS ver " \
               "FROM fullblog_posts GROUP BY name) bp2 " \
               "WHERE bp1.version = bp2.ver AND bp1.name = bp2.name " \
               "AND " + search_clause
    env.log.debug("search_blog_posts() SQL: %r" % sql)
    cursor.execute(sql, args)
    # Return the items we have found
    return [(row[0], row[1], to_datetime(row[2], utc), row[3],
            row[4], row[5]) for row in cursor]
Exemplo n.º 31
0
    def get_search_results(self, req, terms, filters):
        if not 'wiki' in filters:
            return
        with self.env.db_query as db:
            sql_query, args = search_to_sql(db, ['w1.name', 'w1.author',
                                                 'w1.text'], terms)
            wiki_realm = Resource('wiki')
            for name, ts, author, text in db("""
                    SELECT w1.name, w1.time, w1.author, w1.text
                    FROM wiki w1,(SELECT name, max(version) AS ver
                                  FROM wiki GROUP BY name) w2
                    WHERE w1.version = w2.ver AND w1.name = w2.name
                    AND """ + sql_query, args):
                page = wiki_realm(id=name)
                if 'WIKI_VIEW' in req.perm(page):
                    yield (get_resource_url(self.env, page, req.href),
                           '%s: %s' % (name, shorten_line(text)),
                           from_utimestamp(ts), author,
                           shorten_result(text, terms))

        # Attachments
        for result in AttachmentModule(self.env).get_search_results(
            req, wiki_realm, terms):
            yield result
Exemplo n.º 32
0
    def get_search_results(self, req, terms, filters):
        if not 'milestone' in filters:
            return
        db = self.env.get_db_cnx()
        sql_query, args = search_to_sql(db, ['name', 'description'], terms)
        cursor = db.cursor()
        cursor.execute("SELECT name,due,completed,description "
                       "FROM milestone "
                       "WHERE " + sql_query, args)

        milestone_realm = Resource('milestone')
        for name, due, completed, description in cursor:
            milestone = milestone_realm(id=name)
            if 'MILESTONE_VIEW' in req.perm(milestone):
                dt = (completed and from_utimestamp(completed) or
                      due and from_utimestamp(due) or datetime.now(utc))
                yield (get_resource_url(self.env, milestone, req.href),
                       get_resource_name(self.env, milestone), dt,
                       '', shorten_result(description, terms))
        
        # Attachments
        for result in AttachmentModule(self.env).get_search_results(
            req, milestone_realm, terms):
            yield result