本文整理汇总了Python中olympia.addons.indexers.AddonIndexer类的典型用法代码示例。如果您正苦于以下问题:Python AddonIndexer类的具体用法?Python AddonIndexer怎么用?Python AddonIndexer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AddonIndexer类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search
def search(self):
self.reindex(Addon)
qs = Search(using=amo.search.get_es(),
index=AddonIndexer.get_index_alias(),
doc_type=AddonIndexer.get_doctype_name())
return qs.filter('term', id=self.addon.pk).execute()[0]
示例2: find_inconsistencies_between_es_and_db
def find_inconsistencies_between_es_and_db(ids, **kw):
length = len(ids)
log.info(
'Searching for inconsistencies between db and es %d-%d [%d].',
ids[0], ids[-1], length)
db_addons = Addon.unfiltered.in_bulk(ids)
es_addons = Search(
doc_type=AddonIndexer.get_doctype_name(),
index=AddonIndexer.get_index_alias(),
using=amo.search.get_es()).filter('ids', values=ids)[:length].execute()
es_addons = es_addons
db_len = len(db_addons)
es_len = len(es_addons)
if db_len != es_len:
log.info('Inconsistency found: %d in db vs %d in es.',
db_len, es_len)
for result in es_addons.hits.hits:
pk = result['_source']['id']
db_modified = db_addons[pk].modified.isoformat()
es_modified = result['_source']['modified']
if db_modified != es_modified:
log.info('Inconsistency found for addon %d: '
'modified is %s in db vs %s in es.',
pk, db_modified, es_modified)
db_status = db_addons[pk].status
es_status = result['_source']['status']
if db_status != es_status:
log.info('Inconsistency found for addon %d: '
'status is %s in db vs %s in es.',
pk, db_status, es_status)
示例3: serialize
def serialize(self):
self.reindex(Addon)
qs = Search(using=amo.search.get_es(),
index=AddonIndexer.get_index_alias(),
doc_type=AddonIndexer.get_doctype_name())
obj = qs.filter('term', id=self.addon.pk).execute()[0]
with self.assertNumQueries(0):
serializer = ESAddonSerializer(context={'request': self.request})
result = serializer.to_representation(obj)
return result
示例4: test_mapping
def test_mapping(self):
"""Compare actual mapping in ES with the one the indexer returns, once
an object has been indexed.
We don't want dynamic mapping for addons (too risky), so the two
mappings should be equal."""
self.reindex(Addon)
indexer = AddonIndexer()
doc_name = indexer.get_doctype_name()
real_index_name = self.index_names[SearchMixin.ES_ALIAS_KEY]
mappings = self.es.indices.get_mapping(
indexer.get_index_alias())[real_index_name]['mappings']
actual_properties = mappings[doc_name]['properties']
indexer_properties = indexer.get_mapping()[doc_name]['properties']
assert set(actual_properties.keys()) == set(indexer_properties.keys())
示例5: setUp
def setUp(self):
super(TestAddonIndexer, self).setUp()
self.transforms = (attach_tags, attach_translations)
self.indexer = AddonIndexer()
self.addon = Addon.objects.get(pk=3615)
示例6: TestAddonIndexer
class TestAddonIndexer(TestCase):
fixtures = ['base/users', 'base/addon_3615']
# The base list of fields we expect to see in the mapping/extraction.
# This only contains the fields for which we use the value directly,
# see expected_fields() for the rest.
simple_fields = [
'average_daily_users', 'bayesian_rating', 'created', 'default_locale',
'guid', 'hotness', 'icon_type', 'id', 'is_disabled', 'is_experimental',
'is_listed', 'last_updated', 'modified', 'public_stats', 'slug',
'status', 'type', 'view_source', 'weekly_downloads',
]
def setUp(self):
super(TestAddonIndexer, self).setUp()
self.transforms = (attach_tags, attach_translations)
self.indexer = AddonIndexer()
self.addon = Addon.objects.get(pk=3615)
@classmethod
def expected_fields(cls, include_nullable=True):
"""
Returns a list of fields we expect to be present in the mapping and
in the extraction method.
Should be updated whenever you change the mapping to add/remove fields.
"""
# Fields that can not be directly compared with the property of the
# same name on the Addon instance, either because the property doesn't
# exist on the model, or it has a different name, or the value we need
# to store in ES differs from the one in the db.
complex_fields = [
'app', 'appversion', 'boost', 'category', 'current_beta_version',
'current_version', 'description', 'has_eula', 'has_privacy_policy',
'has_theme_rereview', 'has_version', 'listed_authors', 'name',
'name_sort', 'platforms', 'previews', 'public_stats', 'ratings',
'summary', 'tags',
]
# Fields that need to be present in the mapping, but might be skipped
# for extraction because they can be null.
nullable_fields = ['persona']
# For each translated field that needs to be indexed, we store one
# version for each language-specific analyzer we have.
_indexed_translated_fields = ('name', 'description', 'summary')
analyzer_fields = list(chain.from_iterable(
[['%s_%s' % (field, analyzer) for analyzer in SEARCH_ANALYZER_MAP]
for field in _indexed_translated_fields]))
# It'd be annoying to hardcode `analyzer_fields`, so we generate it,
# but to make sure the test is correct we still do a simple check of
# the length to make sure we properly flattened the list.
assert len(analyzer_fields) == (len(SEARCH_ANALYZER_MAP) *
len(_indexed_translated_fields))
# Each translated field that we want to return to the API.
raw_translated_fields = [
'%s_translations' % field for field in
['name', 'description', 'homepage', 'summary', 'support_email',
'support_url']]
# Return a list with the base fields and the dynamic ones added.
fields = (cls.simple_fields + complex_fields + analyzer_fields +
raw_translated_fields)
if include_nullable:
fields += nullable_fields
return fields
def test_mapping(self):
doc_name = self.indexer.get_doctype_name()
assert doc_name
mapping_properties = self.indexer.get_mapping()[doc_name]['properties']
# Make sure the get_mapping() method does not return fields we did
# not expect to be present, or omitted fields we want.
assert set(mapping_properties.keys()) == set(self.expected_fields())
# Make sure default_locale and translated fields are not indexed.
assert mapping_properties['default_locale']['index'] == 'no'
name_translations = mapping_properties['name_translations']
assert name_translations['properties']['lang']['index'] == 'no'
assert name_translations['properties']['string']['index'] == 'no'
# Make sure nothing inside 'persona' is indexed, it's only there to be
# returned back to the API directly.
for field in mapping_properties['persona']['properties'].values():
assert field['index'] == 'no'
# Make sure current_version mapping is set.
assert mapping_properties['current_version']['properties']
version_mapping = mapping_properties['current_version']['properties']
expected_version_keys = (
'id', 'compatible_apps', 'files', 'reviewed', 'version')
assert set(version_mapping.keys()) == set(expected_version_keys)
# Make sure files mapping is set inside current_version.
files_mapping = version_mapping['files']['properties']
expected_file_keys = ('id', 'created', 'filename', 'hash', 'platform',
#.........这里部分代码省略.........
示例7: setUp
def setUp(self):
super(TestAddonIndexer, self).setUp()
self.transforms = (attach_categories, attach_tags, attach_translations)
self.indexer = AddonIndexer()
示例8: TestAddonIndexer
class TestAddonIndexer(TestCase):
fixtures = ['base/users', 'base/addon_3615']
# The base list of fields we expect to see in the mapping/extraction.
# This only contains the fields for which we use the value directly,
# see expected_fields() for the rest.
simple_fields = [
'average_daily_users', 'bayesian_rating', 'contributions', 'created',
'default_locale', 'guid', 'hotness', 'icon_hash', 'icon_type', 'id',
'is_disabled', 'is_experimental', 'last_updated', 'modified',
'public_stats', 'requires_payment', 'slug', 'status', 'type',
'view_source', 'weekly_downloads',
]
def setUp(self):
super(TestAddonIndexer, self).setUp()
self.transforms = (attach_tags, attach_translations)
self.indexer = AddonIndexer()
self.addon = Addon.objects.get(pk=3615)
@classmethod
def expected_fields(cls, include_nullable=True):
"""
Returns a list of fields we expect to be present in the mapping and
in the extraction method.
Should be updated whenever you change the mapping to add/remove fields.
"""
# Fields that can not be directly compared with the property of the
# same name on the Addon instance, either because the property doesn't
# exist on the model, or it has a different name, or the value we need
# to store in ES differs from the one in the db.
complex_fields = [
'app', 'boost', 'category', 'colors', 'current_version',
'description', 'featured_for', 'has_eula', 'has_privacy_policy',
'is_featured', 'listed_authors', 'name',
'platforms', 'previews', 'public_stats', 'ratings', 'summary',
'tags',
]
# Fields that need to be present in the mapping, but might be skipped
# for extraction because they can be null.
nullable_fields = ['persona']
# For each translated field that needs to be indexed, we store one
# version for each language-specific analyzer we have.
_indexed_translated_fields = ('name', 'description', 'summary')
analyzer_fields = list(chain.from_iterable(
[['%s_l10n_%s' % (field, analyzer) for analyzer
in SEARCH_ANALYZER_MAP] for field in _indexed_translated_fields]))
# It'd be annoying to hardcode `analyzer_fields`, so we generate it,
# but to make sure the test is correct we still do a simple check of
# the length to make sure we properly flattened the list.
assert len(analyzer_fields) == (len(SEARCH_ANALYZER_MAP) *
len(_indexed_translated_fields))
# Each translated field that we want to return to the API.
raw_translated_fields = [
'%s_translations' % field for field in
['name', 'description', 'developer_comments', 'homepage',
'summary', 'support_email', 'support_url']]
# Return a list with the base fields and the dynamic ones added.
fields = (cls.simple_fields + complex_fields + analyzer_fields +
raw_translated_fields)
if include_nullable:
fields += nullable_fields
return fields
def test_mapping(self):
doc_name = self.indexer.get_doctype_name()
assert doc_name
mapping_properties = self.indexer.get_mapping()[doc_name]['properties']
# Make sure the get_mapping() method does not return fields we did
# not expect to be present, or omitted fields we want.
assert set(mapping_properties.keys()) == set(self.expected_fields())
# Make sure default_locale and translated fields are not indexed.
assert mapping_properties['default_locale']['index'] is False
name_translations = mapping_properties['name_translations']
assert name_translations['properties']['lang']['index'] is False
assert name_translations['properties']['string']['index'] is False
# Make sure nothing inside 'persona' is indexed, it's only there to be
# returned back to the API directly.
for field in mapping_properties['persona']['properties'].values():
assert field['index'] is False
# Make sure current_version mapping is set.
assert mapping_properties['current_version']['properties']
version_mapping = mapping_properties['current_version']['properties']
expected_version_keys = (
'id', 'compatible_apps', 'files', 'license',
'release_notes_translations', 'reviewed', 'version')
assert set(version_mapping.keys()) == set(expected_version_keys)
# Make sure files mapping is set inside current_version.
#.........这里部分代码省略.........
示例9: TestAddonIndexer
class TestAddonIndexer(TestCase):
fixtures = ['base/users', 'base/addon_3615']
# The base list of fields we expect to see in the mapping/extraction.
# This only contains the fields for which we use the value directly,
# see expected_fields() for the rest.
simple_fields = [
'average_daily_users', 'bayesian_rating', 'contributions', 'created',
'default_locale',
'guid', 'hotness', 'icon_type', 'id', 'is_disabled', 'is_experimental',
'last_updated', 'modified', 'public_stats', 'requires_payment', 'slug',
'status', 'type', 'view_source', 'weekly_downloads',
]
def setUp(self):
super(TestAddonIndexer, self).setUp()
self.transforms = (attach_tags, attach_translations)
self.indexer = AddonIndexer()
self.addon = Addon.objects.get(pk=3615)
@classmethod
def expected_fields(cls, include_nullable=True):
"""
Returns a list of fields we expect to be present in the mapping and
in the extraction method.
Should be updated whenever you change the mapping to add/remove fields.
"""
# Fields that can not be directly compared with the property of the
# same name on the Addon instance, either because the property doesn't
# exist on the model, or it has a different name, or the value we need
# to store in ES differs from the one in the db.
complex_fields = [
'app', 'boost', 'category', 'current_beta_version',
'current_version', 'description', 'featured_for',
'has_eula', 'has_privacy_policy',
'has_theme_rereview', 'is_featured', 'latest_unlisted_version',
'listed_authors', 'name', 'name_sort', 'platforms', 'previews',
'public_stats', 'ratings', 'summary', 'tags',
]
# Fields that need to be present in the mapping, but might be skipped
# for extraction because they can be null.
nullable_fields = ['persona']
# For each translated field that needs to be indexed, we store one
# version for each language-specific analyzer we have.
_indexed_translated_fields = ('name', 'description', 'summary')
analyzer_fields = list(chain.from_iterable(
[['%s_l10n_%s' % (field, analyzer) for analyzer
in SEARCH_ANALYZER_MAP] for field in _indexed_translated_fields]))
# It'd be annoying to hardcode `analyzer_fields`, so we generate it,
# but to make sure the test is correct we still do a simple check of
# the length to make sure we properly flattened the list.
assert len(analyzer_fields) == (len(SEARCH_ANALYZER_MAP) *
len(_indexed_translated_fields))
# Each translated field that we want to return to the API.
raw_translated_fields = [
'%s_translations' % field for field in
['name', 'description', 'developer_comments', 'homepage',
'summary', 'support_email', 'support_url']]
# Return a list with the base fields and the dynamic ones added.
fields = (cls.simple_fields + complex_fields + analyzer_fields +
raw_translated_fields)
if include_nullable:
fields += nullable_fields
return fields
def test_mapping(self):
doc_name = self.indexer.get_doctype_name()
assert doc_name
mapping_properties = self.indexer.get_mapping()[doc_name]['properties']
# Make sure the get_mapping() method does not return fields we did
# not expect to be present, or omitted fields we want.
assert set(mapping_properties.keys()) == set(self.expected_fields())
# Make sure default_locale and translated fields are not indexed.
assert mapping_properties['default_locale']['index'] is False
name_translations = mapping_properties['name_translations']
assert name_translations['properties']['lang']['index'] is False
assert name_translations['properties']['string']['index'] is False
# Make sure nothing inside 'persona' is indexed, it's only there to be
# returned back to the API directly.
for field in mapping_properties['persona']['properties'].values():
assert field['index'] is False
# Make sure current_version mapping is set.
assert mapping_properties['current_version']['properties']
version_mapping = mapping_properties['current_version']['properties']
expected_version_keys = (
'id', 'compatible_apps', 'files', 'reviewed', 'version')
assert set(version_mapping.keys()) == set(expected_version_keys)
# Make sure files mapping is set inside current_version.
#.........这里部分代码省略.........