def search(collection, p, of, ot, so, rm): """Render search page.""" from invenio.legacy.search_engine import perform_request_search 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'))) argd = argd_orig = wash_search_urlargd(request.args) argd['of'] = 'id' # fix for queries like `/search?p=+ellis` if 'p' in argd: argd['p'] = argd['p'].strip() # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = int(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) # 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 hit_limit = current_app.config['CFG_WEBSEARCH_PREV_NEXT_HIT_LIMIT'] if len(recids) > 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.get_facets_config(collection, 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), ot=ot) return response_formated_records(recids, collection, of, **ctx)
def search(collection, p, of, ot, so, rm): """Render search page.""" from invenio.legacy.search_engine import perform_request_search 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'))) argd = argd_orig = wash_search_urlargd(request.args) argd['of'] = 'id' # fix for queries like `/search?p=+ellis` if 'p' in argd: argd['p'] = argd['p'].strip() # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = int(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) # 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 hit_limit = current_app.config['CFG_WEBSEARCH_PREV_NEXT_HIT_LIMIT'] if len(recids) > 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.get_facets_config(collection, 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), ot=ot ) return response_formated_records(recids, collection, of, **ctx)
def search(collection, p, of, ot, so, sf, sp, rm): """Render search page.""" 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'))) if 'f' in request.args: args = request.args.copy() args['p'] = "{0}:{1}".format(args['f'], args['p']) del args['f'] return redirect('.search', **args) argd = argd_orig = wash_search_urlargd(request.args) # fix for queries like `/search?p=+ellis` p = p.strip().encode('utf-8') jrec = request.values.get('jrec', 1, type=int) # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = int(current_user.get('rg')) rg = int(argd['rg']) collection_breadcrumbs(collection) qid = get_search_query_id(p=p, cc=collection.name) recids = Query(p).search(collection=collection.name) records = len(recids) recids = sort_and_rank_records(recids, so=so, rm=rm, sf=sf, sp=sp, p=p, of='id', rg=rg, jrec=jrec) # 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 hit_limit = current_app.config['CFG_WEBSEARCH_PREV_NEXT_HIT_LIMIT'] if len(recids) > 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.get_facets_config(collection, qid), records=records, rg=rg, create_nearest_terms_box=lambda: _create_neareset_term_box(argd_orig), easy_search_form=EasySearchForm(csrf_enabled=False), ot=ot ) # TODO add search services # # WebSearch services # from invenio.modules.search import services # if jrec <= 1 and \ # (em == "" and True or (EM_REPOSITORY["search_services"] in em)): # user_info = collect_user_info(req) # # display only on first search page, and only if wanted # # when 'em' param set. # for answer_relevance, answer_html in services.get_answers( # req, user_info, of, cc, colls_to_search, p, f, ln): # req.write('<div class="searchservicebox">') # req.write(answer_html) # if verbose > 8: # write_warning("Service relevance: %i" % # answer_relevance, req=req) # req.write('</div>') # TODO add external collection search # if not of in ['hcs', 'hcs2']: # perform_external_collection_search_with_em( # req, cc, [p, p1, p2, p3], f, ec, verbose, # ln, selected_external_collections_infos, em=em) return response_formated_records(recids, collection, of, **ctx)
def search(collection, p, of, ot, so, sf, sp, rm): """Render search page.""" 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'))) if 'f' in request.args: args = request.args.copy() args['p'] = "{0}:{1}".format(args['f'], args['p']) del args['f'] return redirect('.search', **args) argd = argd_orig = wash_search_urlargd(request.args) # fix for queries like `/search?p=+ellis` p = p.strip().encode('utf-8') jrec = request.values.get('jrec', 1, type=int) # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = int(current_user.get('rg')) rg = int(argd['rg']) collection_breadcrumbs(collection) qid = get_search_query_id(p=p, cc=collection.name) recids = Query(p).search(collection=collection.name) records = len(recids) recids = sort_and_rank_records(recids, so=so, rm=rm, sf=sf, sp=sp, p=p, of='id', rg=rg, jrec=jrec) # 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 hit_limit = current_app.config['CFG_WEBSEARCH_PREV_NEXT_HIT_LIMIT'] if len(recids) > 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.get_facets_config(collection, qid), records=records, rg=rg, create_nearest_terms_box=lambda: _create_neareset_term_box(argd_orig), easy_search_form=EasySearchForm(csrf_enabled=False), ot=ot) # TODO add search services # # WebSearch services # from invenio.modules.search import services # if jrec <= 1 and \ # (em == "" and True or (EM_REPOSITORY["search_services"] in em)): # user_info = collect_user_info(req) # # display only on first search page, and only if wanted # # when 'em' param set. # for answer_relevance, answer_html in services.get_answers( # req, user_info, of, cc, colls_to_search, p, f, ln): # req.write('<div class="searchservicebox">') # req.write(answer_html) # if verbose > 8: # write_warning("Service relevance: %i" % # answer_relevance, req=req) # req.write('</div>') # TODO add external collection search # if not of in ['hcs', 'hcs2']: # perform_external_collection_search_with_em( # req, cc, [p, p1, p2, p3], f, ec, verbose, # ln, selected_external_collections_infos, em=em) return response_formated_records(recids, collection, of, **ctx)