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


Python WikiClient.query方法代码示例

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


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

示例1: test_exclude_words

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
    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,代码行数:10,代码来源:test_search.py

示例2: test_no_syntax_error

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
    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,代码行数:10,代码来源:test_search.py

示例3: test_translations_inherit_os_values

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
    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,代码行数:12,代码来源:test_search.py

示例4: test_translations_inherit_os_values

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
    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,代码行数:13,代码来源:test_search.py

示例5: test_range_filter

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
 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,代码行数:11,代码来源:test_search.py

示例6: test_range_filter

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
 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,代码行数:11,代码来源:test_search.py

示例7: test_unicode_excerpt

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
 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,代码行数:14,代码来源:test_search.py

示例8: test_ngram_chars

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
 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,代码行数:8,代码来源:test_search.py

示例9: test_wiki_index_strip_html

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
 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,代码行数:7,代码来源:test_search.py

示例10: test_wiki_index_content

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
 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,代码行数:8,代码来源:test_search.py

示例11: _search_suggestions

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
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,代码行数:65,代码来源:views.py

示例12: test_indexer

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
 def test_indexer(self):
     wc = WikiClient()
     results = wc.query('audio')
     eq_(2, len(results))
开发者ID:pombredanne,项目名称:kitsune,代码行数:6,代码来源:test_search.py

示例13: test_category

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
 def test_category(self):
     wc = WikiClient()
     results = wc.query('', ({'filter': 'category', 'value': [10]},))
     eq_(5, len(results))
     results = wc.query('', ({'filter': 'category', 'value': [30]},))
     eq_(1, len(results))
开发者ID:pombredanne,项目名称:kitsune,代码行数:8,代码来源:test_search.py

示例14: search

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]

#.........这里部分代码省略.........
                filters_f.append({"filter": "is_sticky", "value": (1,)})

            if constants.DISCUSSION_LOCKED in cleaned["thread_type"]:
                filters_f.append({"filter": "is_locked", "value": (1,)})

        if cleaned["forum"]:
            filters_f.append({"filter": "forum_id", "value": cleaned["forum"]})

    # Filters common to support and discussion forums
    # Created filter
    unix_now = int(time.time())
    interval_filters = (
        ("created", cleaned["created"], cleaned["created_date"]),
        ("updated", cleaned["updated"], cleaned["updated_date"]),
        ("question_votes", cleaned["num_voted"], cleaned["num_votes"]),
    )
    for filter_name, filter_option, filter_date in interval_filters:
        if filter_option == constants.INTERVAL_BEFORE:
            before = {"range": True, "filter": filter_name, "min": 0, "max": max(filter_date, 0)}
            if filter_name != "question_votes":
                filters_f.append(before)
            filters_q.append(before)
        elif filter_option == constants.INTERVAL_AFTER:
            after = {"range": True, "filter": filter_name, "min": min(filter_date, unix_now), "max": unix_now}
            if filter_name != "question_votes":
                filters_f.append(after)
            filters_q.append(after)

    sortby = smart_int(request.GET.get("sortby"))
    try:
        if cleaned["w"] & constants.WHERE_WIKI:
            wc = WikiClient()  # Wiki SearchClient instance
            # Execute the query and append to documents
            documents += wc.query(cleaned["q"], filters_w)

        if cleaned["w"] & constants.WHERE_SUPPORT:
            qc = QuestionsClient()  # Support question SearchClient instance

            # Sort results by
            try:
                qc.set_sort_mode(constants.SORT_QUESTIONS[sortby][0], constants.SORT_QUESTIONS[sortby][1])
            except IndexError:
                pass

            documents += qc.query(cleaned["q"], filters_q)

        if cleaned["w"] & constants.WHERE_DISCUSSION:
            dc = DiscussionClient()  # Discussion forums SearchClient instance

            # Sort results by
            try:
                dc.groupsort = constants.GROUPSORT[sortby]
            except IndexError:
                pass

            documents += dc.query(cleaned["q"], filters_f)

    except SearchError:
        if is_json:
            return HttpResponse(json.dumps({"error": _("Search Unavailable")}), mimetype=mimetype, status=503)

        t = "search/mobile/down.html" if request.MOBILE else "search/down.html"
        return jingo.render(request, t, {"q": cleaned["q"]}, status=503)

    pages = paginate(request, documents, settings.SEARCH_RESULTS_PER_PAGE)
开发者ID:grayf0x616,项目名称:kitsune,代码行数:69,代码来源:views.py

示例15: test_range_filter

# 需要导入模块: from search.clients import WikiClient [as 别名]
# 或者: from search.clients.WikiClient import query [as 别名]
 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,代码行数:8,代码来源:test_search.py


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