Exemple #1
0
    def count(self, string):
        w = search.build_where(string)

        c = self.db.execute("SELECT COUNT(*) "
                            "FROM messages, messages_fts "
                            "WHERE messages.rowid = messages_fts.rowid AND "
                            "(%s)" % w.sql, w.args)
        return c.fetchone()[0]
Exemple #2
0
    def search(self, string, offset = 0, limit = 1000):
        w = search.build_where(string)
        w.args.extend([offset, limit])

        return self.db.execute("SELECT subject, messages_fts.'from' AS 'from', "
                               "date, path, offset, length "
                               "FROM messages, messages_fts "
                               "WHERE messages.rowid = messages_fts.rowid AND "
                               "(%s) ORDER BY date DESC LIMIT ?, ?" % w.sql,
                               w.args)
Exemple #3
0
def callback(query, db):
    try:
        w = search.build_where(query)
    except search.SearchException as e:
        return bottle.HTTPError(400, e)

    if w.merge:
        w.sql = "SELECT preso, slide FROM presos, slides WHERE (presos.path = slides.preso) AND %s GROUP BY checksum ORDER BY presomtime DESC, preso, slide LIMIT 500" % w.sql
    else:
        w.sql = "SELECT preso, slide FROM presos, slides WHERE (presos.path = slides.preso) AND %s ORDER BY presomtime DESC, preso, slide" % w.sql
    c = db.execute(w.sql, w.args)

    entries = []
    for row in c:
        p = row["preso"].replace("\t", "%09").replace('"', "%22").replace("#", "%23").replace('?', "%3F")
        entries.append({"src": "static/thumbs/%s/%03u.jpg" % (p, row["slide"]),
                        "preso": "/" + row["preso"],
                        "slide": row["slide"],
                        "png": "static/slides/%s/%03u.png" % (p, row["slide"])
                    })
        
    bottle.response.content_type = "application/json"
    return json.dumps(entries)
Exemple #4
0
 def GET(self, query):
     try:
         w = search.build_where(query)
     except search.SearchException, e:
         return error(e)