(self, session, entities, arglist)
return finalquery
Each entity-filter pair will be made into a separate query
         and they will be all intersected together
Each entity-filter pair will be made into a separate query
         and they will be all intersected together
Each entity - filter pair will be made into a separate query and they will be all intersected together
def buildQuery(self, session, entities, arglist):
        """
         Each entity-filter pair will be made into a separate query
         and they will be all intersected together
        """

        entity = arglist[-1]
        querylist = []
        #To build up the query, bridge every entity to a comic table
        querybase = session.query(entities[entity])
        if len(arglist) != 1:
            if entity == 'roles':
                querybase = querybase.join(Credit).join(Comic)
            if entity == 'persons':
                querybase = querybase.join(Credit).join(Comic)
            if entity == 'characters':
                querybase = querybase.join(comics_characters_table).join(Comic)
            if entity == 'teams':
                querybase = querybase.join(comics_teams_table).join(Comic)
            if entity == 'storyarcs':
                querybase = querybase.join(comics_storyarcs_table).join(Comic)
            if entity == 'genres':
                querybase = querybase.join(comics_genres_table).join(Comic)
            if entity == 'locations':
                querybase = querybase.join(comics_locations_table).join(Comic)
            if entity == 'generictags':
                querybase = querybase.join(comics_generictags_table).join(Comic)
        
        #print "Result entity is====>", entity
        #iterate over list, 2 at a time, building query list,
        #print zip(arglist[0::2], arglist[1::2])
        for e,v in zip(arglist[0::2], arglist[1::2]):
            #print "--->",e,v
            query = querybase
            if e == 'roles':
                if entity != 'persons':
                    query = query.join(Credit)
                query = query.join(Role)
            if e == 'persons':
                if entity != 'roles':
                    query = query.join(Credit)
                query = query.join(Person)
            if e == 'characters':
                query = query.join(comics_characters_table).join(Character)
            if e == 'teams':
                query = query.join(comics_teams_table).join(Team)
            if e == 'storyarcs':
                query = query.join(comics_storyarcs_table).join(StoryArc)
            if e == 'genres':
                query = query.join(comics_genres_table).join(Genre)
            if e == 'locations':
                query = query.join(comics_locations_table).join(Location)
            if e == 'generictags':
                query = query.join(comics_generictags_table).join(GenericTag)
            query = query.filter(entities[e]==v)
            querylist.append(query)
            #print query
                        
        if len(querylist) == 0:
            finalquery = querybase
        else:
            finalquery = querylist[0].intersect(*querylist[1:])
            
        return finalquery
def buildQuery ( self , session , entities , arglist ) : entity = arglist [ - 1 ] querylist = [ ] #To build up the query, bridge every entity to a comic table querybase = session . query ( entities [ entity ] ) if len ( arglist ) != 1 : if entity == 'roles' : querybase = querybase . join ( Credit ) . join ( Comic ) if entity == 'persons' : querybase = querybase . join ( Credit ) . join ( Comic ) if entity == 'characters' : querybase = querybase . join ( comics_characters_table ) . join ( Comic ) if entity == 'teams' : querybase = querybase . join ( comics_teams_table ) . join ( Comic ) if entity == 'storyarcs' : querybase = querybase . join ( comics_storyarcs_table ) . join ( Comic ) if entity == 'genres' : querybase = querybase . join ( comics_genres_table ) . join ( Comic ) if entity == 'locations' : querybase = querybase . join ( comics_locations_table ) . join ( Comic ) if entity == 'generictags' : querybase = querybase . join ( comics_generictags_table ) . join ( Comic ) #print "Result entity is====>", entity #iterate over list, 2 at a time, building query list, #print zip(arglist[0::2], arglist[1::2]) for e , v in zip ( arglist [ 0 : : 2 ] , arglist [ 1 : : 2 ] ) : #print "--->",e,v query = querybase if e == 'roles' : if entity != 'persons' : query = query . join ( Credit ) query = query . join ( Role ) if e == 'persons' : if entity != 'roles' : query = query . join ( Credit ) query = query . join ( Person ) if e == 'characters' : query = query . join ( comics_characters_table ) . join ( Character ) if e == 'teams' : query = query . join ( comics_teams_table ) . join ( Team ) if e == 'storyarcs' : query = query . join ( comics_storyarcs_table ) . join ( StoryArc ) if e == 'genres' : query = query . join ( comics_genres_table ) . join ( Genre ) if e == 'locations' : query = query . join ( comics_locations_table ) . join ( Location ) if e == 'generictags' : query = query . join ( comics_generictags_table ) . join ( GenericTag ) query = query . filter ( entities [ e ] == v ) querylist . append ( query ) #print query if len ( querylist ) == 0 : finalquery = querybase else : finalquery = querylist [ 0 ] . intersect ( * querylist [ 1 : ] ) return finalquery