Esempio n. 1
0
 def shifts(self, start=None, end=None, limit=25, filter=False, query=None):
     from server.models.shift import Shift
     db = core.connect("shiftspace/shared")
     if not filter:
         if not start:
             start = [self.id]
         if not end:
             end = [self.id, {}]
         results = Shift.by_user_and_created(db, limit=limit)
         return Shift.joinData(core.objects(results[start:end]))
     else:
         lucene = core.lucene()
         queryString = "createdBy:%s" % self.id
         theFilter = core.dictToQuery(query)
         if theFilter:
             queryString = queryString + " AND " + theFilter
         try:
             print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
             print queryString
             rows = lucene.search(db, "shifts", q=queryString, include_docs=True, sort="\modified")
         except Exception, err:
             print err
             return []
         shifts = [row["doc"] for row in rows]
         return Shift.joinData(shifts, self.id)
Esempio n. 2
0
 def shifts(self, start=None, end=None, limit=25, filter=False, query=None):
     from server.models.shift import Shift
     db = core.connect("shiftspace/shared")
     if not filter:
         if not start:
             start = [self.id]
         if not end:
             end = [self.id, {}]
         results = Shift.by_user_and_created(db, limit=limit)
         return Shift.joinData(core.objects(results[start:end]))
     else:
         lucene = core.lucene()
         queryString = "createdBy:%s" % self.id
         theFilter = core.dictToQuery(query)
         if theFilter:
             queryString = queryString + " AND " + theFilter
         try:
             print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
             print queryString
             rows = lucene.search(db,
                                  "shifts",
                                  q=queryString,
                                  include_docs=True,
                                  sort="\modified")
         except Exception, err:
             print err
             return []
         shifts = [row["doc"] for row in rows]
         return Shift.joinData(shifts, self.id)
Esempio n. 3
0
    def shifts(cls, user, byHref=None, byDomain=None, byFollowing=False, byGroups=False, bySpace=None, start=0, limit=25, filter=False, query=None, all=False):
        from server.models.ssuser import SSUser
        db = core.connect("shiftspace/shared")
        lucene = core.lucene()
        queryString = ""
        # TODO: validate all fields - David
        
        if byHref or byDomain:
            if byHref:
                queryString = "hrefExact:\"%s_HREF_EXACT\"" % byHref
            elif byDomain:
                queryString = "domain:\"%s\""% byDomain
            if bySpace:
                queryString = queryString + " spaceName:" + bySpace
            queryString = queryString + " AND ((draft:false AND private:false)"
            if user:
                queryString = queryString + " OR createdBy:%s" % user.id
                dbs = user.readable()
                dbs.append(SSUser.db(user.id))
                dbsStr = " ".join(dbs)
                queryString = queryString + ((" OR (draft:false%s)" % ((len(dbs) > 0 and (" AND dbs:(%s)" % dbsStr)) or "")))
            queryString = queryString + ")"
        elif byFollowing:
            from server.models.follow import Follow
            # FIXME: impossible to make this scale in a simple way for many followers w/o p2p - David 12/2/09
            # when p2p we can tag the shift as a follow shift when we get it
            results = Follow.following_by_created(core.connect())
            following = " ".join(core.values(results[[user.id]:[user.id, {}]]))
            queryString = "(draft:false AND private:false AND createdBy:(%s)) OR dbs:(%s)" % (following, SSUser.db(user.id))
        elif byGroups:
            from server.models.group import Group
            queryString = "dbs:(%s)" % " ".join(user.readable())
        if filter:
            queryString = queryString + " AND " + core.dictToQuery(query)

        print queryString
        try:
            if all:
                rows = lucene.search(db, "shifts", q=queryString, include_docs=True, sort="\modified")
            else:
                rows = lucene.search(db, "shifts", q=queryString, include_docs=True, sort="\modified", skip=start, limit=limit)
        except Exception, err:
            print err
            return []
Esempio n. 4
0
    def shifts(cls,
               user,
               byHref=None,
               byDomain=None,
               byFollowing=False,
               byGroups=False,
               bySpace=None,
               start=0,
               limit=25,
               filter=False,
               query=None,
               all=False):
        from server.models.ssuser import SSUser
        db = core.connect("shiftspace/shared")
        lucene = core.lucene()
        queryString = ""
        # TODO: validate all fields - David

        if byHref or byDomain:
            if byHref:
                queryString = "hrefExact:\"%s_HREF_EXACT\"" % byHref
            elif byDomain:
                queryString = "domain:\"%s\"" % byDomain
            if bySpace:
                queryString = queryString + " spaceName:" + bySpace
            queryString = queryString + " AND ((draft:false AND private:false)"
            if user:
                queryString = queryString + " OR createdBy:%s" % user.id
                dbs = user.readable()
                dbs.append(SSUser.db(user.id))
                dbsStr = " ".join(dbs)
                queryString = queryString + ((" OR (draft:false%s)" % (
                    (len(dbs) > 0 and (" AND dbs:(%s)" % dbsStr)) or "")))
            queryString = queryString + ")"
        elif byFollowing:
            from server.models.follow import Follow
            # FIXME: impossible to make this scale in a simple way for many followers w/o p2p - David 12/2/09
            # when p2p we can tag the shift as a follow shift when we get it
            results = Follow.following_by_created(core.connect())
            following = " ".join(core.values(results[[user.id]:[user.id, {}]]))
            queryString = "(draft:false AND private:false AND createdBy:(%s)) OR dbs:(%s)" % (
                following, SSUser.db(user.id))
        elif byGroups:
            from server.models.group import Group
            queryString = "dbs:(%s)" % " ".join(user.readable())
        if filter:
            queryString = queryString + " AND " + core.dictToQuery(query)

        print queryString
        try:
            if all:
                rows = lucene.search(db,
                                     "shifts",
                                     q=queryString,
                                     include_docs=True,
                                     sort="\modified")
            else:
                rows = lucene.search(db,
                                     "shifts",
                                     q=queryString,
                                     include_docs=True,
                                     sort="\modified",
                                     skip=start,
                                     limit=limit)
        except Exception, err:
            print err
            return []