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


Python qparser.MultifieldParser方法代码示例

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


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

示例1: search

# 需要导入模块: from whoosh import qparser [as 别名]
# 或者: from whoosh.qparser import MultifieldParser [as 别名]
def search(self, query_list, fields=None):
        with self.ix.searcher() as searcher:
            query_string = " ".join(query_list)
            query = None
            if "\"" in query_string or ":" in query_string:
                query = QueryParser("content", self.schema).parse(query_string)
            elif len(fields) == 1 and fields[0] == "filename":
                pass
            elif len(fields) == 1 and fields[0] == "tags":
                pass
            elif len(fields) == 2:
                pass
            else:
                fields = ["tags", "headlines", "content", "filename", "doubleemphasiswords", "emphasiswords"]
            if not query:
                query = MultifieldParser(fields, schema=self.ix.schema).parse(query_string)
            parsed_query = "%s" % query
            print "query: %s" % parsed_query
            results = searcher.search(query, terms=False, scored=True, groupedby="path")
            key_terms = results.key_terms("tags", docs=100, numterms=100)
            tag_cloud = [keyword for keyword, score in key_terms]
            search_result = self.create_search_result(results)

        return parsed_query, search_result, tag_cloud 
开发者ID:BernhardWenzel,项目名称:markdown-search,代码行数:26,代码来源:search.py

示例2: msearch

# 需要导入模块: from whoosh import qparser [as 别名]
# 或者: from whoosh.qparser import MultifieldParser [as 别名]
def msearch(self, m, query, fields=None, limit=None, or_=True, **kwargs):
        '''
        set limit make search faster
        '''
        ix = self.index(m)
        if fields is None:
            fields = ix.fields

        def _parser(fieldnames, schema, group, **kwargs):
            return MultifieldParser(fieldnames, schema, group=group, **kwargs)

        group = OrGroup if or_ else AndGroup
        parser = getattr(m, "__msearch_parser__", _parser)(
            fields,
            ix.schema,
            group,
            **kwargs,
        )
        return ix.search(parser.parse(query), limit=limit) 
开发者ID:honmaple,项目名称:flask-msearch,代码行数:21,代码来源:whoosh_backend.py

示例3: search

# 需要导入模块: from whoosh import qparser [as 别名]
# 或者: from whoosh.qparser import MultifieldParser [as 别名]
def search(self, query, sortedby=None, limit=None):
        parser = qparser.MultifieldParser(
            ['owner', 'name', 'title', 'summary'],
            schema=self.schema
        )
        parser.add_plugin(qparser.FuzzyTermPlugin())

        if not isinstance(query, Query):
            query = parser.parse(query or 'name:*')

        with self.index.searcher() as searcher:
            if sortedby:
                facets = []
                for field in sortedby.split(','):
                    reverse = field.startswith('-')
                    if reverse:
                        field = field[1:]

                    if 'sort_' + field in self.schema:
                        field = 'sort_' + field
                    facets.append(FieldFacet(field, reverse=reverse))

                if len(facets) == 1:
                    sortedby = facets[0]
                else:
                    sortedby = MultiFacet(facets)

            for result in searcher.search(
                    query,
                    limit=limit,
                    sortedby=sortedby):

                d = JSONDict(self.db.mods[result['name_id']])
                d.score = result.score
                yield d 
开发者ID:mickael9,项目名称:fac,代码行数:37,代码来源:db.py

示例4: __init__

# 需要导入模块: from whoosh import qparser [as 别名]
# 或者: from whoosh.qparser import MultifieldParser [as 别名]
def __init__(self, index_path, language):
        from whoosh import index as whoosh_index
        from whoosh.fields import Schema, TEXT, ID
        from whoosh import qparser
        from whoosh.highlight import UppercaseFormatter
        from whoosh.analysis import SimpleAnalyzer, LanguageAnalyzer
        from whoosh.lang import has_stemmer, has_stopwords
        import os

        if not has_stemmer(language) or not has_stopwords(language):
            # TODO Display a warning?
            analyzer = SimpleAnalyzer()
        else:
            analyzer = LanguageAnalyzer(language)

        self.schema = Schema(path=ID(unique=True, stored=True), body=TEXT(analyzer=analyzer))
        self.formatter = UppercaseFormatter()

        self.index_path = index_path

        if not os.path.exists(index_path):
            try:
                os.mkdir(index_path)
            except OSError as e:
                sys.exit("Error creating Whoosh index: %s" % e)

        if whoosh_index.exists_in(index_path):
            try:
                self.search_index = whoosh_index.open_dir(index_path)
            except whoosh_index.IndexError as e:
                sys.exit("Error opening whoosh index: {0}".format(e))
        else:
            self.search_index = whoosh_index.create_in(index_path, self.schema)

        self.query_parser = qparser.MultifieldParser(["body", "path"], schema=self.schema)
        self.query_parser.add_plugin(qparser.FuzzyTermPlugin()) 
开发者ID:scragg0x,项目名称:realms-wiki,代码行数:38,代码来源:models.py

示例5: prepare_query

# 需要导入模块: from whoosh import qparser [as 别名]
# 或者: from whoosh.qparser import MultifieldParser [as 别名]
def prepare_query(self, query):
        query = (
            query
            .replace('-in:', 'AND NOT tag:')
            .replace('in:all', '*')
        )
        return MultifieldParser(['body', 'subject', 'raw'], self._index.schema).parse(query) 
开发者ID:pixelated,项目名称:pixelated-user-agent,代码行数:9,代码来源:__init__.py

示例6: build_keywords_query

# 需要导入模块: from whoosh import qparser [as 别名]
# 或者: from whoosh.qparser import MultifieldParser [as 别名]
def build_keywords_query(keywords):
    """
    Build parsers for a query.

    :param MultiDict keywords: The search texts keyed by scope key. If empty,
        the query will match every documents.
    """
    queries = []
    if keywords:
        composer = current_app.config['KERKO_COMPOSER']
        text_plugins = [
            plugins.PhrasePlugin(),
            plugins.GroupPlugin(),
            plugins.OperatorsPlugin(
                And=r"(?<=\s)" + re.escape(gettext("AND")) + r"(?=\s)",
                Or=r"(?<=\s)" + re.escape(gettext("OR")) + r"(?=\s)",
                Not=r"(^|(?<=(\s|[()])))" + re.escape(gettext("NOT")) + r"(?=\s)",
                AndNot=None,
                AndMaybe=None,
                Require=None
            ),
            plugins.BoostPlugin(),
        ]
        for key, value in keywords.items(multi=True):
            fields = [spec.key for spec in composer.fields.values() if key in spec.scopes]
            if not fields:
                raise KeyError  # No known field for that scope key.
            parser = MultifieldParser(
                fields, schema=composer.schema, plugins=text_plugins
            )
            queries.append(parser.parse(value))
    else:
        queries.append(Every())
    return And(queries) 
开发者ID:whiskyechobravo,项目名称:kerko,代码行数:36,代码来源:query.py


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