我正在尝试将我的 Django 模型索引到 Whoosh。在本教程中,他们只是使用content
字段索引文本,但是我如何以这种方式索引我的 Django 模型......
我的模型.py
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)
#------------------------------------------------------------------------------
我也看过本教程,但我不明白如何将索引存储到Whoosh
. 我是新手,Whoosh
有人可以帮助我...