def generic(idx, qs=None, q=None, limit=5, parser=None, page=1): if qs is q is None: raise ValueError('cannot have a null querystring and query') if parser is None: parser = MultifieldParser( ['title', 'keywords', 'summary', 'content', 'author'], idx.schema, group=OrGroup) # add better date parsing support parser.add_plugin(DateParserPlugin()) parser.remove_plugin_class(WildcardPlugin) with idx.searcher() as search: # generate the Query object if qs: query = parser.parse(qs) else: query = q facet = MultiFacet() facet.add_score() facet.add_field('modified', reverse=True) facet.add_field('title') results = search.search_page(query, pagenum=page, sortedby=facet, pagelen=limit) res = clean_results(idx, results, query) # pagination attributes on `search_page` method res.page_number = results.pagenum # current page number res.page_total = results.pagecount # total pages in results res.offset = results.offset # first result of current page res.pagelen = results.pagelen # the number of max results per page return res
def __init__(self, path): self.idxpath = path self.ix = open_dir(self.idxpath) self.query = MultifieldParser(['content', 'ctime'], schema=self.ix.schema) self.query.add_plugin(DateParserPlugin()) self.sorter = MultiFacet(["ctime", ScoreFacet()]) self.parser = ttp.Parser() self.dateparser = parser.parser()
def agruparLista(groupDic): grupo = {} keys = groupDic.keys() if not (groupDic): return None else: if 'precio' in keys and 'graduacion' in keys: precioFacet = getPrecioFacet(groupDic["precio"]) graduacionFacet = getGraduacionFacet(groupDic["graduacion"]) multifaceta = MultiFacet([precioFacet, graduacionFacet]) grupo = {"precio/graduacion": multifaceta} elif 'precio' not in keys and 'graduacion' in keys: grupo = {'graduacion': getGraduacionFacet(groupDic["graduacion"])} elif 'precio' in keys and 'graduacion' not in keys: grupo = {'precio': getPrecioFacet(groupDic["precio"])} return grupo
year = NUMERIC(stored=True) month = NUMERIC(stored=True) day = NUMERIC(stored=True) review = BOOLEAN(stored=True) journal = STORED volume = STORED pages = STORED ix = index.create_in(settings.ABSTRACT_INDEX_PATH, Schema) # query parser and searcher parser = MultifieldParser(fieldnames=("title", "abstract"), schema=ix.schema) searcher = ix.searcher(weighting=BM25F) # facet object for sorting abstracts by date (some have years but not dates) datefacet = MultiFacet() datefacet.add_field("year") datefacet.add_field("month") datefacet.add_field("day") def cachekey(keywords="", genes=(), genehomologs=True): """Return a key to use for cached query results""" if genes is None: genes = () if keywords is None: keywords = "" return "query_k:{0}_g:{1}_h:{2}".format(keywords.replace(" ", "_"), hash(genes), genehomologs)
review = BOOLEAN(stored=True) journal = STORED volume = STORED pages = STORED ix = index.create_in(ABSTRACT_INDEX_PATH, Schema) # query parser and searcher parser = QueryParser('abstract',ix.schema) parser.add_plugin(PhrasePlugin) searcher = ix.searcher(weighting=BM25F) # facet object for sorting abstracts by date (some have years but not dates) datefacet = MultiFacet() datefacet.add_field('year') datefacet.add_field('month') datefacet.add_field('day') #Builds Query def buildquery(keywords=None): # get keyword branch of query print "keywords (buildquery input) ==", keywords keywords = keywords.decode("utf-8") #print "Keyword in Unicode ==", unicode(keywords) keywordbranch = parser.parse(unicode(keywords)) if keywords else NullQuery() #print "keywordbranch (buildquery, pre-score) ==", keywordbranch