本文整理汇总了Python中mkt.feed.indexers.FeedItemIndexer.search方法的典型用法代码示例。如果您正苦于以下问题:Python FeedItemIndexer.search方法的具体用法?Python FeedItemIndexer.search怎么用?Python FeedItemIndexer.search使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mkt.feed.indexers.FeedItemIndexer
的用法示例。
在下文中一共展示了FeedItemIndexer.search方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get
# 需要导入模块: from mkt.feed.indexers import FeedItemIndexer [as 别名]
# 或者: from mkt.feed.indexers.FeedItemIndexer import search [as 别名]
def _get(self, request, rest_of_world=False, original_region=None,
*args, **kwargs):
es = FeedItemIndexer.get_es()
# Parse region.
if rest_of_world:
region = mkt.regions.RESTOFWORLD.id
else:
region = request.REGION.id
# Parse carrier.
carrier = None
q = request.QUERY_PARAMS
if q.get('carrier') and q['carrier'] in mkt.carriers.CARRIER_MAP:
carrier = mkt.carriers.CARRIER_MAP[q['carrier']].id
# Fetch FeedItems.
sq = self.get_es_feed_query(FeedItemIndexer.search(using=es),
region=region, carrier=carrier,
original_region=original_region)
# The paginator triggers the ES request.
with statsd.timer('mkt.feed.view.feed_query'):
feed_items = self.paginate_queryset(sq)
feed_ok = self._check_empty_feed(feed_items, rest_of_world)
if feed_ok != 1:
return self._handle_empty_feed(feed_ok, region, request, args,
kwargs)
# Build the meta object.
meta = mkt.api.paginator.CustomPaginationSerializer(
feed_items, context={'request': request}).data['meta']
# Set up serializer context.
feed_element_map = {
feed.FEED_TYPE_APP: {},
feed.FEED_TYPE_BRAND: {},
feed.FEED_TYPE_COLL: {},
feed.FEED_TYPE_SHELF: {},
}
# Fetch feed elements to attach to FeedItems later.
apps = []
sq = self.get_es_feed_element_query(
Search(using=es, index=self.get_feed_element_index()), feed_items)
with statsd.timer('mkt.feed.view.feed_element_query'):
feed_elements = sq.execute().hits
for feed_elm in feed_elements:
# Store the feed elements to attach to FeedItems later.
feed_element_map[feed_elm['item_type']][feed_elm['id']] = feed_elm
# Store the apps to retrieve later.
apps += self.get_app_ids(feed_elm)
# Remove dupes from apps list.
apps = list(set(apps))
# Fetch apps to attach to feed elements later.
app_map = self.get_apps(request, apps)
# Super serialize.
with statsd.timer('mkt.feed.view.serialize'):
feed_items = FeedItemESSerializer(feed_items, many=True, context={
'app_map': app_map,
'feed_element_map': feed_element_map,
'request': request
}).data
# Filter excluded apps. If there are feed items that have all their
# apps excluded, they will be removed from the feed.
feed_items = self.filter_feed_items(request, feed_items)
feed_ok = self._check_empty_feed(feed_items, rest_of_world)
if feed_ok != 1:
if not rest_of_world:
log.warning('Feed empty for region {0}. Requerying feed with '
'region=RESTOFWORLD'.format(region))
return self._handle_empty_feed(feed_ok, region, request, args,
kwargs)
return response.Response({'meta': meta, 'objects': feed_items},
status=status.HTTP_200_OK)
示例2: _get
# 需要导入模块: from mkt.feed.indexers import FeedItemIndexer [as 别名]
# 或者: from mkt.feed.indexers.FeedItemIndexer import search [as 别名]
def _get(self, request, rest_of_world=False, original_region=None, *args, **kwargs):
es = FeedItemIndexer.get_es()
# Parse region.
if rest_of_world:
region = mkt.regions.RESTOFWORLD.id
else:
region = request.REGION.id
# Parse carrier.
carrier = None
q = request.query_params
if q.get("carrier") and q["carrier"] in mkt.carriers.CARRIER_MAP:
carrier = mkt.carriers.CARRIER_MAP[q["carrier"]].id
# Fetch FeedItems.
sq = self.get_es_feed_query(
FeedItemIndexer.search(using=es), region=region, carrier=carrier, original_region=original_region
)
# The paginator triggers the ES request.
with statsd.timer("mkt.feed.view.feed_query"):
feed_items = self.paginate_queryset(sq)
feed_ok = self._check_empty_feed(feed_items, rest_of_world)
if feed_ok != 1:
return self._handle_empty_feed(feed_ok, region, request, args, kwargs)
# Build the meta object.
meta = self.paginator.get_paginated_response(feed_items).data["meta"]
# Set up serializer context.
feed_element_map = {
feed.FEED_TYPE_APP: {},
feed.FEED_TYPE_BRAND: {},
feed.FEED_TYPE_COLL: {},
feed.FEED_TYPE_SHELF: {},
}
# Fetch feed elements to attach to FeedItems later.
apps = []
sq = self.get_es_feed_element_query(Search(using=es, index=self.get_feed_element_index()), feed_items)
with statsd.timer("mkt.feed.view.feed_element_query"):
feed_elements = sq.execute().hits
for feed_elm in feed_elements:
# Store the feed elements to attach to FeedItems later.
feed_element_map[feed_elm["item_type"]][feed_elm["id"]] = feed_elm
# Store the apps to retrieve later.
apps += self.get_app_ids(feed_elm)
# Remove dupes from apps list.
apps = list(set(apps))
# Fetch apps to attach to feed elements later.
app_map = self.get_apps(request, apps)
# Super serialize.
with statsd.timer("mkt.feed.view.serialize"):
feed_items = FeedItemESSerializer(
feed_items,
many=True,
context={"app_map": app_map, "feed_element_map": feed_element_map, "request": request},
).data
# Filter excluded apps. If there are feed items that have all their
# apps excluded, they will be removed from the feed.
feed_items = self.filter_feed_items(request, feed_items)
feed_ok = self._check_empty_feed(feed_items, rest_of_world)
if feed_ok != 1:
if not rest_of_world:
log.warning("Feed empty for region {0}. Requerying feed with " "region=RESTOFWORLD".format(region))
return self._handle_empty_feed(feed_ok, region, request, args, kwargs)
with statsd.timer("mkt.feed.view.feed_website_query"):
websites = self.get_featured_websites()
return response.Response({"meta": meta, "objects": feed_items, "websites": websites}, status=status.HTTP_200_OK)
示例3: _get
# 需要导入模块: from mkt.feed.indexers import FeedItemIndexer [as 别名]
# 或者: from mkt.feed.indexers.FeedItemIndexer import search [as 别名]
def _get(self, request, *args, **kwargs):
es = FeedItemIndexer.get_es()
# Parse carrier and region.
q = request.QUERY_PARAMS
region = request.REGION.id
carrier = None
if q.get('carrier') and q['carrier'] in mkt.carriers.CARRIER_MAP:
carrier = mkt.carriers.CARRIER_MAP[q['carrier']].id
# Fetch FeedItems.
sq = self.get_es_feed_query(FeedItemIndexer.search(using=es),
region=region, carrier=carrier)
feed_items = self.paginate_queryset(sq)
# No items returned; try to fall back to RoW.
if not feed_items:
world_sq = self.get_es_feed_query(FeedItemIndexer.search(using=es))
world_feed_items = self.paginate_queryset(world_sq)
# No RoW feed items, either. Let's 404.
if not world_feed_items:
world_meta = mkt.api.paginator.CustomPaginationSerializer(
world_feed_items,
context={'request': request}).data['meta']
return response.Response({'meta': world_meta, 'objects': []},
status=status.HTTP_404_NOT_FOUND)
# Return RoW items.
else:
feed_items = world_feed_items
# Build the meta object.
meta = mkt.api.paginator.CustomPaginationSerializer(
feed_items, context={'request': request}).data['meta']
# Set up serializer context.
feed_element_map = {
feed.FEED_TYPE_APP: {},
feed.FEED_TYPE_BRAND: {},
feed.FEED_TYPE_COLL: {},
feed.FEED_TYPE_SHELF: {},
}
# Fetch feed elements to attach to FeedItems later.
apps = []
sq = self.get_es_feed_element_query(
Search(using=es, index=self.get_feed_element_index()), feed_items)
for feed_elm in sq.execute().hits:
# Store the feed elements to attach to FeedItems later.
feed_element_map[feed_elm['item_type']][feed_elm['id']] = feed_elm
# Store the apps to retrieve later.
apps += self.get_app_ids(feed_elm)
# Fetch apps to attach to feed elements later (with mget).
app_map = self.mget_apps(apps)
# Super serialize.
feed_items = FeedItemESSerializer(feed_items, many=True, context={
'app_map': app_map,
'feed_element_map': feed_element_map,
'request': request
}).data
# Filter excluded apps. If there are feed items that have all their
# apps excluded, they will be removed from the feed.
feed_items = self.filter_apps_feed_items(request, feed_items)
# Slice AFTER filtering so that filtering works correctly.
self.limit_apps_feed_items(feed_items)
# TODO (chuck): paginate after filtering/slicing.
return response.Response({'meta': meta, 'objects': feed_items},
status=status.HTTP_200_OK)