Exemple #1
0
class IdeasIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    created_at = indexes.DateTimeField(model_attr='created_at')
    location_idea = indexes.LocationField(model_attr='get_location')
    location_poi = indexes.LocationField(model_attr='get_location')

    def get_model(self):
        return Idea
Exemple #2
0
class UserIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True)
    first_name = indexes.CharField(model_attr='first_name')
    last_name = indexes.CharField(model_attr='last_name')
    gender = indexes.CharField(model_attr='gender', null=True)
    age = indexes.IntegerField(null=True)
    location = indexes.LocationField()
    goals = indexes.MultiValueField()
    offers = indexes.MultiValueField()
    interests = indexes.MultiValueField()
    likes = indexes.MultiValueField()
    likes_ids = indexes.MultiValueField()
    likes_fb_ids = indexes.MultiValueField()

    def get_model(self):
        return FacebookCustomUserActive

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.all()

    def prepare_location(self, obj):
        location = get_user_location(obj.id)
        return {"lat": location.y, "lon": location.x}

    def prepare_age(self, obj):
        return calculate_age(obj.date_of_birth)

    def prepare_goals(self, obj):
        # Since we're using a M2M relationship with a complex lookup,
        # we can prepare the list here.
        return [unicode(goal) for goal in obj.goal_set.all()]

    def prepare_offers(self, obj):
        # Since we're using a M2M relationship with a complex lookup,
        # we can prepare the list here.
        return [unicode(offer) for offer in obj.offer_set.all()]

    def prepare_interests(self, obj):
        # Since we're using a M2M relationship with a complex lookup,
        # we can prepare the list here.
        return [unicode(interest) for interest in obj.interest_set.all()]

    def prepare_likes(self, obj):
        return [
            unicode(like.name)
            for like in FacebookLike.objects.filter(user_id=obj.id)
        ]

    def prepare_likes_ids(self, obj):
        return [
            unicode(like.id)
            for like in FacebookLike.objects.filter(user_id=obj.id)
        ]

    def prepare_likes_fb_ids(self, obj):
        return [
            unicode(like.facebook_id)
            for like in FacebookLike.objects.filter(user_id=obj.id)
        ]
Exemple #3
0
class PatronIndex(indexes.Indexable, indexes.SearchIndex):
    text = indexes.CharField(document=True, use_template=False)
    location = indexes.LocationField(model_attr='default_address__position',
                                     null=True)

    username = indexes.CharField(model_attr='username')
    avatar = indexes.CharField(null=True)
    sites = indexes.MultiValueField(faceted=True)
    date_joined_date = indexes.DateField(model_attr='date_joined__date')
    url = indexes.CharField(model_attr='get_absolute_url')

    def get_updated_field(self):
        return "date_joined_date"

    def prepare_sites(self, obj):
        return tuple(obj.sites.values_list('id', flat=True))

    def prepare_avatar(self, obj):
        # FIXME: should we really check for obj.avatar here?
        return obj.thumbnail.url if obj.avatar and obj.thumbnail else None

    def get_model(self):
        return Patron

    def index_queryset(self, using=None):
        return self.get_model().on_site.select_related(
            'default_address__position')
Exemple #4
0
class ListingIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=False)
    listing_id = indexes.IntegerField(model_attr='id')
    artist_id = indexes.IntegerField(model_attr='get_artist_id')
    artist_avatar = indexes.CharField(model_attr='get_artist_avatar')
    artist_name = indexes.CharField(model_attr='get_artist_name')
    salon_id = indexes.IntegerField(model_attr='get_salon_id')
    salon_name = indexes.CharField(model_attr='get_salon_name')
    salon_avatar = indexes.CharField(model_attr='get_salon_avatar')
    title = indexes.NgramField(model_attr='title')
    location = indexes.LocationField(model_attr='get_location')
    description = indexes.NgramField(model_attr='description')
    get_picture = indexes.CharField(model_attr='get_picture')
    metadata = indexes.CharField(model_attr='metadata')
    currency = indexes.CharField(model_attr='currency')
    price = indexes.FloatField(model_attr='price')
    likes = indexes.IntegerField(model_attr='likes')
    comments = indexes.IntegerField(model_attr='comments')
    tags = indexes.NgramField(model_attr='get_tags')
    status = indexes.IntegerField(model_attr='status')
    gender = indexes.IntegerField(model_attr='gender')
    rating = indexes.IntegerField(model_attr='get_rating')
    style = indexes.NgramField(model_attr='get_style')

    def get_model(self):
        return Listing

    def index_queryset(self, using=None):
        return self.get_model().objects.all().select_related('artist')
Exemple #5
0
class AnnotationIndex(indexes.SearchIndex, indexes.Indexable):
    category = indexes.CharField(model_attr='category', null=True)
    text = indexes.CharField(
        document=True,
        use_template=False,
        model_attr='text',
        null=True)
    username = indexes.CharField(model_attr='username', null=True)
    picture_url = indexes.CharField(model_attr='picture_url', null=True)
    the_model_name = indexes.CharField(model_attr='the_model_name', null=True)
    the_model_pk = indexes.CharField(model_attr='the_model_pk', null=True)
    location = indexes.LocationField(model_attr='location', null=True)
    datetime_from = indexes.DateTimeField(
        model_attr='datetime_from', null=True)
    datetime_until = indexes.DateTimeField(
        model_attr='datetime_until', null=True)
    visibility = indexes.CharField(model_attr='visibility', null=True)
    tags = indexes.CharField(model_attr='tags', null=True)

    def get_model(self):
        return Annotation

    def index_queryset(self, using=None):
        return self.get_model().objects.all()

    def get_updated_field(self):
        return 'updated_at'
class EventIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    categories = indexes.FacetMultiValueField()
    title = indexes.CharField(model_attr='title')
    end_date = indexes.DateField(
        model_attr='end_date',
        default=lambda: datetime.now() + timedelta(days=(30 * 365)))
    # If no expiry, expire after 30 years
    city = indexes.CharField(model_attr='venue__city', faceted=True, null=True)
    neighborhood = indexes.CharField(model_attr='venue__neighborhood',
                                     faceted=True,
                                     null=True)
    point = indexes.LocationField(model_attr='venue__point', null=True)

    # We add this for autocomplete.
    title_auto = indexes.EdgeNgramField(use_template=True)

    def get_model(self):
        return Event

    def prepare_categories(self, obj):
        return [category.name for category in obj.category.all()]

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(publish=True)
Exemple #7
0
class CourseIndex(indexes.ModelSearchIndex, indexes.Indexable):
    autocomplete = indexes.EdgeNgramField()
    coordinates = indexes.LocationField(model_attr="coordinates")
    category_id = indexes.IntegerField()
    date_start = indexes.DateTimeField(model_attr="date_start")
    date_end = indexes.DateTimeField(model_attr="date_end")

    class Meta:
        model = Course

    @staticmethod
    def prepare_autocomplete(obj):
        return " ".join((
            obj.course_name,
            obj.location_country.code,
            obj.location_address,
            obj.location_city,
            obj.location_postal_code,
            obj.location_state,
        ))

    def prepare_category_id(self, obj):
        return obj.category.id

    def get_model(self):
        return Course

    def index_queryset(self, using=None):
        return self.get_model().objects.filter(created__lte=timezone.now())
Exemple #8
0
class IssueIndex(indexes.SearchIndex, indexes.Indexable):
    latest_decision_date = indexes.DateField()
    text = indexes.CharField(document=True, use_template=True)
    category = indexes.IntegerField(faceted=True)
    categories = MultiValueIntegerField(faceted=True)
    districts = indexes.MultiValueField(faceted=True)
    location = indexes.LocationField()
    policymakers = MultiValueIntegerField(faceted=True)

    def get_updated_field(self):
        return 'last_modified_time'

    def prepare_latest_decision_date(self, obj):
        return obj.latest_decision_date

    def prepare_category(self, obj):
        return obj.category.pk

    def prepare_categories(self, obj):
        cat_tree = obj.category.get_ancestors(include_self=True)
        return [x.pk for x in cat_tree]

    def prepare_policymakers(self, obj):
        ai_list = obj.agendaitem_set.all()
        pm_list = set([ai.meeting.policymaker.id for ai in ai_list])
        return list(pm_list)

    def prepare_districts(self, obj):
        districts = obj.districts.all()
        return [x.name for x in districts]

    def prepare_location(self, obj):
        geometries = list(obj.geometries.all())
        for g in geometries:
            if g.geometry.geom_type == 'Point':
                return "%f,%f" % (g.geometry.y, g.geometry.x)
        for g in geometries:
            if g.geometry.geom_type in ('Polygon', 'MultiPolygon'):
                center = g.geometry.centroid
                return "%f,%f" % (center.y, center.x)
        return None

    def prepare_text(self, obj):
        field = self.fields['text']
        ret = field.prepare(obj)
        lines = ret.split('\n')
        # remove duplicate lines
        seen = set()
        result = []
        dupes = False
        for line in lines:
            if line not in seen:
                result.append(line)
                seen.add(line)
        ret = '\n'.join(result)
        return ret

    def get_model(self):
        return Issue
Exemple #9
0
class LocationSiteIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    site_name = indexes.CharField(indexed=True, model_attr='name')
    boundary = indexes.CharField(indexed=True)

    location_type_name = indexes.NgramField(indexed=True,
                                            model_attr='location_type__name')

    location_site_point = indexes.LocationField()

    location_coordinates = indexes.CharField()

    location_site_name = indexes.CharField(model_attr='name')

    location_site_id = indexes.CharField(model_attr='id')

    def prepare_location_site_point(self, obj):
        return '%s,%s' % obj.get_centroid().coords

    location_site_geometry = indexes.CharField()
    id = indexes.CharField()

    def prepare_location_coordinates(self, obj):
        return '%s,%s' % obj.get_centroid().coords

    def prepare_location_site_geometry(self, obj):
        geometry = obj.get_geometry()
        if geometry:
            return geometry.json
        else:
            return ''

    def prepare_id(self, obj):
        if obj.pk:
            return obj.pk
        return ''

    def prepare_boundary(self, obj):
        if not obj.boundary:
            return ''
        ids = []
        boundary = obj.boundary
        while True:
            try:
                ids.append(boundary.id)
                boundary = boundary.top_level_boundary
            except AttributeError:
                break
        return '_' + '_'.join([str(i) for i in ids]) + '_'

    class Meta:
        app_label = 'bims'

    def index_queryset(self, using=None):
        """Used to reindex model"""
        return self.get_model().objects.all()

    def get_model(self):
        return LocationSite
class CityPictureIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, model_attr='name', null=True)
    geometry = indexes.LocationField(model_attr='geometry', null=True)
    picture_url = indexes.CharField(model_attr='picture_url', null=True)
    radius = indexes.IntegerField(model_attr='radius', null=True)

    def get_model(self):
        return CityPicture
class SolrSpatialSearchIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(model_attr='name', document=True)
    location = indexes.LocationField()

    def prepare_location(self, obj):
        return "%s,%s" % (obj.lat, obj.lon)

    def get_model(self):
        return ASixthMockModel
class LocationIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    name = indexes.CharField(model_attr="name")
    location = indexes.LocationField()

    def get_model(self):
        return Location

    def prepare_location(self, obj):
        return "%s,%s" % (obj.lat, obj.lng)
class PostingIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    update_date = indexes.DateTimeField(model_attr='update_date')
    location = indexes.LocationField(model_attr='get_location')

    def get_model(self):
        return Posting

    def index_queryset(self, using=None):
        return self.get_model().objects.filter(update_date__lte=timezone.now())
Exemple #14
0
class NoteIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')
    body = indexes.CharField(model_attr='body')
    number = indexes.IntegerField(model_attr='number')
    price = indexes.IntegerField(model_attr='price')
    phone_number = indexes.IntegerField(model_attr='phone_number')
    location = indexes.LocationField(model_attr='get_location')
    location_info = indexes.CharField(model_attr='get_location_info')

    def get_model(self):
        return Note
class LocalCouponIndex(CouponIndex):
    coupon_ref_id = indexes.IntegerField(model_attr='ref_id', null=True)
    embedly_title = indexes.CharField(model_attr='embedly_title', null=True)
    embedly_description = indexes.CharField(model_attr='embedly_description',
                                            null=True)
    restrictions = indexes.CharField(model_attr='restrictions', null=True)
    directlink = indexes.CharField(model_attr='directlink', null=True)
    price = indexes.FloatField(model_attr='price', null=True)
    listprice = indexes.FloatField(model_attr='listprice', null=True)
    discount = indexes.FloatField(model_attr='discount', null=True)
    percent = indexes.IntegerField(model_attr='percent', null=True)
    merchant_location = indexes.LocationField(
        model_attr='merchant_location__get_location', null=True)
    online = indexes.BooleanField(model_attr='online', null=True)
    lastupdated = indexes.DateTimeField(model_attr='lastupdated', null=True)
    mobilequery = indexes.CharField(use_template=True, null=True)
    provider_slug = indexes.CharField(model_attr='coupon_network__code',
                                      null=True)
    provider = indexes.CharField(model_attr='coupon_network__name', null=True)
    category_slugs = indexes.MultiValueField(null=True)
    categories = indexes.MultiValueField(null=True)
    is_duplicate = indexes.BooleanField(model_attr='is_duplicate', null=True)
    status = indexes.CharField(model_attr='status', null=True)
    merchant_ref_id = indexes.IntegerField(model_attr='merchant__ref_id',
                                           null=True)
    merchant_name = indexes.CharField(model_attr='merchant__name', null=True)
    merchant_link = indexes.CharField(model_attr='merchant__link', null=True)
    merchant_address = indexes.CharField(
        model_attr='merchant_location__address', null=True)
    merchant_locality = indexes.CharField(
        model_attr='merchant_location__locality', null=True)
    merchant_region = indexes.CharField(model_attr='merchant_location__region',
                                        null=True)
    merchant_postal_code = indexes.CharField(
        model_attr='merchant_location__postal_code', null=True)
    related_deals_count = indexes.IntegerField(null=True)

    def get_model(self):
        return Coupon

    def index_queryset(self, using=None):
        return self.get_model().all_objects.filter(ref_id_source='sqoot')

    def prepare_categories(self, obj):
        return [c.name for c in obj.categories.all()]

    def prepare_category_slugs(self, obj):
        return [c.code for c in obj.categories.all()]

    def prepare_related_deals_count(self, obj):
        return Coupon.all_objects.filter(related_deal=obj).count()
class LocationSiteIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    site_name = indexes.CharField(indexed=True, model_attr='name')
    boundary = indexes.IntegerField()

    location_type_name = indexes.NgramField(indexed=True,
                                            model_attr='location_type__name')

    location_site_point = indexes.LocationField()

    location_coordinates = indexes.CharField()

    location_site_name = indexes.CharField(model_attr='name')

    location_site_id = indexes.CharField(model_attr='id')

    def prepare_location_site_point(self, obj):
        return '%s,%s' % obj.get_centroid().coords

    location_site_geometry = indexes.CharField()
    id = indexes.CharField()

    def prepare_location_coordinates(self, obj):
        return '%s,%s' % obj.get_centroid().coords

    def prepare_location_site_geometry(self, obj):
        geometry = obj.get_geometry()
        if geometry:
            return geometry.json
        else:
            return ''

    def prepare_id(self, obj):
        if obj.pk:
            return obj.pk
        return ''

    def prepare_boundary(self, obj):
        if obj.boundary:
            return obj.boundary.id
        return 0

    class Meta:
        app_label = 'bims'

    def index_queryset(self, using=None):
        """Used to reindex model"""
        return self.get_model().objects.all()

    def get_model(self):
        return LocationSite
class RepositoryIndex(indexes.RealTimeSearchIndex, indexes.Indexable):
    name = indexes.CharField(model_attr='name', default=True, boost=1.1)
    slug = indexes.CharField(model_attr='slug', indexed=False, stored=True)
    description = indexes.CharField(model_attr='general_context', null=True)
    other_names = indexes.MultiValueField(model_attr='other_names',
                                          stored=True,
                                          indexed=True)
    address = indexes.CharField(model_attr='primary_contact',
                                null=True,
                                stored=True,
                                indexed=False)
    country = indexes.CharField(model_attr='country_code',
                                faceted=True,
                                null=True,
                                stored=True)
    location = indexes.LocationField(null=True, faceted=True, stored=True)
    text = indexes.CharField(document=True, use_template=True, stored=False)
    publication_date = indexes.DateTimeField(model_attr='created_on')
    publication_status = indexes.IntegerField(model_attr='publication_status',
                                              faceted=True,
                                              stored=True)
    suggestions = indexes.CharField()

    def get_model(self):
        return models.Repository

    def prepare(self, obj):
        prepared_data = super(RepositoryIndex, self).prepare(obj)
        prepared_data['suggestions'] = prepared_data['text']
        return prepared_data

    def prepare_address(self, desc):
        contact = desc.primary_contact
        if contact:
            return contact.format()

    def prepare_location(self, desc):
        try:
            place = desc.place_set.all()[0]
        except IndexError:
            return
        return "%s,%s" % (place.point.x, place.point.y)

    def index_queryset(self):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(
            created_on__lte=datetime.datetime.now())

    def get_updated_field(self):
        return "updated_on"
Exemple #18
0
class CheckinSearchIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True)
    username = indexes.CharField(model_attr='username')
    comment = indexes.CharField(model_attr='comment')
    # Again, if you were using GeoDjango, this could be just:
    #   location = indexes.LocationField(model_attr='location')
    location = indexes.LocationField(model_attr='get_location')
    created = indexes.DateTimeField(model_attr='created')

    def get_model(self):
        return Checkin

    def prepare_text(self, obj):
        # Because I don't feel like creating a template just for this.
        return '\n'.join([obj.comment, obj.username])
Exemple #19
0
class LocationIndex(CelerySearchIndex, indexes.Indexable):
    """
    This document handles the construction of the Location Solr document.
    """
    text = indexes.CharField(document=True, use_template=True)
    name = indexes.CharField(model_attr='name_en', null=True)
    location_type = indexes.CharField(model_attr='loc_type', null=True)
    parent_text = indexes.CharField(model_attr='parent_text', null=True)
    location = indexes.LocationField(model_attr='get_location', null=True)

    def get_model(self):
        return Location

    def get_updated_field(self):
        return "location_modified"
Exemple #20
0
class AdIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True, template_name='search/indexes/ad/ad_text.txt')

    #model fields
    title = indexes.CharField(model_attr='title')
    short_description = indexes.CharField(model_attr='short_description')
    slug = indexes.CharField(model_attr='slug')
    price = indexes.FloatField(model_attr='price')
    pub_date = indexes.DateTimeField(model_attr='pub_date')
    tags = indexes.CharField()
    image1 = indexes.CharField()
    #localities = indexes.CharField(faceted=True)
    #provinces = indexes.CharField(faceted=True)
    #administrative_area_level_2 = indexes.CharField(faceted=True)
    categories = indexes.MultiValueField(faceted=True)
    groups = indexes.MultiValueField(faceted=True)

    location = indexes.LocationField()

    def prepare_location(self, obj):
        # If you're just storing the floats...
        return "%s,%s" % (obj.locations.first().lat, obj.locations.first().lng)

    def prepare_image1(self, obj):
        return str(obj.images.first().image)

    def prepare(self, object):
        self.prepared_data = super(AdIndex, self).prepare(object)

        self.prepared_data['tags'] = [tag.name for tag in object.tags.all()]
        self.prepared_data['categories'] = [category.slug for category in object.categories.all()]
        self.prepared_data['groups'] = [group.slug for group in object.groups.all()]
        #self.prepared_data['categories_slug'] = [category.slug for category in object.categories.all()]
        #self.prepared_data['localities'] = [location.locality for location in object.locations.all()]
        #self.prepared_data['provinces'] = [location.administrative_area_level_1 for location in object.locations.all()]
        #self.prepared_data['administrative_area_level_2'] = [location.administrative_area_level_2 for location in object.locations.all()]

        return self.prepared_data

    class Meta:
        model = Ad

    def get_model(self):
        return Ad

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now()).filter(status=1)
class AdvisorIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    first_name = indexes.CharField(model_attr='first_name')
    last_name = indexes.CharField(model_attr='last_name')
    crd = indexes.IntegerField(model_attr='crd')
    location = indexes.LocationField(model_attr='company__geo_location',
                                     null=True)
    modified = indexes.DateTimeField(model_attr='modified')

    def get_model(self):
        return Advisor

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(
            modified__lte=datetime.datetime.now())
Exemple #22
0
class TourPointLocationIndex(indexes.SearchIndex, indexes.Indexable):
    """
    Index the TourPoint objects, defines which attributes will be indexed, 
    so we can serach for them.
    """
    text = indexes.CharField(document=True)
    name = indexes.CharField(model_attr='name')
    category = indexes.CharField(model_attr='category')
    coordinates = indexes.LocationField(model_attr="coordinates")
    private = indexes.BooleanField(model_attr='private')
    longitude = indexes.FloatField(model_attr='longitude')
    latitude = indexes.FloatField(model_attr='latitude')
    owner = indexes.CharField(model_attr='owner')

    def get_model(self):
        return TourPoint
Exemple #23
0
class FieldIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.EdgeNgramField(document=True, use_template=True)
    location = indexes.LocationField()

    def get_model(self):
        return Field

    def prepare(self, obj):
        prepared_data = super(FieldIndex, self).prepare(obj)
        return prepared_data

    def prepare_location(self, obj):
        return "%s,%s" % (obj.lat, obj.lng)

    def index_queryset(self, using=None):
        return self.get_model().objects.all()
Exemple #24
0
class ExternalBaseIndexMixin(indexes.SearchIndex):
    
    source = indexes.CharField(stored=True, indexed=False, model_attr='source')
    portal = indexes.IntegerField(default=EXTERNAL_CONTENT_PORTAL_ID)
    location = indexes.LocationField(null=True)
    
    """ from StoredDataIndexMixin """
    
    title = indexes.CharField(stored=True, indexed=False, model_attr='title')
    # slug for linking
    slug = indexes.CharField(stored=True, indexed=True, model_attr='slug')
    url = indexes.CharField(stored=True, indexed=False, model_attr='url')
    description = indexes.CharField(stored=True, indexed=False, model_attr='description')
    # the small icon image, should be a 144x144 image
    icon_image_url = indexes.CharField(stored=True, indexed=False, model_attr='icon_image_url')
    # the small background image or None, should be a 500x275 image
    background_image_small_url = indexes.CharField(stored=True, indexed=False, model_attr='background_image_small_url', null=True)
    # the large background image or None, should be a 1000x550 image
    background_image_large_url = indexes.CharField(stored=True, indexed=False, model_attr='background_image_large_url', null=True)
    # group slug for linking, subject to implementing indexed
    group_slug = indexes.CharField(stored=True, indexed=True, model_attr='group_slug', null=True)
    # group name for linking, subject to implementing indexed
    group_name = indexes.CharField(stored=True, indexed=False, model_attr='group_name', null=True)
    # attendees for events, projects for groups
    participant_count = indexes.IntegerField(stored=True, indexed=False, model_attr='participant_count', null=True)
    # member count for projects/groups, group-member count for events, memberships for users
    member_count = indexes.IntegerField(stored=True, indexed=False, model_attr='member_count', null=True)
    # groups/projects: number of upcoming events
    content_count = indexes.IntegerField(stored=True, indexed=False, model_attr='content_count', null=True)
    
    """ from DefaultTagObjectIndex """
        
    mt_location = indexes.CharField(stored=True, indexed=False, null=True, model_attr='mt_location')
    mt_location_lat = indexes.FloatField(null=True, model_attr='mt_location_lat')
    mt_location_lon = indexes.FloatField(null=True, model_attr='mt_location_lon')
    mt_topics = CommaSeperatedIntegerMultiValueField(null=True, model_attr='mt_topics')
    mt_visibility = indexes.IntegerField(stored=True, indexed=False, default=2)
    
    mt_public = indexes.BooleanField(default=True)
    
    text = TemplateResolveNgramField(document=True, model_attr='title')
    
    def prepare_location(self, obj):
        if obj.mt_location_lat and obj.mt_location_lon:
            # this expects (lat,lon)!
            return "%s,%s" % (obj.mt_location_lat, obj.mt_location_lon)
        return None
Exemple #25
0
class LocationIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    address = indexes.CharField(model_attr="address")
    city = indexes.CharField(model_attr="city")
    zip_code = indexes.CharField(model_attr="zip_code")

    autocomplete = indexes.EdgeNgramField()
    coordinates = indexes.LocationField(model_attr='coordinates')

    @staticmethod
    def prepare_autocomplete(obj):
        return " ".join((obj.address, obj.city, obj.zip_code))

    def get_model(self):
        return LocationCurrent

    def index_queryset(self, using=None):
        return self.get_model().objects.filter(created__lte=timezone.now())
class EventIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    name = indexes.CharField(model_attr='name')
    keywords = indexes.CharField(model_attr='keywords')
    description = indexes.CharField(model_attr='description')
    start_date = indexes.DateField(model_attr='start_date')
    end_date = indexes.DateField(model_attr='end_date')
    location = indexes.LocationField(model_attr='get_location')
    user_id = indexes.IntegerField(model_attr='user_id', null=True)

    def get_model(self):
        return Event

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        self.get_model().objects.filter(end_date__lt=datetime.datetime.now()).delete()

        return self.get_model().objects.filter(end_date__gte=datetime.datetime.now())
Exemple #27
0
class ProfessionalIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    location = indexes.LocationField(model_attr='get_location', null=True)
    averageRating = indexes.DecimalField(model_attr='averageRating', null=True)

    def get_model(self):
        return Professional

    def prepare(self, obj):
        self.prepared_data = super(ProfessionalIndex, self).prepare(obj)
        # Append each category name to field 'text'
        categoryList = []
        for category in obj.categories.all():
            categoryList.extend(categoryListRecursive(category))
        categoryList = set(categoryList)

        for cat in categoryList:
            self.prepared_data['text'] += ' %s' % cat
        return self.prepared_data
Exemple #28
0
class EventIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True)
    name = indexes.CharField(model_attr='name')
    description = indexes.CharField(model_attr='description', null=True)
    location = indexes.LocationField(null=True)
    starts_on = indexes.DateTimeField(model_attr='starts_on')

    def get_model(self):
        return Event

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.all()

    def prepare_location(self, obj):
        if obj.point:
            return {"lat": obj.point.y, "lon": obj.point.x}
        else:
            return {"lat": 0, "lon": 0}
Exemple #29
0
class MinnesotaBikeIntersections(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True,
                             use_template=True,
                             model_attr='name',
                             null=True)
    source = indexes.IntegerField(model_attr='id')
    target = indexes.IntegerField(model_attr='id')
    geometry = indexes.LocationField(model_attr='the_geom')

    content_auto = indexes.EdgeNgramField(model_attr='name', null=True)

    def get_model(self):
        return Bikeintersections

    def index_queryset(self, using=None):
        return self.get_model().objects.all()

    def __str__(self):
        return self.text
class ZipCodeIndex(CelerySearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    # Shitty workaround to the content__contains problem
    contains = indexes.EdgeNgramField(use_template=True,
        template_name='search/indexes/location/zipcode_text.txt')
    code = indexes.DecimalField(model_attr='code')
    city = indexes.CharField(model_attr='city')
    state = indexes.CharField(model_attr='state')
    latitude = indexes.DecimalField(model_attr='latitude')
    longitude = indexes.DecimalField(model_attr='longitude')
    location = indexes.LocationField()

    def get_model(self):
        return ZipCode

    def get_updated_field(self):
        return 'updated'

    def prepare_location(self, obj):
        return '%s,%s' % (obj.latitude, obj.longitude)