当前位置: 首页>>代码示例>>Python>>正文


Python Page.objects方法代码示例

本文整理汇总了Python中models.Page.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Page.objects方法的具体用法?Python Page.objects怎么用?Python Page.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Page的用法示例。


在下文中一共展示了Page.objects方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: show_pages

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import objects [as 别名]
def show_pages():
    if request.method == "POST" and g.site.domain == g.user:
        name = request.form['name']
        if name:
            p = Page()
            p.name = name
            p.slug = slugify(name)
            p.site = g.site.domain
            p.save()
            return redirect(url_for(".edit_page", slug=p.slug))
    pages = Page.objects(site=g.site.domain)
    return render_template('pages.html', pages=pages)
开发者ID:abal09,项目名称:samklang,代码行数:14,代码来源:pages.py

示例2: rebuild_url_lookup

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import objects [as 别名]
def rebuild_url_lookup():
    ''' Rebuld URL lookup data'''
    print "Rebuilding URL"
    env = __open_env()
    urls = env.open_db('urls')
    with env.begin(db=urls, write=True) as txn:
        cursor = txn.cursor()
        for k, v in cursor:
            txn.delete(k)
        for item in Page.objects():
            t = item.url.encode('utf-8')
            txn.put(t, '1')
    print "Done"
    env.close()
开发者ID:vlasy,项目名称:skool,代码行数:16,代码来源:crawler.py

示例3: search

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import objects [as 别名]
def search(query, field, start=0, size=100, recommend=False, fuzzy=False, highlight=None):
    '''
    Perform Elasticsearch index lookup for documents with given parameters

    :param query: text to be searched for
    :type query: str
    :param field: field to be searched
    :type field: str
    :param start: offset for results presentation
    :type start: int
    :param size: how many documents to present
    :type size: int
    :param recommend: fill in document's recommendations
    :type recommend: bool
    :param fuzzy: perform fuzzy search
    :type fuzzy: bool
    :param highlight: highlight query in result document
    :type highlight: bool
    :returns: number of results and results
    :rtype: tuple (nrOfResults, results)
    '''
    body = {
        "from": start,
        'query': {}
    }
    if size > 0:
        body['size'] = size
    query = re.sub(r'[/:]', '\\/', query)
    body['query']['query_string'] = {"fields": [field], "query": query, "default_operator": "AND"}
    if fuzzy:
        body['query']['query_string']['fuzziness'] = 'AUTO'  # is default - can be ommited
    else:
        body['query']['query_string']['fuzziness'] = 0  # or 1 - both should be ok
    if highlight and len(highlight) is 2:
        body['highlight'] = {
            "pre_tags": [highlight[0]],
            "post_tags": [highlight[1]],
            "fields": {
                field: {}
            }
        }
    # print body
    res = Elasticsearch().search(index=INDEX_NAME, body=body)
    # print res
    pres = []
    for r in res['hits']['hits']:
        hit = Page.objects(id=r['_source']['_id']).first()
        if hit:
            if highlight and len(highlight) is 2:
                hit.btext = '<br><br>'.join(r['highlight']['btext'])
            pres.append(hit)

    fin = []
    for page in pres:
        tmp = []
        if recommend:
            if page.parent:
                for r in page.parent.recs:
                    x = [r.url, r.title]
                    tmp.append(x)
            else:
                for r in page.recs:
                    x = [r.url, r.url]
                    tmp.append(x)
        fin.append([page, tmp])
    return (res['hits']['total'], fin)
开发者ID:vlasy,项目名称:skool,代码行数:68,代码来源:search.py


注:本文中的models.Page.objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。