def extract_document(cls, obj_id, obj=None): if obj is None: model = cls.get_model() obj = model.objects.select_related( 'current_revision', 'parent').get(pk=obj_id) if obj.html.startswith(REDIRECT_HTML): # It's possible this document is indexed and was turned # into a redirect, so now we want to explicitly unindex # it. The way we do that is by throwing an exception # which gets handled by the indexing machinery. raise UnindexMeBro() d = {} d['id'] = obj.id d['model'] = cls.get_mapping_type_name() d['url'] = obj.get_absolute_url() d['indexed_on'] = int(time.time()) d['topic'] = [t.slug for t in obj.get_topics()] d['product'] = [p.slug for p in obj.get_products()] d['document_title'] = obj.title d['document_locale'] = obj.locale d['document_parent_id'] = obj.parent.id if obj.parent else None d['document_content'] = obj.html d['document_category'] = obj.category d['document_slug'] = obj.slug d['document_is_archived'] = obj.is_archived d['document_display_order'] = obj.original.display_order d['document_summary'] = obj.summary if obj.current_revision is not None: d['document_keywords'] = obj.current_revision.keywords d['updated'] = int(time.mktime( obj.current_revision.created.timetuple())) d['document_current_id'] = obj.current_revision.id d['document_recent_helpful_votes'] = obj.recent_helpful_votes else: d['document_summary'] = None d['document_keywords'] = None d['updated'] = None d['document_current_id'] = None d['document_recent_helpful_votes'] = 0 # Don't query for helpful votes if the document doesn't have a current # revision, or is a template, or is a redirect, or is in Navigation # category (50). if (obj.current_revision and not obj.is_template and not obj.html.startswith(REDIRECT_HTML) and not obj.category == 50): d['document_recent_helpful_votes'] = obj.recent_helpful_votes else: d['document_recent_helpful_votes'] = 0 # Select a locale-appropriate default analyzer for all strings. d['_analyzer'] = es_analyzer_for_locale(obj.locale) return d
def extract_document(cls, obj_id, obj=None): if obj is None: model = cls.get_model() obj = model.uncached.select_related( 'current_revision', 'parent').get(pk=obj_id) if obj.html.startswith(REDIRECT_HTML): # It's possible this document is indexed and was turned # into a redirect, so now we want to explicitly unindex # it. The way we do that is by throwing an exception # which gets handled by the indexing machinery. raise UnindexMeBro() d = {} d['id'] = obj.id d['model'] = cls.get_mapping_type_name() d['url'] = obj.get_absolute_url() d['indexed_on'] = int(time.time()) d['topic'] = [t.slug for t in obj.get_topics(True)] d['product'] = [p.slug for p in obj.get_products(True)] d['document_title'] = obj.title d['document_locale'] = obj.locale d['document_parent_id'] = obj.parent.id if obj.parent else None d['document_content'] = obj.html d['document_category'] = obj.category d['document_slug'] = obj.slug d['document_is_archived'] = obj.is_archived if obj.current_revision is not None: d['document_summary'] = obj.current_revision.summary d['document_keywords'] = obj.current_revision.keywords d['updated'] = int(time.mktime( obj.current_revision.created.timetuple())) d['document_current_id'] = obj.current_revision.id d['document_recent_helpful_votes'] = obj.recent_helpful_votes else: d['document_summary'] = None d['document_keywords'] = None d['updated'] = None d['document_current_id'] = None d['document_recent_helpful_votes'] = 0 # Don't query for helpful votes if the document doesn't have a current # revision, or is a template, or is a redirect, or is in Navigation # category (50). if (obj.current_revision and not obj.is_template and not obj.html.startswith(REDIRECT_HTML) and not obj.category == 50): d['document_recent_helpful_votes'] = obj.recent_helpful_votes else: d['document_recent_helpful_votes'] = 0 # Select a locale-appropriate default analyzer for all strings. d['_analyzer'] = es_analyzer_for_locale(obj.locale) return d
def test_with_synonyms_wrong_locale(self): actual = es_utils.es_analyzer_for_locale('es', synonyms=True) eq_('snowball-spanish', actual)
def test_with_synonyms_right_locale(self): actual = es_utils.es_analyzer_for_locale('en-US', synonyms=True) eq_('snowball-english-synonyms', actual)
def test_without_synonyms(self): actual = es_utils.es_analyzer_for_locale('en-US', synonyms=False) eq_('snowball-english', actual)
def test_default(self): actual = es_utils.es_analyzer_for_locale('en-US') eq_('snowball-english', actual)
def test_with_synonyms_wrong_locale(self): actual = es_utils.es_analyzer_for_locale('es', synonyms=True) eq_('snowball-spanish', actual)
def test_with_synonyms_right_locale(self): actual = es_utils.es_analyzer_for_locale('en-US', synonyms=True) eq_('snowball-english-synonyms', actual)
def test_without_synonyms(self): actual = es_utils.es_analyzer_for_locale('en-US', synonyms=False) eq_('snowball-english', actual)
def test_default(self): actual = es_utils.es_analyzer_for_locale('en-US') eq_('snowball-english', actual)
def test_default(self): actual = es_utils.es_analyzer_for_locale("en-US") eq_("snowball-english", actual)
def test_default(self): actual = es_utils.es_analyzer_for_locale("en-US") eq_("snowball-english", actual)