Python 如何将Django模型索引为嗖嗖声

Python 如何将Django模型索引为嗖嗖声,python,django,whoosh,Python,Django,Whoosh,我正在尝试将我的Django模型索引到嗖嗖声中。在这种情况下,它们只是使用内容字段对文本进行索引,但我如何以这种方式索引我的Django模型 我的模特 import json from django.db import models from django.contrib import admin #------------------------------------------------------------------------------ class scrapedData

我正在尝试将我的Django模型索引到嗖嗖声中。在这种情况下,它们只是使用
内容
字段对文本进行索引,但我如何以这种方式索引我的Django模型

我的模特

import json
from django.db import models
from django.contrib import admin
#------------------------------------------------------------------------------ 


class scrapedData (models.Model):
    """ This a model for scraped data collected by eScraper"""

    productMRP = models.FloatField()                                      # Product MRP
    image_urls = models.TextField()                                       # Images URL's for image pipeline for downloading
    productSite = models.URLField()                                       # Product web-site URL
    productDesc = models.TextField()                                      # Product Description
    image_paths = models.TextField()                                      # Product images path on the local machine
    productImage = models.TextField()                                     # Product image URL's
    productTitle = models.TextField()                                     # Product title
    productPrice = models.FloatField()                                    # Product discounted price
    hasVariants = models.BooleanField()                                   # Product variants like : colors or sizes, True is if product has variants, False otherwise
    productCategory = models.TextField()                                  # Product category
    availability = models.BooleanField()                                  # Product availability ,True if product is in stock, False otherwise
    productSubCategory = models.TextField()                               # Product sub-category
    currency = models.CharField(max_length=3)                             # Product price currency
    productURL = models.URLField(max_length=500)                          # Product page URL
    updatedAt = models.DateTimeField(auto_now=True)                       # Time at which product is updated
    createdAt = models.DateTimeField(auto_now_add=True)                   # Time at which product is created


    def product_Image(self):
        """Method to return product images for admin panel"""
        images = ''
        imagePaths = json.loads(self.image_paths)
        for image_path in imagePaths:
            images += '<img src="/images/%s/" height="150" width="150"/>' % image_path            
        return images
    product_Image.allow_tags = True


    def product_URL(self):
        """Method to return product URL for admin panel"""     
        return "<a href=%s>%s<a>"%(self.productURL,self.productTitle)    
    product_URL.allow_tags = True


    class Meta:
        """Meta class to control display Behavior of the Model name """        
        verbose_name_plural = "scrapedData"


class scrapedDataAdmin(admin.ModelAdmin):
    """scrapedData admin class"""

    list_display = ('productTitle','productSite','updatedAt','createdAt',
                    'product_URL','product_Image','productMRP','productPrice','currency',
                    'productDesc','productCategory','availability',
                    'hasVariants','productSubCategory','image_paths','image_urls'
                    )

    search_fields = ('productTitle','productSite','productURL','productMRP',
                    'productPrice','productDesc','productCategory','availability',
                    'hasVariants','productSubCategory','image_paths','image_urls'
                    )

    ordering = ('productSite',)


admin.site.register(scrapedData,scrapedDataAdmin)

#------------------------------------------------------------------------------
导入json
从django.db导入模型
从django.contrib导入管理
#------------------------------------------------------------------------------ 
类数据(models.Model):
“”“这是eScraper收集的刮取数据的模型”“”
productMRP=models.FloatField()#产品MRP
image_URL=models.TextField()#用于下载图像管道的图像URL
productSite=models.URLField()#产品网站URL
productDesc=models.TextField()#产品描述
image_path=models.TextField()#本地计算机上的产品映像路径
productImage=models.TextField()#产品图像URL的
productTitle=models.TextField()#产品标题
productPrice=models.FloatField()#产品折扣价
hasVariants=models.BooleanField()#产品变量如:颜色或尺寸,如果产品有变量,则为True,否则为False
productCategory=models.TextField()#产品类别
可用性=models.BooleanField()#产品可用性,如果产品有库存,则为True,否则为False
productSubCategory=models.TextField()#产品子类别
货币=型号。CharField(最大长度=3)#产品价格货币
productURL=models.URLField(最大长度=500)#产品页面URL
updatedAt=models.DateTimeField(auto_now=True)#产品更新的时间
createdAt=models.DateTimeField(auto_now_add=True)#创建产品的时间
def产品_图像(自身):
“”“返回管理面板的产品映像的方法”“”
图像=“”
imagepath=json.load(self.image\u路径)
对于imagePaths中的图像路径:
图像+=''%image\u路径
返回图像
product_Image.allow_tags=True
def产品URL(自我):
“”“返回管理面板的产品URL的方法”“”

返回“但我不知道如何将索引存储到
Whoosh
。我是新来的
Whoosh
有人能帮我吗…

下面的教程会让你启动并运行:)你在使用吗?不,我没有使用haystack,因为它提供
templateDoesnotextist
但事实上它存在,因为我能够打开search.html。。。。如果你能帮助我,那将是非常有帮助的…你所说的指数模型是什么意思?为模型中的所有字段编制索引?你真的想让用户在你的模型中搜索与任何字段相关的关键字吗?我觉得搜索结果有点不可预测。我的2c:使用Haystack和Solr w/websolr.com以获得便宜。它的设置非常简单,最终您可以进行可靠的搜索。