Django-Haystack在搜索索引中没有内容

时间:2014-03-10 22:08:32

标签: django-haystack

就在最近,我运行了'python manage.py rebuild_index -v2'来为Haystack-Elastisearch项目构建一个可搜索的索引。 rebuild index命令的结果是:

Indexing 452 quorum_ sensings
  indexed 1 - 452 of 452 (by 8436).

当我检查索引时,索引中没有数据。

导致这种情况的原因是什么?

我正在使用Django 1.6,Haystack 2.1和Python 3.3.3

以下是我的一些代码:

models.py

from django.db import models


class Quorum_Sensing(models.Model):
    IUAPAC_NAME = models.CharField(max_length=400)
    Inducer_Molecule = models.CharField(max_length=100)
    Category_Inducer_Molecule = models.CharField(max_length=40)
    Inducer_Name_Synonym_Abbreviation = models.TextField()
    Chemical_Nature_Inducer_Molecule = models.CharField(max_length=40)
    Natural_Synthetic = models.CharField(max_length=120)
    Pubchem_Link_Inducer_Molecules = models.URLField()
    Mass_Inducer_Molecule = models.CharField(max_length=50)
    Number_Amino_Acids_In_Inducer_Molecule = models.CharField(max_length=60)
    IUPAC_Chemical_ID = models.CharField(max_length=60)
    QuorumPep_Link = models.URLField()
    Amino_Acid_Sequence_Inducer = models.CharField (max_length=300)
    SMILES = models.CharField(max_length=250)
    Organism_Involved = models.CharField (max_length=200)
    Strain1 = models.CharField(max_length=120)
    Strain2 = models.CharField(max_length=120)
    Strain3 = models.CharField(max_length=120)
    Strain4 = models.CharField(max_length=120)
    Strain5 = models.CharField(max_length=120)
    Taxonomy_Link = models.URLField()
    Pathogenic_Or_Not = models.CharField(max_length=120)
    Host = models.CharField(max_length=120)
    Target_Protein = models.CharField (max_length=160)
    Target_Protein_Length = models.CharField (max_length=40)
    Gene_Name = models.CharField(max_length=60)
    Broad_Functional_Category_Target_Molecule = models.CharField(max_length=300)
    GI = models.CharField(max_length=30)
    NCBI_Link_Target_Molecule = models.URLField(max_length=400)
    Mode_Of_Action = models.TextField()
    UNIPROT_Link_Target_Molecule = models.URLField()
    EMBL_Link_Target_Molecule = models.URLField()
    Related_Citations = models.URLField(max_length=400)
    Annotator = models.EmailField()

quorum_sensing_text.txt

{{ object.text }}
{{ object.Category_Inducer_Molecule }}
{{ object.Amino_Acid_Sequence_Inducer }}
{{ object.Organism_Involved }}
{{ object.Target_Protein }}
{{ object.Broad_Functional_Category_Target_Molecule }}

search_indexes.py

from bacterial.models import Quorum_Sensing
from haystack import indexes


class Quorum_SensingIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True,  template_name='quorum_sensing_text.txt')
    Category_Inducer_Molecule = indexes.CharField(model_attr='Category_Inducer_Molecule', faceted=True)
    Amino_Acid_Sequence_Inducer = indexes.CharField(model_attr='Amino_Acid_Sequence_Inducer', faceted=True)
    Organism_Involved = indexes.CharField(model_attr='Organism_Involved', faceted=True)
    Target_Protein = indexes.CharField(model_attr='Target_Protein', faceted=True)
    Broad_Functional_Category_Target_Molecule = indexes.CharField(model_attr='Broad_Functional_Category_Target_Molecule',faceted=True)


    def get_model(self):
        return Quorum_Sensing

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

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

发现了这个问题。这是一个损坏的Haystack fields.py文件。修复了文件,现在正在填充“文本”字段