from haystack import indexes

from directseo.seo.models import jobListing, Moc

class JobIndex(indexes.RealTimeSearchIndex, indexes.Indexable):
    country = indexes.CharField(model_attr='country', faceted=True, null=True)
    country_ac = indexes.EdgeNgramField(model_attr='country', null=True)
    state_ac = indexes.EdgeNgramField(model_attr='state', null=True)
    city_ac = indexes.EdgeNgramField(model_attr='city', null=True)
    title_ac = indexes.EdgeNgramField(model_attr='title', null=True)
    country_short = indexes.CharField(model_attr='country_short')
    country_slab = indexes.CharField(faceted=True)
    state = indexes.CharField(model_attr='state', faceted=True, null=True)
    state_short = indexes.CharField(model_attr='state_short', null=True)
    state_slab = indexes.CharField(faceted=True)
    city = indexes.CharField(model_attr='location', faceted=True, null=True)
    city_slab = indexes.CharField(faceted=True)
    date_new = indexes.DateTimeField(model_attr='date_new', null=True, faceted=True)
    real_city = indexes.CharField(faceted=True, model_attr='city', null=True)
    full_loc = indexes.CharField(faceted=True)
    uid = indexes.IntegerField(model_attr='uid', indexed=False)
    title = indexes.CharField(model_attr='title', faceted=True)
    title_slab = indexes.CharField(faceted=True)
    buid = indexes.IntegerField(model_attr='buid_id')
    moc = indexes.MultiValueField(faceted=True, null=True)
    moc_slab = indexes.MultiValueField(faceted=True, null=True)
    onet = indexes.IntegerField(model_attr='onet_id', faceted=True, null=True)
    text = indexes.CharField(document=True, use_template=True)

    def get_model(self):
        return jobListing

    def prepare_full_loc(self, obj):
        fields = ['city', 'state', 'location', 'country']
        strings = ['%s::%s' % (f, getattr(obj, f)) for f in fields if
                   getattr(obj, f)]
        return '@@'.join(strings)
    def prepare_country_slab(self, obj):
        return "%s/jobs::%s" % (obj.country_short.lower(),
    def prepare_state_slab(self, obj):
        if obj.stateSlug:
            url = "%s/%s/jobs" % (obj.stateSlug, obj.country_short.lower())
            return "%s::%s" % (url, obj.state)
    def prepare_city_slab(self, obj):
        url = "%s/%s/%s/jobs" % (obj.citySlug, obj.stateSlug,
        return "%s::%s" % (url, obj.location)
    def prepare_moc_slab(self, obj):
        # Need to pass a flag so that this is not done if the site does not have
        # MOCs turned on.
        if obj.onet_id:
            return ["%s/%s/%s/vet-jobs::%s - %s" %
                    (moc.title_slug, moc.code, moc.branch, moc.code, moc.title)
                    for moc in Moc.objects.filter(onets__joblisting=obj)]
    def prepare_moc(self, obj):
        Makes the calls to get the MOC codes that map to the job's onet code.
        if obj.onet_id:
            return [moc.code for moc in

    def prepare_title_slab(self, obj):
        Creates title slab.

        if obj.titleSlug and obj.titleSlug != "none":
            return "%s/jobs-in::%s" % (obj.titleSlug.strip('-'), obj.title)

Generated by matt using scpaste at Fri Dec 23 19:46:28 2011. EST. (original)