本文整理汇总了Python中sqlalchemy_searchable.parse_search_query函数的典型用法代码示例。如果您正苦于以下问题:Python parse_search_query函数的具体用法?Python parse_search_query怎么用?Python parse_search_query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_search_query函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_not_between_words
def test_not_between_words(self):
assert parse_search_query('wars -star') == (
'wars:* & ! star:*'
)
assert parse_search_query(u'äää -ööö') == (
u'äää:* & ! ööö:*'
)
示例2: test_emails_with_email_tokens
def test_emails_with_email_tokens(self):
assert (
parse_search_query(
'[email protected]',
parser=SearchQueryParser(emails_as_tokens=True)
) ==
'[email protected]:*'
)
示例3: simple_search
def simple_search(query):
q1 = Article.query.filter(Article.search_vector.match_tsquery(parse_search_query(query)))
#q2 = Article.query.filter(Article.authors.any(Author.lastname.ilike(query)))
#q2 = Article.query.filter(Article.authors.any(func.lower(Author.lastname) == func.lower(query)))
#q = q1.union(q2)
return q1.order_by((Article.created + cast("0", Interval)).desc())
示例4: test_supports_custom_parsers
def test_supports_custom_parsers(self):
assert (
parse_search_query(
'star wars',
parser=SearchQueryParser(wildcard='*')
)
==
'star* & wars*'
)
示例5: base_search
def base_search(query):
filter_list = []
remove_list = []
#get list of category flags given
#and remove them from the query
if '-phd' in query.lower():
remove_list.append(People.phd==None)
query = query.replace('-phd','')
elif 'phd' in query.lower():
filter_list.append(People.phd)
query = query.replace('phd','')
if '-staff' in query.lower():
remove_list.append(People.staff==None)
query = query.replace('-staff','')
elif 'staff' in query.lower():
filter_list.append(People.staff)
query = query.replace('staff','')
if '-postdoc' in query.lower():
remove_list.append(People.postdoc==None)
query = query.replace('-postdoc','')
elif 'postdoc' in query.lower():
filter_list.append(People.postdoc)
query = query.replace('postdoc','')
if '-associate' in query.lower():
remove_list.append(People.associate==None)
query = query.replace('-associate','')
elif 'associate' in query.lower():
filter_list.append(People.associate)
query = query.replace('associate','')
#for a simple "query all" function
if ('*' in query) or not query.strip(' '):
all = People.query.filter(and_(*remove_list)).filter(or_(*filter_list))
return all
#for each category, query on the join using combined search vector
phd_vec = People.search_vector | PhD.search_vector
phd = db.session.query(People).join(PhD).filter(phd_vec.match(parse_search_query(query)))
pos_vec = People.search_vector | Positions.search_vector
staff = db.session.query(People).join(Staff).join(Positions).filter(pos_vec.match(parse_search_query(query)))
associates = db.session.query(People).join(Associates).join(Positions).filter(pos_vec.match(parse_search_query(query)))
staff_nopos = People.query.join(Staff).filter(~(Staff.position.any())).search(query)
assoc_nopos = People.query.join(Associates).filter(~(Associates.position.any())).search(query)
others = People.query.filter(People.staff==None, People.associate==None, People.phd==None).search(query)
#union all categories, and filter by category tags
union = phd.union(staff, staff_nopos, associates, assoc_nopos, others)
union = union.filter(and_(*remove_list)).filter(or_(*filter_list))
return union
示例6: feed_articles
def feed_articles(self):
# explain (analyze,buffers) select * from article INNER JOIN (select id from article as blah where search_vector @@ to_tsquery('circuit:* & qed:* | qubit:*') union select article_id from articlesauthors as blah where author_id in (54962, 55738, 85464, 85465, 125598, 55921)) on id=blah order by created desc;
#select * from (select distinct on (id) * from (select articles.* from articles where search_vector @@ ... union all select a.* from articles a join articlesauthors aa on ... where author_id = any (...)) s1) s2 order by created_at desc;
#explain (analyze,buffers) select article.*, (article.id+0) as dummy_article_id from article where search_vector @@ to_tsquery('circuit:* & qed:* | qubit:*') union select a.*, (a.id+0) as dummy_article_id from article a join articlesauthors aa on a.id=aa.article_id where author_id in (54962, 55738, 85464, 85465, 125598, 55921) order by created desc;search_query = parse_search_query(' or '.join([kw.keyword for kw in self.keywords]))
#select article.*, (article.id+0) as dummy_article_id from article where search_vector @@ to_tsquery('circuit:* & qed:* | qubit:*') union select a.*, (a.id+0) as dummy_article_id from article a join articlesauthors aa on a.id=aa.article_id where author_id in (54962, 55738, 85464, 85465, 125598, 55921) order by created desc;search_query = parse_search_query(' or '.join([kw.keyword for kw in self.keywords]))
search_query = parse_search_query(' or '.join([kw.keyword for kw in self.keywords]))
alist = [a.id for a in self.authors]
s1 = select([ArticleAuthor.article_id]).where(ArticleAuthor.author_id.in_(alist))
s2 = select([Article.id]).where(Article.search_vector.match_tsquery(search_query))
q = Article.query.filter(Article.id.in_(s1.union(s2))).order_by((Article.created + cast("0",
Interval)).desc()) #The addition of the extra interval is important because it changes the way the query plan is computed and makes it run 100x faster!
return q
示例7: test_space_as_and
def test_space_as_and(self):
assert parse_search_query('star wars') == 'star:* & wars:*'
示例8: test_multiple_ors
def test_multiple_ors(self):
assert parse_search_query('star or or or wars') == 'star:* | wars:*'
示例9: test_or
def test_or(self):
assert parse_search_query('star or wars') == 'star:* | wars:*'
示例10: test_hyphen_between_words
def test_hyphen_between_words(self):
assert parse_search_query('star-wars') == 'star:* & wars:*'
示例11: test_or_within_a_token_preceded_by_space
def test_or_within_a_token_preceded_by_space(self):
assert parse_search_query('star organs') == (
'star:* & organs:*'
)
示例12: test_empty_parenthesis
def test_empty_parenthesis(self):
assert parse_search_query('()') == ''
示例13: test_and_within_a_token_preceded_by_space
def test_and_within_a_token_preceded_by_space(self):
assert parse_search_query('star andromeda') == (
'star:* & andromeda:*'
)
示例14: test_single_quotes
def test_single_quotes(self):
assert parse_search_query("'star") == (
'star:*'
)
示例15: test_multiple_and
def test_multiple_and(self):
assert parse_search_query('star and and wars') == 'star:* & wars:*'