class PackageSearchIndex(SearchIndex): name = CharField(model_attr='name') text = CharField(document=True, use_template=True, null=True, stored=False, template_name='djangopypi/haystack/package_text.txt') author = MultiValueField(stored=False, null=True) classifier = MultiValueField(stored=False, null=True, model_attr='latest__classifiers') summary = CharField(stored=False, null=True, model_attr='latest__summary') description = CharField(stored=False, null=True, model_attr='latest__description') def prepare_author(self, obj): output = [] for user in list(obj.owners.all()) + list(obj.maintainers.all()): output.append(user.get_full_name()) if user.email: output.append(user.email) if obj.latest: info = obj.latest.package_info for field in ( 'author', 'author_email', 'maintainer', 'maintainer_email', ): if info.get(field): output.append(info.get(field)) return output
class AssetIndex(indexes.SearchIndex): text = CharField(document=True, use_template=True) name = CharField() study_type = MultiValueField(faceted=True) species = MultiValueField(faceted=True) discipline = MultiValueField(faceted=True) asset_type = CharField(faceted=True) infrastructure = MultiValueField(faceted=True) featured = MultiValueField(faceted=True) class Meta: abstract = True def prepare_study_type(self, obj): return [facet.name for facet in obj.facet.filter(facet='Study Type')] def prepare_species(self, obj): return [facet.name for facet in obj.facet.filter(facet='Species')] def prepare_discipline(self, obj): return [facet.name for facet in obj.facet.filter(facet='Discipline')] def prepare_infrastructure(self, obj): return [ facet.name for facet in obj.facet.filter(facet='Infrastructure') ] def prepare_asset_type(self, obj): return obj._meta.object_name def prepare_featured(self, obj): return [facet.name for facet in obj.facet.filter(facet='Featured')] def prepare_name(self, obj): return obj.name
class CreatorIndex(ObjectIndex, indexes.SearchIndex, indexes.Indexable): text = indexes.CharField( document=True, use_template=True, template_name='search/indexes/gcd/creator_text.txt') gcd_official_name = indexes.CharField(model_attr="gcd_official_name", boost=DEFAULT_BOOST) name = MultiValueField(boost=DEFAULT_BOOST) facet_model_name = indexes.CharField(faceted=True) year = indexes.IntegerField() sort_name = indexes.CharField(model_attr="gcd_official_name", indexed=False) country = indexes.CharField(model_attr='birth_country__name', indexed=False, faceted=True, null=True) def get_model(self): return Creator def prepare_facet_model_name(self, obj): return "creator" def prepare_name(self, obj): return [(creator_name.name) for creator_name in obj.creator_names.all()] def prepare_year(self, obj): if obj.birth_date.year and '?' not in obj.birth_date.year: return int(obj.birth_date.year) else: return 9999
class BrandIndex(ObjectIndex, indexes.SearchIndex, indexes.Indexable): text = indexes.CharField( document=True, use_template=True, template_name='search/indexes/gcd/publisher_text.txt') name = indexes.CharField(model_attr="name", boost=DEFAULT_BOOST) facet_model_name = indexes.CharField(faceted=True) sort_name = indexes.CharField(model_attr='name', indexed=False) year = indexes.IntegerField() publisher = MultiValueField(faceted=True, indexed=False) def get_model(self): return Brand def prepare_facet_model_name(self, obj): return "brand emblem" def prepare_publisher(self, obj): return [(brand_group.parent.name) for brand_group in obj.group.all()]
class ImageIndex(CelerySearchIndex, Indexable): text = CharField(document=True, use_template=True) title = CharField(model_attr='title') description = CharField(model_attr='description', null=True) published = DateTimeField(model_attr='published') uploaded = DateTimeField(model_attr='uploaded') imaging_telescopes = CharField() guiding_telescopes = CharField() mounts = CharField() imaging_cameras = CharField() guiding_cameras = CharField() pixel_scale = FloatField() field_radius = FloatField() countries = CharField() animated = BooleanField(model_attr='animated') likes = IntegerField() integration = FloatField() moon_phase = FloatField() first_acquisition_date = DateTimeField() last_acquisition_date = DateTimeField() views = IntegerField() solar_system_main_subject = IntegerField() is_deep_sky = BooleanField() is_solar_system = BooleanField() is_sun = BooleanField() is_moon = BooleanField() is_planets = BooleanField() is_comets = BooleanField() is_iotd = BooleanField() is_top_pick = BooleanField() license = IntegerField(model_attr='license') min_aperture = IntegerField() max_aperture = IntegerField() min_pixel_size = IntegerField() max_pixel_size = IntegerField() bookmarks = IntegerField() telescope_types = MultiValueField() camera_types = MultiValueField() comments = IntegerField() is_commercial = BooleanField() subject_type = IntegerField(model_attr='subject_type') acquisition_type = CharField(model_attr='acquisition_type') data_source = CharField(model_attr='data_source') remote_source = CharField(model_attr='remote_source', null=True) username = CharField(model_attr='user__username') objects_in_field = CharField() def index_queryset(self, using=None): return self.get_model().objects.filter(moderator_decision=1).exclude( corrupted=True) def get_model(self): return Image def get_updated_field(self): return "updated" def prepare_imaging_telescopes(self, obj): return [ "%s, %s" % (x.get("make"), x.get("name")) for x in obj.imaging_telescopes.all().values('make', 'name') ] def prepare_guiding_telescopes(self, obj): return [ "%s, %s" % (x.get("make"), x.get("name")) for x in obj.guiding_telescopes.all().values('make', 'name') ] def prepare_mounts(self, obj): return [ "%s, %s" % (x.get("make"), x.get("name")) for x in obj.mounts.all().values('make', 'name') ] def prepare_imaging_cameras(self, obj): return [ "%s, %s" % (x.get("make"), x.get("name")) for x in obj.imaging_cameras.all().values('make', 'name') ] def prepare_guiding_cameras(self, obj): return [ "%s, %s" % (x.get("make"), x.get("name")) for x in obj.guiding_cameras.all().values('make', 'name') ] def prepare_pixel_scale(self, obj): return obj.solution.pixscale if obj.solution else None def prepare_field_radius(self, obj): return obj.solution.radius if obj.solution else None def prepare_likes(self, obj): return _prepare_likes(obj) def prepare_integration(self, obj): return _get_integration(obj) def prepare_moon_phase(self, obj): return _prepare_moon_phase(obj) def prepare_first_acquisition_date(self, obj): return _prepare_first_acquisition_date(obj) def prepare_last_acquisition_date(self, obj): return _prepare_last_acquisition_date(obj) def prepare_views(self, obj): return _prepare_views(obj, 'image') def prepare_bookmarks(self, obj): return _prepare_bookmarks(obj) def prepare_telescope_types(self, obj): return _prepare_telescope_types(obj) def prepare_camera_types(self, obj): return _prepare_camera_types(obj) def prepare_comments(self, obj): return _prepare_comments(obj) def prepare_is_commercial(self, obj): commercial_gear = CommercialGear.objects.filter(image=obj) return commercial_gear.count() > 0 def prepare_is_iotd(self, obj): return hasattr(obj, 'iotd') def prepare_is_top_pick(self, obj): return obj.iotdvote_set.count() > 0 and not hasattr(obj, 'iotd') def prepare_objects_in_field(self, obj): return obj.solution.objects_in_field.join(", ") \ if obj.solution and obj.solution.objects_in_field \ else None def prepare_countries(self, obj): return ' '.join([x.country for x in obj.locations.all() if x.country])
class ImageIndex(SearchIndex, Indexable): text = CharField(document=True, use_template=True) title = CharField(model_attr='title') description = CharField(model_attr='description', null=True) published = DateTimeField(model_attr='published') uploaded = DateTimeField(model_attr='uploaded') imaging_telescopes = CharField() guiding_telescopes = CharField() mounts = CharField() imaging_cameras = CharField() guiding_cameras = CharField() coord_ra_min = FloatField() coord_ra_max = FloatField() coord_dec_min = FloatField() coord_dec_max = FloatField() pixel_scale = FloatField() field_radius = FloatField() countries = CharField() animated = BooleanField(model_attr='animated') likes = IntegerField() integration = FloatField() moon_phase = FloatField() first_acquisition_date = DateTimeField() last_acquisition_date = DateTimeField() views = IntegerField() solar_system_main_subject_char = CharField( model_attr='solar_system_main_subject', null=True) is_deep_sky = BooleanField() is_solar_system = BooleanField() is_sun = BooleanField() is_moon = BooleanField() is_planets = BooleanField() is_comets = BooleanField() constellation = CharField() is_iotd = BooleanField() is_top_pick = BooleanField() is_top_pick_nomination = BooleanField() license = IntegerField() license_name = CharField() min_aperture = IntegerField() max_aperture = IntegerField() min_pixel_size = IntegerField() max_pixel_size = IntegerField() bookmarks = IntegerField() telescope_types = MultiValueField() camera_types = MultiValueField() comments = IntegerField() subject_type_char = CharField(model_attr='subject_type') acquisition_type = CharField(model_attr='acquisition_type') data_source = CharField(model_attr='data_source') remote_source = CharField(model_attr='remote_source', null=True) username = CharField(model_attr='user__username') objects_in_field = CharField() bortle_scale = FloatField() def index_queryset(self, using=None): return self.get_model().objects.filter(moderator_decision=1).exclude( corrupted=True) def get_model(self): return Image def get_updated_field(self): return "updated" def prepare_imaging_telescopes(self, obj): return [ "%s, %s" % (x.get("make"), x.get("name")) for x in obj.imaging_telescopes.all().values('make', 'name') ] def prepare_guiding_telescopes(self, obj): return [ "%s, %s" % (x.get("make"), x.get("name")) for x in obj.guiding_telescopes.all().values('make', 'name') ] def prepare_mounts(self, obj): return [ "%s, %s" % (x.get("make"), x.get("name")) for x in obj.mounts.all().values('make', 'name') ] def prepare_imaging_cameras(self, obj): return [ "%s, %s" % (x.get("make"), x.get("name")) for x in obj.imaging_cameras.all().values('make', 'name') ] def prepare_guiding_cameras(self, obj): return [ "%s, %s" % (x.get("make"), x.get("name")) for x in obj.guiding_cameras.all().values('make', 'name') ] def prepare_coord_ra_min(self, obj): if obj.solution is not None and obj.solution.ra is not None and obj.solution.radius is not None: return obj.solution.ra - obj.solution.radius return None def prepare_coord_ra_max(self, obj): if obj.solution is not None and obj.solution.ra is not None and obj.solution.radius is not None: return obj.solution.ra + obj.solution.radius return None def prepare_coord_dec_min(self, obj): if obj.solution is not None and obj.solution.dec is not None and obj.solution.radius is not None: return obj.solution.dec - obj.solution.radius return None def prepare_coord_dec_max(self, obj): if obj.solution is not None and obj.solution.dec is not None and obj.solution.radius is not None: return obj.solution.dec + obj.solution.radius return None def prepare_pixel_scale(self, obj): return obj.solution.pixscale if obj.solution else None def prepare_field_radius(self, obj): return obj.solution.radius if obj.solution else None def prepare_likes(self, obj): return _prepare_likes(obj) def prepare_integration(self, obj): return _prepare_integration(obj) def prepare_moon_phase(self, obj): return _prepare_moon_phase(obj) def prepare_first_acquisition_date(self, obj): return _prepare_first_acquisition_date(obj) def prepare_last_acquisition_date(self, obj): return _prepare_last_acquisition_date(obj) def prepare_views(self, obj): return _prepare_views(obj, 'image') def prepare_license(self, obj): return License.to_deprecated_integer(obj.license) def prepare_license_name(self, obj): return obj.license def prepare_bookmarks(self, obj): return _prepare_bookmarks(obj) def prepare_constellation(self, obj): constellation = ImageService.get_constellation(obj.solution) # Escape with __ because And (Andromeda) is not searchable, due to it being the same word as the AND operator. return "__%s__" % constellation.get( 'abbreviation') if constellation else None def prepare_telescope_types(self, obj): return _prepare_telescope_types(obj) def prepare_camera_types(self, obj): return _prepare_camera_types(obj) def prepare_comments(self, obj): return _prepare_comments(obj) def prepare_is_iotd(self, obj): return IotdService().is_iotd(obj) def prepare_is_top_pick(self, obj): return IotdService().is_top_pick( obj) and not IotdService().is_iotd(obj) def prepare_is_top_pick_nomination(self, obj): return IotdService().is_top_pick_nomination(obj) and \ not IotdService().is_top_pick(obj) and \ not IotdService().is_iotd(obj) def prepare_objects_in_field(self, obj): return SolutionService( obj.solution).get_objects_in_field() if obj.solution else None def prepare_countries(self, obj): return ' '.join([x.country for x in obj.locations.all() if x.country]) def prepare_bortle_scale(self, obj): deep_sky_acquisitions = DeepSky_Acquisition.objects.filter( image=obj, bortle__isnull=False) if deep_sky_acquisitions.exists(): return sum([x.bortle for x in deep_sky_acquisitions]) / float( deep_sky_acquisitions.count()) return None