def _queries(): """Preprocess collection queries.""" from invenio.ext.sqlalchemy import db from invenio.modules.collections.models import Collection return dict( (collection.name, dict(query=SearchEngine( COLLECTIONS_DELETED_RECORDS.format(dbquery=collection.dbquery)), ancestors=set(c.name for c in collection.ancestors if c.dbquery is None))) for collection in Collection.query.filter( Collection.dbquery != None, db.not_(Collection.dbquery.like('hostedcollection:%'))).all())
def search_pattern(req=None, p=None, f=None, m=None, ap=0, of="id", verbose=0, ln=CFG_SITE_LANG, display_nearest_terms_box=True, wl=0): """Search for complex pattern 'p' within field 'f' according to matching type 'm'. Return hitset of recIDs. The function uses multi-stage searching algorithm in case of no exact match found. See the Search Internals document for detailed description. The 'ap' argument governs whether an alternative patterns are to be used in case there is no direct hit for (p,f,m). For example, whether to replace non-alphanumeric characters by spaces if it would give some hits. See the Search Internals document for detailed description. (ap=0 forbits the alternative pattern usage, ap=1 permits it.) 'ap' is also internally used for allowing hidden tag search (for requests coming from webcoll, for example). In this case ap=-9 The 'of' argument governs whether to print or not some information to the user in case of no match found. (Usually it prints the information in case of HTML formats, otherwise it's silent). The 'verbose' argument controls the level of debugging information to be printed (0=least, 9=most). All the parameters are assumed to have been previously washed. This function is suitable as a mid-level API. """ if f is None: from invenio.modules.search.api import SearchEngine results = SearchEngine(p).search() else: results = search_unit(p, f, m, wl=wl) import warnings warnings.warn( 'Deprecated search_pattern(p={0}, f={1}, m={2}) = {3}.'.format( p, f, m, results), stacklevel=2) return results
def get_unique_record_json(param): """API to query records from the database.""" from invenio.modules.search.api import SearchEngine data, query = {}, {} data['status'] = 'notfound' recid = SearchEngine(param).search() if len(recid) == 1: query = get_record(recid[0]).dumps(clean=True) data['status'] = 'success' elif len(recid) > 1: data['status'] = 'multiplefound' data['source'] = 'database' data['query'] = query return data
def perform_request_search(req=None, cc=CFG_SITE_NAME, c=None, p="", f="", rg=None, sf="", so="a", sp="", rm="", of="id", ot="", aas=0, p1="", f1="", m1="", op1="", p2="", f2="", m2="", op2="", p3="", f3="", m3="", sc=0, jrec=0, recid=-1, recidb=-1, sysno="", id=-1, idb=-1, sysnb="", action="", d1="", d1y=0, d1m=0, d1d=0, d2="", d2y=0, d2m=0, d2d=0, dt="", verbose=0, ap=0, ln=CFG_SITE_LANG, ec=None, tab="", wl=0, em=""): kwargs = prs_wash_arguments(req=req, cc=cc, c=c, p=p, f=f, rg=rg, sf=sf, so=so, sp=sp, rm=rm, of=of, ot=ot, aas=aas, p1=p1, f1=f1, m1=m1, op1=op1, p2=p2, f2=f2, m2=m2, op2=op2, p3=p3, f3=f3, m3=m3, sc=sc, jrec=jrec, recid=recid, recidb=recidb, sysno=sysno, id=id, idb=idb, sysnb=sysnb, action=action, d1=d1, d1y=d1y, d1m=d1m, d1d=d1d, d2=d2, d2y=d2y, d2m=d2m, d2d=d2d, dt=dt, verbose=verbose, ap=ap, ln=ln, ec=ec, tab=tab, wl=wl, em=em) import warnings warnings.warn('Deprecated perform_request_search({}).'.format(str(kwargs)), stacklevel=2) from invenio.modules.search.api import SearchEngine p = create_add_to_search_pattern(p, p1, f1, m1, "") p = create_add_to_search_pattern(p, p2, f2, m2, op1) p = create_add_to_search_pattern(p, p3, f3, m3, op2) return SearchEngine(p).search(collection=cc)
def get_fulltext_terms_from_search_pattern(search_pattern): """Return fulltext terms from search pattern.""" from invenio.modules.search.api import SearchEngine return SearchEngine(search_pattern).terms(keywords=['fulltext'])