Пример #1
0
def search(query, params, offset, per_page=20):
    """ external search method, performs the search and builds the results page
        parameters: 
            query - string - query to be performed 
            params - string - parameters coming off sidebar search
            offset - int - offset of results on page vs per_page amount
            per_page - int - # of results per page
        returns: results page
        """
    if DEBUG:
        print "Flickr search initializing"
    if not query and not params:
        return Result(0,1), {}
    
    offset, page = modulate_offset(int(offset), per_page)
    next_offset = offset + per_page
    page = offset/per_page +1 

    retrieved_response, args = _perform_search(query, params, page, per_page)
    hits = _count(retrieved_response)

    result = Result(hits, next_offset)    
    response_json = retrieved_response
    results = response_json["photos"]["photo"]
    
    result_object = _build_result(result, results)
    return result_object, args    
Пример #2
0
def search(query, params, offset, per_page=20):
    if DEBUG:
        print "CA SEARCH INITIATING"
    if not query and not params: 
        return Result(0,1),{}

    offset, page = modulate_offset(int(offset), per_page)    
    retrieved_response, args = _perform_request(query, params)
    hits =  _count(retrieved_response)
    next_offset = offset + per_page
    page = offset/per_page +1

    result = Result(hits, next_offset)
    response_json = retrieved_response.json()
    results = response_json["results"]
    for iobject in results:
        thumbnail_url = iobject[PREVIEW_MEDIA]
        original_url = iobject[ORIGINAL_MEDIA]
        title = iobject[TITLE]
        objID = iobject[ID]
        image = ResultImage(original_url, thumbnail_url, title, objID)
        result.addImage(image)
    return result, args