# Path: data_center/models.py
# class Course(models.Model):
#     """Course database schema"""
#     no = models.CharField(max_length=20, unique=True, db_index=True)
#     code = models.CharField(max_length=20, blank=True)
#     eng_title = models.CharField(max_length=200, blank=True)
#     chi_title = models.CharField(max_length=200, blank=True)
#     note = models.TextField(blank=True)
#     objective = models.CharField(max_length=80, blank=True)
#     time = models.CharField(max_length=20, blank=True)
#     time_token = models.CharField(max_length=20, blank=True)
#     teacher = models.CharField(max_length=40, blank=True)  # Only save Chinese
#     room = models.CharField(max_length=80, blank=True)
#     credit = models.IntegerField(default=0)
#     limit = models.IntegerField(default=0)
#     prerequisite = models.BooleanField(default=False, blank=True)
#     ys = models.CharField(max_length=10, blank=True)
# 
#     ge = models.CharField(max_length=80, blank=True)
# 
#     hit = models.IntegerField(default=0)
# 
#     syllabus = models.TextField(blank=True)  # pure text
#     has_attachment = models.BooleanField(default=False)  # has pdf
# 
#     def __str__(self):
#         return self.no
# 
#     @property
#     def attachment_url(self):
#         return attachment_url_format % urlquote(self.no)


from data_center.models import Course
from haystack import indexes


class CourseIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.NgramField(document=True, use_template=True)

    no = indexes.CharField(model_attr='no')
    code = indexes.CharField(model_attr='code')
    eng_title = indexes.CharField(model_attr='eng_title')
    chi_title = indexes.CharField(model_attr='chi_title')
    note = indexes.CharField(model_attr='note')
    objective = indexes.CharField(model_attr='objective')
    time = indexes.CharField(model_attr='time')
    time_token = indexes.CharField(model_attr='time_token')
    teacher = indexes.CharField(model_attr='teacher')
    room = indexes.CharField(model_attr='room')
    ge = indexes.CharField(model_attr='ge')


# Path: data_center/models.py
# class Course(models.Model):
#     """Course database schema"""
#     no = models.CharField(max_length=20, unique=True, db_index=True)
#     code = models.CharField(max_length=20, blank=True)
#     eng_title = models.CharField(max_length=200, blank=True)
#     chi_title = models.CharField(max_length=200, blank=True)
#     note = models.TextField(blank=True)
#     objective = models.CharField(max_length=80, blank=True)
#     time = models.CharField(max_length=20, blank=True)
#     time_token = models.CharField(max_length=20, blank=True)
#     teacher = models.CharField(max_length=40, blank=True)  # Only save Chinese
#     room = models.CharField(max_length=80, blank=True)
#     credit = models.IntegerField(default=0)
#     limit = models.IntegerField(default=0)
#     prerequisite = models.BooleanField(default=False, blank=True)
#     ys = models.CharField(max_length=10, blank=True)
# 
#     ge = models.CharField(max_length=80, blank=True)
# 
#     hit = models.IntegerField(default=0)
# 
#     syllabus = models.TextField(blank=True)  # pure text
#     has_attachment = models.BooleanField(default=False)  # has pdf
# 
#     def __str__(self):
#         return self.no
# 
#     @property
#     def attachment_url(self):
#         return attachment_url_format % urlquote(self.no)


# Path: data_center/search_indexes.py
from data_center.models import Course
from haystack import indexes



class CourseIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.NgramField(document=True, use_template=True)

    no = indexes.CharField(model_attr='no')
    code = indexes.CharField(model_attr='code')
    eng_title = indexes.CharField(model_attr='eng_title')
    chi_title = indexes.CharField(model_attr='chi_title')
    note = indexes.CharField(model_attr='note')
    objective = indexes.CharField(model_attr='objective')
    time = indexes.CharField(model_attr='time')
    time_token = indexes.CharField(model_attr='time_token')
    teacher = indexes.CharField(model_attr='teacher')
    room = indexes.CharField(model_attr='room')
    ge = indexes.CharField(model_attr='ge')


    credit = indexes.IntegerField(model_attr='credit')