本文整理汇总了Python中whoosh.qparser.QueryParser类的典型用法代码示例。如果您正苦于以下问题:Python QueryParser类的具体用法?Python QueryParser怎么用?Python QueryParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QueryParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: numeroDeCorreos2
def numeroDeCorreos2(var):
with ix.searcher() as searcher:
query = QueryParser("name", ix2.schema)
qp = query.parse(unicode(var))
with ix2.searcher() as s:
results = s.search(qp)
mail = results[0]["mail"]
query = QueryParser("mailTo", ix.schema).parse(mail)
results = searcher.search(query)
panel = Tkinter.Toplevel()
scrollbar = Tkinter.Scrollbar(panel)
scrollbar.pack(side=Tkinter.RIGHT, fill=Tkinter.Y)
listado = Tkinter.Text(panel, width=150, height=30, yscrollcommand=scrollbar.set)
i = 1
for result in results:
listado.insert(Tkinter.INSERT, "Mail from: " + result["mailFrom"])
listado.insert(Tkinter.INSERT, "Mail to: " + result["mailTo"])
listado.insert(Tkinter.INSERT, "Subject: " + result["subject"])
date = result["date"]
listado.insert(Tkinter.INSERT, "Date: " + date[:4] + "-" + date[4:6] + "-" + date[6:])
listado.insert(Tkinter.INSERT, "Content: ")
content = re.findall("'([^']*)'", result["content"])
last = content[-1]
i += 1
for line in content:
if line is not last:
line = line[:-2]
listado.insert(Tkinter.INSERT, line + "\n")
listado.insert(Tkinter.INSERT, "\n")
listado.insert(Tkinter.INSERT, "Este remitente ha enviado " + str(i - 1) + " correos.")
scrollbar.config(command=listado.yview)
listado.pack()
开发者ID:albbosgom,项目名称:practicas-aii,代码行数:33,代码来源:practica7.py
示例2: searchNote
def searchNote(self):
""" Sorting criteria: "title > path > content"
Search matches are organized into html source.
"""
pattern = self.searchEdit.text()
if not pattern:
return
results = []
print("Searching using", pattern)
with self.ix.searcher() as searcher:
matches = []
for f in ["title", "path", "content"]:
queryp = QueryParser(f, self.ix.schema)
queryp.add_plugin(RegexPlugin())
# r"pattern" is the desired regex term format
query = queryp.parse('r"' + pattern + '"')
ms = searcher.search(query, limit=None) # default limit is 10!
for m in ms:
if not m in matches:
matches.append(m)
for r in matches:
title = r['title']
path = r['path']
term = r.highlights("content")
results.append([title, path, term])
html = ""
for title, path, hi in results:
html += ("<p><a href='" + path + "'>" + title +
"</a><br/><span class='path'>" +
path + "</span><br/>" + hi + "</p>")
self.searchView.setHtml(html)
print("Finished searching", pattern)
开发者ID:kissthink,项目名称:mikidown,代码行数:35,代码来源:mikiwindow.py
示例3: test_wildcard_existing_terms
def test_wildcard_existing_terms():
s = fields.Schema(key=fields.ID, value=fields.TEXT)
ix = RamStorage().create_index(s)
w = ix.writer()
w.add_document(key=u("a"), value=u("alfa bravo bear charlie delta"))
w.add_document(key=u("a"), value=u("boggle echo render rendering renders"))
w.commit()
r = ix.reader()
qp = QueryParser("value", ix.schema)
def words(terms):
z = []
for t in terms:
assert t[0] == "value"
z.append(t[1])
return " ".join(sorted(z))
q = qp.parse(u("b*"))
ts = q.existing_terms(r)
assert_equal(ts, set())
ts = q.existing_terms(r, expand=True)
assert_equal(words(ts), "bear boggle bravo")
q = qp.parse(u("[a TO f]"))
ts = q.existing_terms(r)
assert_equal(ts, set())
ts = q.existing_terms(r, expand=True)
assert_equal(words(ts), "alfa bear boggle bravo charlie delta echo")
q = query.Variations("value", "render")
ts = q.existing_terms(r, expand=False)
assert_equal(ts, set())
ts = q.existing_terms(r, expand=True)
assert_equal(words(ts), "render rendering renders")
开发者ID:ChimmyTee,项目名称:oh-mainline,代码行数:35,代码来源:test_queries.py
示例4: populateTable
def populateTable(self, searchterm=None):
self.infoTable.clear()
self.infoTable.setHorizontalHeaderLabels( [ "Title", "Authors", "Tags", "Year", "Read" ] )
self.infoTable.setRowCount(0)
self.infoTable.horizontalHeader().setResizeMode(0, QHeaderView.Stretch)
self.infoTable.verticalHeader().hide()
if( searchterm == None or searchterm == "" ):
papers = KKDocument.objects.all()
for p in papers:
a = ', '.join([x.name for x in p.authors.all()])
t = ', '.join([x.tag for x in p.tags.all()])
self.newEntry(p.title, a, t, p.year, p)
return # were done here - all papers printed
# only if there is a searchterm:
# search full text with whoosh
print "FINDING %s" % searchterm
searcher = self.whoosh_ix.searcher()
parser = QueryParser("content", schema = self.whoosh_schema)
query = parser.parse(unicode(searchterm))
whoosh_results = searcher.search(query)
print "FOUND", len(whoosh_results), "Objects"
for r in whoosh_results:
p = KKDocument.objects.get(localFile=r['path'])
a = ', '.join([x.name for x in p.authors.all()])
t = ', '.join([x.tag for x in p.tags.all()])
self.newEntry(p.title, a, t, p.year, p)
开发者ID:konradmiller,项目名称:KnowledgeKeeper,代码行数:30,代码来源:main.py
示例5: findsnippets
def findsnippets(query, daterange=None, page=1,ndocs=PER_PAGE, MAX_SEARCH_RESULTS=MAX_SEARCH_RESULTS,distribution=True):
ix = open_dir(indexdir)
res=[]
daycount={}
with ix.searcher() as searcher:
parser = QueryParser("content", ix.schema)
myquery = parser.parse(query)
if daterange!=None:
datequery=DateRange("date", daterange[0],daterange[1])
results = searcher.search(datequery & myquery,limit=MAX_SEARCH_RESULTS)
else:
results = searcher.search(myquery,limit=MAX_SEARCH_RESULTS)
if distribution:
myfacet=Facets().add_field("date",maptype=sorting.Count)
if daterange!=None:
datequery=DateRange("date", daterange[0],daterange[1])
daycount_orig=searcher.search(datequery & myquery, groupedby=myfacet,limit=MAX_SEARCH_RESULTS)
else:
daycount_orig=searcher.search(myquery, groupedby=myfacet,limit=MAX_SEARCH_RESULTS)
for day in daycount_orig.groups():
daycount[day]=daycount_orig.groups()[day]
for result in results[(page-1)*ndocs:page*ndocs]:
doc=PoorDoc(docidentifier=result['identifier'],date=int(result['date'].strftime("%Y%m%d")))
snippet=result.highlights("content", text=doc.getcontent())
res.append({'title':result['title'],'identifier':result['identifier'],'date':result['date'],'snippet':snippet})
total_docs=results.estimated_length()
return res, total_docs, daycount
else:
for result in results[(page-1)*ndocs:page*ndocs]:
doc=PoorDoc(docidentifier=result['identifier'],date=int(result['date'].strftime("%Y%m%d")))
snippet=result.highlights("content", text=doc.getcontent())
res.append({'title':result['title'],'identifier':result['identifier'],'date':result['date'],'snippet':snippet})
total_docs=results.estimated_length()
return res, total_docs
开发者ID:Fematich,项目名称:article_browser,代码行数:34,代码来源:utils.py
示例6: OnlyOneSearch
def OnlyOneSearch(queryStr="",index=".index"):
ix=get_index(index)
searcher = ix.searcher()
parser = QueryParser("name", schema = ix.schema)
query=parser.parse(queryStr)
results = searcher.search(query)
return results
开发者ID:assem-ch,项目名称:academic_projects,代码行数:7,代码来源:searcher.py
示例7: crearEsquemaCorreo
def crearEsquemaCorreo():
correo1 = "1.txt"
correoEsquema = Schema(remitente=ID(stored=True), destinatarios=KEYWORD(stored=True), fecha=DATETIME(stored=True),asunto=KEYWORD(stored=True), cuerpo=TEXT(stored=True))
if not os.path.exists("indexCorreo"):
os.mkdir("indexCorreo")
iC = index.create_in("indexCorreo", correoEsquema)
iC = open_dir("indexCorreo")
writer = iC.writer()
fecha = "20101015"
date_email = datetime.strptime(fecha, "%Y%m%d")
writer.add_document(remitente=u"unoarrobagmail.com", destinatarios=u"dosarrobagmail.com tresarrobagmail.com", fecha=date_email,asunto=u"Contrato de compraventa con la constructora",cuerpo=u"Estimados socios: ya hemos firmado el contrato de compraventa con el cliente preferencial. Espero noticias vuestras. Un saludo,")
#writer.add_document(email=u"dosarrobagmail.com", name=u"Pedro Guerra")
#writer.add_document(email=u"tresarrobagmail.com", name=u"Ana Montero")
#writer.add_document(email=u"cuatroarrobagmail.com", name=u"Luis Pontes")
writer.commit()
qp = QueryParser("remitente", schema=iC.schema)
q = qp.parse(u"unoarrobagmail.com")
with iC.searcher() as s:
results = s.search(q)
print results[0]
开发者ID:garridev,项目名称:practicas-aii,代码行数:26,代码来源:ExamenViernes.py
示例8: whooshSearch
def whooshSearch(searchTerm, brandTerm):
brandTerm = brandTerm.lower()
#Open index
ix = index.open_dir("index")
#Identify which field
parserFood = QueryParser("tag", ix.schema)
queryFood = parserFood.parse(searchTerm)
searcher = ix.searcher()
#Create filter
if brandTerm == "":
brandTerm = "general"
allow_q = Term("source", brandTerm)
resultFoodGen = searcher.search(queryFood,filter = allow_q, limit = 7)
resultFoodNoGen = searcher.search(queryFood,mask = allow_q, limit = 1000)
resultFood = [each for each in resultFoodGen] + [each for each in resultFoodNoGen]
else:
allow_q = Term("source", brandTerm)
resultFood = searcher.search(queryFood,filter = allow_q, limit = 1000)
resultList = []
for i in resultFood:
resultList.append(i["id"])
searcher.close()
return resultList
开发者ID:Jasckom,项目名称:nutrientdata,代码行数:29,代码来源:whooshSearch.py
示例9: searchNote
def searchNote(self):
pattern = self.searchEdit.text()
qres = []
with self.ix.searcher() as searcher:
queryp = QueryParser("content", self.ix.schema)
queryp.add_plugin(RegexPlugin())
query = queryp.parse('r"' + pattern + '"')
# r"pattern" is the desired regex term format
pathFacet = sorting.FieldFacet("path")
scores = sorting.ScoreFacet()
results = searcher.search(
query, limit=None, sortedby=[pathFacet, scores]) # default limit is 10!
for r in results:
listItem = QListWidgetItem()
title = r['title']
text = r['path']
term = r.highlights("content")
qres.append([title, text, term])
html = """
<style>
body { font-size: 14px; }
.path { font-size: 12px; color: #009933; }
</style>
"""
for ti, te, hi in qres:
html += ("<p><a href='" + te + "'>" + ti +
"</a><br/><span class='path'>" +
te + "</span><br/>" + hi + "</p>")
self.searchView.setHtml(html)
开发者ID:dragon-D,项目名称:mikidown,代码行数:29,代码来源:mikiwindow.py
示例10: whoosh
def whoosh(q_query, raw_query, page):
results = []
try:
import internal_search
with internal_search.ix.searcher() as searcher:
from whoosh.qparser import QueryParser
parser = QueryParser("keywords", internal_search.ix.schema)
myquery = parser.parse('"%s"' %raw_query)
w_results = searcher.search(myquery)
for r in w_results:
s = ''
if 'official' in r:
s = ' official'
if not 'twitter' in r:
t = ''
else:
t = r['twitter']
results.append({
"style" : "internal_search%s" % s,
"title" : r['title'],
"url" : r['link'],
"snippet" : r['content'],
"display_url" : r['link'],
"twitter" : t
})
except Exception as ex:
import traceback
results.append({
"style" : "error",
"title" : "An error occured: %s" % repr(ex) + "<br/>" + traceback.format_exc().replace("\n", "<br/>"),
"snippet" : "<pre>%s</pre>" % debug_info
})
return results
开发者ID:kennydude,项目名称:Search-Engine,代码行数:33,代码来源:web.py
示例11: lookup
def lookup(self, key, raw=True, field="entity_id"):
if key == 'entities' or key is None:
if raw:
return b2u(list(self.objects.values()))
else:
return b2u(list(self.infos.values()))
from whoosh.qparser import QueryParser
# import pdb; pdb.set_trace()
key = key.strip('+')
key = key.replace('+', ' AND ')
for uri, a in list(ATTRS_INV.items()):
key = key.replace(uri, a)
key = " {!s} ".format(key)
key = re.sub("([^=]+)=(\S+)", "\\1:\\2", key)
key = re.sub("{([^}]+)}(\S+)", "\\1:\\2", key)
key = key.strip()
qp = QueryParser("object_id", schema=self.schema)
q = qp.parse(key)
lst = set()
with self.index.searcher() as searcher:
results = searcher.search(q, limit=None)
for result in results:
if raw:
lst.add(self.objects[result['object_id']])
else:
lst.add(self.infos[result['object_id']])
return b2u(list(lst))
开发者ID:leifj,项目名称:pyFF,代码行数:30,代码来源:store.py
示例12: search
def search(self, q, page = 1, size = 30):
searcher = self.ix.searcher()
parser = QueryParser("content", schema=self.ix.schema, group=OrGroup)
parser_rlt = parser.parse(q)
#print unicode(parser_rlt)
results = searcher.search_page(parser_rlt, page, size)
return self.parse_results(results)
开发者ID:jannson,项目名称:iskdaemon,代码行数:7,代码来源:simdb.py
示例13: fulltext_search
def fulltext_search(request, query, limit):
# query index
index = get_index()
parser = QueryParser('value', index.schema)
with index.searcher() as searcher:
query = parser.parse(query)
results = searcher.search(query, limit=limit)
results = results_to_instances(request, results)
# helper for limit
def limited(res):
if limit is not None:
return res[:limit]
return res
# if authenticated, return all draft and published results
authenticated = bool(authenticated_userid(request))
if authenticated:
return limited(
[res for res in results if res.state in ['draft', 'published']])
# check for submitter
submitter = get_submitter(request)
if submitter:
return limited(
[res for res in results if res.state == 'published' or
(res.state == 'draft' and submitter == res.submitter)])
# return only public results
return limited([res for res in results if res.state == 'published'])
开发者ID:rnixx,项目名称:chronotope,代码行数:28,代码来源:search.py
示例14: __init__
def __init__(self, search_term):
search_term = re.sub( and_regex, ' AND ', search_term )
search_term = re.sub( or_regex, ' OR ', search_term)
parser = QueryParser("content", schema=None)
q = parser.parse(search_term)
invalid = self.validate_search_term(q)
if invalid:
raise ValueError(invalid + search_term)
myapp.db_connector.connect()
session = myapp.db_connector.get_session()
subq = session.query( TourneyList.id.label("tourney_list_id"),
TourneyVenue.country.label("country_name"),
TourneyVenue.state.label("state_name"),
TourneyVenue.city.label("city_name"),
TourneyVenue.venue.label("venue_name"),
Tourney.tourney_type.label("tourney_type"),
func.group_concat( ShipPilot.ship_type.distinct()).label("ship_name" ),
func.group_concat( func.concat( Pilot.name, " ", Pilot.canon_name )).label("pilot_name"),
func.group_concat( func.concat( Upgrade.name, " ", Upgrade.canon_name ) ).label("upgrade_name") ). \
join(Tourney).\
join(TourneyVenue).\
join(Ship). \
join(ShipPilot). \
join(Pilot). \
outerjoin(ShipUpgrade). \
outerjoin(Upgrade).\
group_by( TourneyList.id).subquery()
fn = tree_to_expr(q, subq)
self.query = session.query(subq.c.tourney_list_id).filter( fn )
开发者ID:roshow,项目名称:xwlists,代码行数:35,代码来源:search.py
示例15: index_query
def index_query(environ, **kwargs):
"""
Return a generator of tiddlers that match
the provided arguments.
"""
logging.debug('entering with %s', environ)
print 'getting called on index_query'
config = environ['tiddlyweb.config']
#store = environ['tiddlyweb.store']
query_parts = []
for field, value in kwargs.items():
if field == 'tag':
field = 'tags'
query_parts.append('%s:%s' % (field, value))
query_string = ' '.join(query_parts)
print 'getting inside on index_query'
schema = config.get('wsearch.schema', SEARCH_DEFAULTS['wsearch.schema'])
searcher = get_searcher(config)
parser = QueryParser('text', schema=Schema(**schema))
query = parser.parse(query_string)
logging.debug('query parsed to %s' % query)
results = searcher.search(query)
def tiddler_from_result(result):
print 'r', result
bag, title = result['id'].split(':', 1)
tiddler = Tiddler(title, bag)
return tiddler
#return store.get(tiddler)
for result in results:
yield tiddler_from_result(result)
return
开发者ID:jdlrobson,项目名称:tiddlyweb-plugins,代码行数:34,代码来源:whoosher.py
示例16: test_all_terms
def test_all_terms():
q = QueryParser("a", None).parse(u('hello b:there c:"my friend"'))
ts = q.all_terms(phrases=False)
assert sorted(ts) == [("a", "hello"), ("b", "there")]
ts = q.all_terms(phrases=True)
assert sorted(ts) == [("a", "hello"), ("b", "there"), ("c", "friend"),
("c", "my")]
开发者ID:pombredanne,项目名称:whoosh-clone,代码行数:7,代码来源:test_queries.py
示例17: search_datasets
def search_datasets(self, search_phrase, limit=None):
"""Search for just the datasets."""
from collections import defaultdict
from whoosh.qparser import QueryParser
parser = QueryParser("doc", schema=self.dataset_index.schema)
query = parser.parse(search_phrase)
datasets = defaultdict(SearchResult)
with self.dataset_index.searcher() as searcher:
results = searcher.search(query, limit=limit)
for hit in results:
vid = hit.get('vid')
bvid = hit.get('bvid')
type = hit.get('type')
datasets[bvid].vid = bvid
if type == 'b':
datasets[bvid].bundle_found = True
datasets[bvid].b_score += hit.score
else:
datasets[bvid].p_score += hit.score
datasets[bvid].partitions.add(vid)
return datasets
开发者ID:Gudinya,项目名称:ambry,代码行数:32,代码来源:search.py
示例18: test_correct_query
def test_correct_query():
schema = fields.Schema(a=fields.TEXT(), b=fields.TEXT)
with TempIndex(schema) as ix:
with ix.writer() as w:
w.add_document(a=u"alfa bravo charlie delta")
w.add_document(a=u"delta echo foxtrot golf")
w.add_document(a=u"golf hotel india juliet")
w.add_document(a=u"juliet kilo lima mike")
with ix.searcher() as s:
qp = QueryParser("a", ix.schema)
qtext = u'alpha ("brovo november" OR b:dolta) detail'
q = qp.parse(qtext, ix.schema)
c = s.correct_query(q, qtext)
cq = c.query
assert isinstance(cq, query.And)
assert cq[0].text == "alfa"
assert isinstance(cq[1], query.Or)
assert isinstance(cq[1][0], query.Phrase)
assert cq[1][0].words == ["bravo", "november"]
qtext = u'alpha b:("brovo november" a:delta) detail'
q = qp.parse(qtext, ix.schema)
c = s.correct_query(q, qtext)
assert c.query.__unicode__() == '(a:alfa AND b:"brovo november" AND a:delta AND a:detail)'
assert c.string == 'alfa b:("brovo november" a:delta) detail'
hf = highlight.HtmlFormatter(classname="c")
assert c.format_string(hf) == '<strong class="c term0">alfa</strong> b:("brovo november" a:delta) detail'
开发者ID:pombredanne,项目名称:whoosh-clone,代码行数:30,代码来源:test_spelling.py
示例19: grid_search
def grid_search(rookie_avg, surround, fragment_char_limit, whoosh_results, corpus, query_string):
'''
find best top parameter for whoosh snips. top parameter controls how many ... delimited fragments
best = minimize distance w/ average size of rookie snip
'''
best = {""}
best_distance_so_far = 1000000000
index = open_dir("indexes/{}/".format(corpus))
corpusid = getcorpusid(corpus)
for top in range(1, 5): # basically fixed for now
with index.searcher() as srch:
query_parser = QueryParser("content", schema=index.schema)
qry = query_parser.parse(query_string)
results = srch.search(qry, limit=None)
results.fragmenter.surround = surround
results.fragmenter.maxchars = fragment_char_limit
sum_ = 0
for s_ix, a in enumerate(results):
path = a.get("path").replace("/", "")
sents = get_preproc_sentences(path, corpusid)
sss = unicode(" ".join(sents).encode("ascii", "ignore"))
sss = str(a.highlights("content", text=sss, top=top))
sum_ += len(sss)
diff = abs(rookie_avg - sum_/len(results))
print "top of {} gives diff of {}".format(top, diff)
if diff < best_distance_so_far:
best = top
best_distance_so_far = diff
print "best top = {}".format(best)
return best
开发者ID:AbeHandler,项目名称:rookie,代码行数:31,代码来源:app.py
示例20: test_correct_spell_field
def test_correct_spell_field():
ana = analysis.StemmingAnalyzer()
schema = fields.Schema(text=fields.TEXT(analyzer=ana, spelling=True))
with TempIndex(schema) as ix:
with ix.writer() as w:
w.add_document(text=u"rendering shading modeling reactions")
with ix.searcher() as s:
text = s.schema["text"]
spell_text = s.schema["spell_text"]
r = s.reader()
words = [text.from_bytes(t) for t in r.lexicon("text")]
assert words == ["model", "reaction", "render", "shade"]
words = [spell_text.from_bytes(t) for t in r.lexicon("spell_text")]
assert words == ["modeling", "reactions", "rendering", "shading"]
qp = QueryParser("text", s.schema)
qtext = u"renderink"
q = qp.parse(qtext, s.schema)
r = s.search(q)
assert len(r) == 0
c = s.correct_query(q, qtext)
assert c.string == "rendering"
assert c.query == query.Term("text", "rendering")
hf = highlight.HtmlFormatter(classname="c")
assert c.format_string(hf) == '<strong class="c term0">rendering</strong>'
开发者ID:pombredanne,项目名称:whoosh-clone,代码行数:31,代码来源:test_spelling.py
注:本文中的whoosh.qparser.QueryParser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论