मैं django-haystack के साथ खेल रहा हूं और इसे elasticsearch के साथ लागू करने की कोशिश कर रहा हूं (मैंने पहले ही वास्तव में किया था।) मेरा मॉडल है। title
, content
और एक भी tags
फ़ील्ड जो एक है ManyRelatedManager
:
tags = models.ManyToManyField( "Tag", through = "PostTags" )
मेरी खोज अनुक्रमणिका ऑब्जेक्ट निम्नानुसार बनाया गया है:
class PostIndex( indexes.SearchIndex, indexes.Indexable ):
text = indexes.CharField( document = True, use_template = True )
title = indexes.CharField( model_attr = "title", boost = 1.125 )
content = indexes.CharField( model_attr = "content" )
date_added = indexes.DateTimeField( model_attr = "date_added" )
मेरा पहला सवाल है ... मैं टैग को कैसे शामिल करूं? PostIndex
आपत्ति? मैं शीर्षक और सामग्री की तुलना में टैग को बहुत अधिक बढ़ावा देना चाहता हूं।
post_text.txt
टेम्पलेट:
{{ object.title }}
{{ object.content }}
{% for tag in object.tags.all %}
{{ tag.name }}
{% endfor %}
उत्तर:
जवाब के लिए 0 № 1आप टैग के लिए एक बहु पहलू फ़ील्ड जोड़ सकते हैं और अनुक्रमण समय पर आबाद और बढ़ा सकते हैं। आपके PostIndex मॉडल में:
tags = FacetMultiValueField(boost = 2)
तथा
def prepare_tags(self, obj):
return [t.name for t in obj.tags.all()]