• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python clients.WikiClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中search.clients.WikiClient的典型用法代码示例。如果您正苦于以下问题:Python WikiClient类的具体用法?Python WikiClient怎么用?Python WikiClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_utf8_excerpt

 def test_utf8_excerpt(self):
     """Characters should stay in UTF-8."""
     wc = WikiClient()
     page = Document.objects.get(pk=4)
     q = u'fa\xe7on'
     excerpt = wc.excerpt(page.html, q)
     assert q in excerpt, u'%s not in %s' % (q, excerpt)
开发者ID:pombredanne,项目名称:kitsune,代码行数:7,代码来源:test_search.py


示例2: test_no_syntax_error

    def test_no_syntax_error(self):
        """Test that special chars cannot cause a syntax error."""
        wc = WikiClient()
        results = wc.query('video^$')
        eq_(1, len(results))

        results = wc.query('video^^^$$$^')
        eq_(1, len(results))
开发者ID:pombredanne,项目名称:kitsune,代码行数:8,代码来源:test_search.py


示例3: test_exclude_words

    def test_exclude_words(self):
        """Excluding words with -word works."""
        wc = WikiClient()
        results = wc.query('spanish')
        eq_(1, len(results))

        results = wc.query('spanish -content')
        eq_(0, len(results))
开发者ID:pombredanne,项目名称:kitsune,代码行数:8,代码来源:test_search.py


示例4: test_unicode_excerpt

 def test_unicode_excerpt(self):
     """Unicode characters in the excerpt should not be a problem."""
     wc = WikiClient()
     page = Document.objects.get(pk=2)
     try:
         excerpt = wc.excerpt(page.html, u'\u3068')
         render('{{ c }}', {'c': excerpt})
     except UnicodeDecodeError:
         self.fail('Raised UnicodeDecodeError.')
开发者ID:pombredanne,项目名称:kitsune,代码行数:9,代码来源:test_search.py


示例5: test_range_filter

 def test_range_filter(self):
     """Test filtering on a range."""
     wc = WikiClient()
     filter_ = ({'filter': 'updated',
                 'max': 1244355125,
                 'min': 1244355115,
                 'range': True},)
     results = wc.query('', filter_)
     eq_(1, len(results))
开发者ID:sgarrity,项目名称:kitsune,代码行数:9,代码来源:test_search.py


示例6: test_clean_excerpt

 def test_clean_excerpt(self):
     """SearchClient.excerpt() should not allow disallowed HTML through."""
     wc = WikiClient()  # Index strips HTML
     qc = QuestionsClient()  # Index does not strip HTML
     input = "test <div>the start of something</div>"
     output_strip = "<b>test</b>  the start of something"
     output_nostrip = "<b>test</b> &lt;div&gt;the start of " "something&lt;/div&gt;"
     eq_(output_strip, wc.excerpt(input, "test"))
     eq_(output_nostrip, qc.excerpt(input, "test"))
开发者ID:unixeO,项目名称:kitsune,代码行数:9,代码来源:test_search.py


示例7: test_range_filter

 def test_range_filter(self):
     """Test filtering on a range."""
     wc = WikiClient()
     filter_ = ({'filter': 'updated',
                 'max': 1285765791,
                 'min': 1284664176,
                 'range': True},)
     results = wc.query('', filter_)
     eq_(2, len(results))
开发者ID:pombredanne,项目名称:kitsune,代码行数:9,代码来源:test_search.py


示例8: test_translations_inherit_os_values

    def test_translations_inherit_os_values(self):
        wc = WikiClient()
        filters = [{"filter": "locale", "value": (crc32("fr"),)}, {"filter": "os", "value": (1,)}]
        results = wc.query("", filters)
        eq_(1, len(results))
        eq_(4, results[0]["id"])

        filters[1]["value"] = (4,)
        results = wc.query("", filters)
        eq_(0, len(results))
开发者ID:unixeO,项目名称:kitsune,代码行数:10,代码来源:test_search.py


示例9: test_translations_inherit_os_values

    def test_translations_inherit_os_values(self):
        wc = WikiClient()
        filters = [{'filter': 'locale', 'value': (crc32('fr'),)},
                   {'filter': 'os', 'value': (1,)}]
        results = wc.query('', filters)
        eq_(1, len(results))
        eq_(4, results[0]['id'])

        filters[1]['value'] = (4,)
        results = wc.query('', filters)
        eq_(0, len(results))
开发者ID:MechanisM,项目名称:kitsune,代码行数:11,代码来源:test_search.py


示例10: test_unicode_excerpt

 def test_unicode_excerpt(self):
     """Unicode characters in the excerpt should not be a problem."""
     wc = WikiClient()
     q = 'contribute'
     results = wc.query(q)
     eq_(1, len(results))
     page = WikiPage.objects.get(pk=results[0]['id'])
     try:
         excerpt = wc.excerpt(page.content, q)
         render('{{ c }}', {'c': excerpt})
     except UnicodeDecodeError:
         self.fail('Raised UnicodeDecodeError.')
开发者ID:sgarrity,项目名称:kitsune,代码行数:12,代码来源:test_search.py


示例11: test_clean_hyphens

 def test_clean_hyphens(self):
     """Hyphens in words aren't special characters."""
     wc = WikiClient()
     results = wc.query('marque-page')
     eq_(1, len(results))
开发者ID:pombredanne,项目名称:kitsune,代码行数:5,代码来源:test_search.py


示例12: test_ngram_chars

 def test_ngram_chars(self):
     """Ideographs are handled correctly."""
     wc = WikiClient()
     results = wc.query(u'\u30c1')
     eq_(1, len(results))
     eq_(2, results[0]['id'])
开发者ID:pombredanne,项目名称:kitsune,代码行数:6,代码来源:test_search.py


示例13: test_wiki_index_strip_html

 def test_wiki_index_strip_html(self):
     """HTML should be stripped, not indexed."""
     wc = WikiClient()
     results = wc.query('strong')
     eq_(0, len(results))
开发者ID:pombredanne,项目名称:kitsune,代码行数:5,代码来源:test_search.py


示例14: test_wiki_index_content

 def test_wiki_index_content(self):
     """Obviously the content should be indexed."""
     wc = WikiClient()
     results = wc.query('video')
     eq_(1, len(results))
     eq_(1, results[0]['id'])
开发者ID:pombredanne,项目名称:kitsune,代码行数:6,代码来源:test_search.py


示例15: test_indexer

 def test_indexer(self):
     wc = WikiClient()
     results = wc.query('audio')
     eq_(2, len(results))
开发者ID:pombredanne,项目名称:kitsune,代码行数:4,代码来源:test_search.py


示例16: test_range_filter

 def test_range_filter(self):
     """Test filtering on a range."""
     wc = WikiClient()
     filter_ = ({"filter": "updated", "max": 1285765791, "min": 1284664176, "range": True},)
     results = wc.query("", filter_)
     eq_(2, len(results))
开发者ID:unixeO,项目名称:kitsune,代码行数:6,代码来源:test_search.py


示例17: test_none_content_excerpt

 def test_none_content_excerpt(self):
     """SearchClient.excerpt() returns empty string for None type."""
     wc = WikiClient()
     eq_('', wc.excerpt(None, 'test'))
开发者ID:pombredanne,项目名称:kitsune,代码行数:4,代码来源:test_search.py


示例18: test_clean_excerpt

 def test_clean_excerpt(self):
     """SearchClient.excerpt() should not allow disallowed HTML through."""
     wc = WikiClient()
     eq_('<b>test</b>&lt;/style&gt;', wc.excerpt('test</style>', 'test'))
开发者ID:sgarrity,项目名称:kitsune,代码行数:4,代码来源:test_search.py


示例19: _search_suggestions

def _search_suggestions(query, locale):
    """Return an iterable of the most relevant wiki pages and questions.

    query -- full text to search on
    locale -- locale to limit to

    Items are dicts of:
        {
            'type':
            'object':
        }

    Returns up to 3 wiki pages, then up to 3 questions.

    TODO: ZOMFG this needs to be refactored and the search app should
          provide an internal API. Seriously.

    """

    # Max number of search results per type.
    WIKI_RESULTS = QUESTIONS_RESULTS = 3

    # Search wiki pages:
    wiki_searcher = WikiClient()
    filters = [{'filter': 'locale',
                'value': (sphinx_locale(locale),)},
               {'filter': 'category',
                'value': [x for x in settings.SEARCH_DEFAULT_CATEGORIES
                          if x >= 0]},
               {'filter': 'category',
                'exclude': True,
                'value': [-x for x in settings.SEARCH_DEFAULT_CATEGORIES
                          if x < 0]}]
    raw_results = wiki_searcher.query(query, filters=filters,
                                      limit=WIKI_RESULTS)
    # Lazily build excerpts from results. Stop when we have enough:
    results = []
    for r in raw_results:
        try:
            doc = Document.objects.select_related('current_revision').\
                get(pk=r['id'])
            results.append({
                'type': 'document',
                'object': doc,
            })
        except Document.DoesNotExist:
            pass

    question_searcher = QuestionsClient()
    # questions app is en-US only.
    raw_results = question_searcher.query(query,
                                          limit=QUESTIONS_RESULTS)
    for r in raw_results:
        try:
            q = Question.objects.get(pk=r['attrs']['question_id'])
            results.append({
                'type': 'question',
                'object': q
            })
        except Question.DoesNotExist:
            pass

    return results
开发者ID:bowmasters,项目名称:kitsune,代码行数:63,代码来源:views.py


示例20: test_clean_excerpt

 def test_clean_excerpt(self):
     """SearchClient.excerpt() should not allow disallowed HTML through."""
     wc = WikiClient()  # Index strips HTML
     input = 'test <div>the start of something</div>'
     output_strip = '<b>test</b>  the start of something'
     eq_(output_strip, wc.excerpt(input, 'test'))
开发者ID:GPHemsley,项目名称:kuma,代码行数:6,代码来源:test_search.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python conf.EMPTY_QUERY类代码示例发布时间:2022-05-27
下一篇:
Python client.Client类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap