def search(collection, p, of, so, rm): """ Renders search pages. """ if 'action_browse' in request.args: return browse() from invenio.websearch_webinterface import wash_search_urlargd argd = argd_orig = wash_search_urlargd(request.args) argd['of'] = 'id' # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = current_user.get('rg') rg = int(argd['rg']) collection_breadcrumbs(collection) qid = get_search_query_id(**argd) recids = perform_request_search(req=request.get_legacy_request(), **argd) if so or rm: recids.reverse() ctx = dict( facets=FACETS.config(collection=collection, qid=qid), records=len(get_current_user_records_that_can_be_displayed(qid)), qid=qid, rg=rg, create_nearest_terms_box=lambda: _create_neareset_term_box(argd_orig), easy_search_form=EasySearchForm(csrf_enabled=False)) return response_formated_records(recids, collection, of, **ctx)
def browse(collection, p, f, of, so, rm, rg, jrec): from invenio.websearch_webinterface import wash_search_urlargd argd_orig = wash_search_urlargd(request.args) collection_breadcrumbs(collection) colls = [collection.name] + request.args.getlist('c') if f is None and ':' in p[1:]: f, p = string.split(p, ":", 1) records = map( lambda (r, h): (r.decode('utf-8'), h), browse_pattern_phrases(req=request.get_legacy_request(), colls=colls, p=p, f=f, rg=rg, ln=g.ln)) @register_template_context_processor def index_context(): return dict( collection=collection, create_nearest_terms_box=lambda: _create_neareset_term_box( argd_orig), pagination=Pagination(int(ceil(jrec / float(rg))), rg, len(records)), rg=rg, p=p, f=f, easy_search_form=EasySearchForm(csrf_enabled=False), ) return dict(records=records)
def search(collection, p, of, so, rm): """ Renders search pages. """ if 'action_browse' in request.args \ or request.args.get('action', '') == 'browse': return browse() if 'c' in request.args and len(request.args) == 1 \ and len(request.args.getlist('c')) == 1: return redirect(url_for('.collection', name=request.args.get('c'))) from invenio.websearch_webinterface import wash_search_urlargd argd = argd_orig = wash_search_urlargd(request.args) argd['of'] = 'id' # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = current_user.get('rg') rg = int(argd['rg']) collection_breadcrumbs(collection) qid = get_search_query_id(**argd) recids = perform_request_search(req=request.get_legacy_request(), **argd) #if so or rm: if len(of) > 0 and of[0] == 'h': recids.reverse() # back-to-search related code if request and not isinstance(request.get_legacy_request(), cStringIO.OutputType): # store the last search results page session['websearch-last-query'] = request.get_legacy_request( ).unparsed_uri if len(recids) > CFG_WEBSEARCH_PREV_NEXT_HIT_LIMIT: last_query_hits = None else: last_query_hits = recids # store list of results if user wants to display hits # in a single list, or store list of collections of records # if user displays hits split by collections: session["websearch-last-query-hits"] = last_query_hits ctx = dict( facets=FACETS.config(collection=collection, qid=qid), records=len(get_current_user_records_that_can_be_displayed(qid)), qid=qid, rg=rg, create_nearest_terms_box=lambda: _create_neareset_term_box(argd_orig), easy_search_form=EasySearchForm(csrf_enabled=False)) return response_formated_records(recids, collection, of, **ctx)
def rss(collection, p, jrec, so, rm): of = 'xr' argd = argd_orig = wash_search_urlargd(request.args) argd['of'] = 'id' # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = current_user.get('rg') rg = int(argd['rg']) qid = get_search_query_id(**argd) recids = perform_request_search(req=request.get_legacy_request(), **argd) if so or rm: recids.reverse() ctx = dict(records=len( get_current_user_records_that_can_be_displayed(qid)), qid=qid, rg=rg) return response_formated_records(recids, collection, of, **ctx)
def search(): """ Renders search pages. @FIXME: add parameter stream=True """ uid = current_user.get_id() #url_args = SearchUrlargs(user=user, session=session, **request.args) name = request.args.get('cc') if name: collection = Collection.query.filter(Collection.name == name).first_or_404() else: collection = Collection.query.get_or_404(1) if collection.is_restricted: (auth_code, auth_msg) = acc_authorize_action(uid, VIEWRESTRCOLL, collection=collection.name) if auth_code and current_user.is_guest: return redirect(url_for('webaccount.login', referer=request.url)) elif auth_code: return abort(401) from invenio.websearch_webinterface import wash_search_urlargd argd = argd_orig = wash_search_urlargd(request.args) argd['of'] = 'id' #FIXME b = [] def _crumb_builder(collection): qargs = request.args.to_dict() qargs['cc'] = collection.name return (collection.name_ln, 'search.search', qargs) if collection.id > 1: qargs = request.args.to_dict() qargs['cc'] = Collection.query.get_or_404(1).name b = get_collection_breadcrumbs(collection, [ (_('Home'), 'search.search', qargs)], builder=_crumb_builder) current_app.config['breadcrumbs_map'][request.endpoint] = b rg = request.args.get('rg', 10, type=int) page = request.args.get('jrec', 1, type=int) qid = get_search_query_id(**argd) recids = perform_request_search(req=request, **argd) if (argd_orig.get('so') or argd_orig.get('rm')): recids.reverse() FACET_SORTED_LIST = current_app.config.get('FACET_SORTED_LIST', []) facets = map(lambda x: x.get_conf(collection=collection, qid=qid), FACET_SORTED_LIST) @register_template_context_processor def index_context(): return dict(collection=collection, facets=facets, RecordInfo=RecordInfo, create_nearest_terms_box=lambda: _create_neareset_term_box(argd_orig), pagination=Pagination(int(ceil(page / float(rg))), rg, len(recids)), rg=rg, qid=qid, easy_search_form=EasySearchForm(csrf_enabled=False), format_record=cached_format_record, #FIXME: move to DB layer export_formats=get_export_formats()) return dict(recids=recids)
def urlArgs(url): url_split=urlparse.urlparse(url)[4] #print url_split argd = wash_search_urlargd(cgi.parse_qs(url_split)) argd['of']="id" return argd