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


Python SolrQuery.set_facet_options方法代码示例

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


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

示例1: get_user_tags

# 需要导入模块: from utils.search.solr import SolrQuery [as 别名]
# 或者: from utils.search.solr.SolrQuery import set_facet_options [as 别名]
    def get_user_tags(self, use_solr=True):
        if use_solr:
            query = SolrQuery()
            query.set_dismax_query('')
            filter_query = 'username:\"%s\"' % self.user.username
            query.set_query_options(field_list=["id"], filter_query=filter_query)
            query.add_facet_fields("tag")
            query.set_facet_options("tag", limit=10, mincount=1)
            solr = Solr(settings.SOLR_URL)

            try:
                results = SolrResponseInterpreter(solr.select(unicode(query)))
            except SolrException as e:
                return False
            except Exception as e:
                return False

            return [{'name': tag, 'count': count} for tag, count in results.facets['tag']]

        else:
            return DelayedQueryExecuter("""
                   SELECT tags_tag.name AS name, X.c AS count
                     FROM ( SELECT tag_id, count(*) as c
                              FROM tags_taggeditem
                         LEFT JOIN sounds_sound ON object_id=sounds_sound.id
                             WHERE tags_taggeditem.user_id=%d AND
                                   sounds_sound.moderation_state='OK' AND
                                   sounds_sound.processing_state='OK'
                          GROUP BY tag_id
                          ORDER BY c
                        DESC LIMIT 10) AS X
                LEFT JOIN tags_tag ON tags_tag.id=X.tag_id
                 ORDER BY tags_tag.name;""" % self.user_id)
开发者ID:qubodup,项目名称:freesound,代码行数:35,代码来源:models.py

示例2: get_pack_tags

# 需要导入模块: from utils.search.solr import SolrQuery [as 别名]
# 或者: from utils.search.solr.SolrQuery import set_facet_options [as 别名]
def get_pack_tags(pack_obj):
    query = SolrQuery()
    query.set_dismax_query('')
    filter_query = 'username:\"%s\" pack:\"%s\"' % (pack_obj.user.username, pack_obj.name)
    query.set_query_options(field_list=["id"], filter_query=filter_query)
    query.add_facet_fields("tag")
    query.set_facet_options("tag", limit=20, mincount=1)
    try:
        solr = Solr(settings.SOLR_URL)
        results = SolrResponseInterpreter(solr.select(unicode(query)))
    except (SolrException, Exception) as e:
        #  TODO: do something here?
        return False
    return results.facets
开发者ID:MTG,项目名称:freesound,代码行数:16,代码来源:views.py

示例3: search_prepare_query

# 需要导入模块: from utils.search.solr import SolrQuery [as 别名]
# 或者: from utils.search.solr.SolrQuery import set_facet_options [as 别名]
def search_prepare_query(search_query,
                         filter_query,
                         sort,
                         current_page,
                         sounds_per_page,
                         id_weight = DEFAULT_SEARCH_WEIGHTS['id'],
                         tag_weight = DEFAULT_SEARCH_WEIGHTS['tag'],
                         description_weight = DEFAULT_SEARCH_WEIGHTS['description'],
                         username_weight = DEFAULT_SEARCH_WEIGHTS['username'],
                         pack_tokenized_weight = DEFAULT_SEARCH_WEIGHTS['pack_tokenized'],
                         original_filename_weight = DEFAULT_SEARCH_WEIGHTS['original_filename'],
                         grouping = False,
                         include_facets = True,
                         grouping_pack_limit = 1):
    query = SolrQuery()

    field_weights = []
    if id_weight != 0 :
        field_weights.append(("id", id_weight))
    if tag_weight != 0 :
        field_weights.append(("tag", tag_weight))
    if description_weight != 0 :
        field_weights.append(("description", description_weight))
    if username_weight != 0 :
        field_weights.append(("username", username_weight))
    if pack_tokenized_weight != 0 :
        field_weights.append(("pack_tokenized", pack_tokenized_weight))
    if original_filename_weight != 0 :
        field_weights.append(("original_filename", original_filename_weight))

    query.set_dismax_query(search_query,
                           query_fields=field_weights,)
    query.set_query_options(start=(current_page - 1) * sounds_per_page, rows=sounds_per_page, field_list=["id"], filter_query=filter_query, sort=sort)

    if include_facets:
        query.add_facet_fields("samplerate", "grouping_pack", "username", "tag", "bitrate", "bitdepth", "type", "channels", "license")
        query.set_facet_options_default(limit=5, sort=True, mincount=1, count_missing=False)
        query.set_facet_options("tag", limit=30)
        query.set_facet_options("username", limit=30)
        query.set_facet_options("grouping_pack", limit=10)
        query.set_facet_options("license", limit=10)

    if grouping:
        query.set_group_field(group_field="grouping_pack")
        query.set_group_options(group_func=None,
            group_query=None,
            group_rows=10,
            group_start=0,
            group_limit=grouping_pack_limit,  # This is the number of documents that will be returned for each group. By default only 1 is returned.
            group_offset=0,
            group_sort=None,
            group_sort_ingroup=None,
            group_format='grouped',
            group_main=False,
            group_num_groups=True,
            group_cache_percent=0)


    return query
开发者ID:darad,项目名称:freesound,代码行数:61,代码来源:views.py

示例4: int

# 需要导入模块: from utils.search.solr import SolrQuery [as 别名]
# 或者: from utils.search.solr.SolrQuery import set_facet_options [as 别名]
        
        count = int(count)

        results_before += count

        # clean the only few things DisMax doesn't like... :)
        search = search.strip("+-").replace("--", "").replace("+-", "").replace("-+", "").replace("++", "")
        if search == "\"" or search == "\"\"":
            search = ""

        query = SolrQuery()
        query.set_dismax_query(search, query_fields=[("id", 4), ("tag",3), ("description",3), ("username",2), ("pack_original",2), ("filename",2), "comment"])
        query.set_query_options(start=0, rows=10, field_list=["id"])
        query.add_facet_fields("samplerate", "pack_original", "username", "tag", "bitrate", "bitdepth")
        query.set_facet_options_default(limit=5, sort=True, mincount=1, count_missing=True)
        query.set_facet_options("tag", limit=30)
        query.set_facet_options("username", limit=30)
        
        response = solr.select(unicode(query))
        interpreted = SolrResponseInterpreter(response)

        num_queries_total += 1
        num_queries_this_loop += 1
        
        time_solr += interpreted.q_time
        results_solr += interpreted.num_found

    except KeyboardInterrupt:
        break
    except UnicodeDecodeError:
        pass
开发者ID:LoodVogel,项目名称:freesound,代码行数:33,代码来源:freesound_test.py

示例5: search_prepare_query

# 需要导入模块: from utils.search.solr import SolrQuery [as 别名]
# 或者: from utils.search.solr.SolrQuery import set_facet_options [as 别名]
def search_prepare_query(search_query,
                         filter_query,
                         sort,
                         current_page,
                         sounds_per_page,
                         id_weight=settings.DEFAULT_SEARCH_WEIGHTS['id'],
                         tag_weight=settings.DEFAULT_SEARCH_WEIGHTS['tag'],
                         description_weight=settings.DEFAULT_SEARCH_WEIGHTS['description'],
                         username_weight=settings.DEFAULT_SEARCH_WEIGHTS['username'],
                         pack_tokenized_weight=settings.DEFAULT_SEARCH_WEIGHTS['pack_tokenized'],
                         original_filename_weight=settings.DEFAULT_SEARCH_WEIGHTS['original_filename'],
                         grouping=False,
                         include_facets=True,
                         grouping_pack_limit=1,
                         offset=None):
    query = SolrQuery()

    # Set field weights and scoring function
    field_weights = []
    if id_weight != 0:
        field_weights.append(("id", id_weight))
    if tag_weight != 0:
        field_weights.append(("tag", tag_weight))
    if description_weight != 0:
        field_weights.append(("description", description_weight))
    if username_weight != 0:
        field_weights.append(("username", username_weight))
    if pack_tokenized_weight != 0:
        field_weights.append(("pack_tokenized", pack_tokenized_weight))
    if original_filename_weight != 0:
        field_weights.append(("original_filename", original_filename_weight))
    query.set_dismax_query(search_query,
                           query_fields=field_weights,)

    # Set start and rows parameters (offset and size)
    if not offset:
        start = (current_page - 1) * sounds_per_page
    else:
        start = offset

    # Process filter
    filter_query = search_process_filter(filter_query)

    # Set all options
    query.set_query_options(start=start, rows=sounds_per_page, field_list=["id"], filter_query=filter_query, sort=sort)

    # Specify query factes
    if include_facets:
        query.add_facet_fields("samplerate", "grouping_pack", "username", "tag", "bitrate", "bitdepth", "type", "channels", "license")
        query.set_facet_options_default(limit=5, sort=True, mincount=1, count_missing=False)
        query.set_facet_options("type", limit=len(sounds.models.Sound.SOUND_TYPE_CHOICES))
        query.set_facet_options("tag", limit=30)
        query.set_facet_options("username", limit=30)
        query.set_facet_options("grouping_pack", limit=10)
        query.set_facet_options("license", limit=10)

    # Add groups
    if grouping:
        query.set_group_field(group_field="grouping_pack")
        query.set_group_options(
            group_func=None,
            group_query=None,
            group_rows=10,
            group_start=0,
            group_limit=grouping_pack_limit,  # This is the number of documents that will be returned for each group. By default only 1 is returned.
            group_offset=0,
            group_sort=None,
            group_sort_ingroup=None,
            group_format='grouped',
            group_main=False,
            group_num_groups=True,
            group_cache_percent=0)
    return query
开发者ID:MTG,项目名称:freesound,代码行数:75,代码来源:views.py


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