下面是我的档案。我的问题是index_queryset()中的print语句打印所有记录,但前端没有显示任何内容。所有查询都显示“未找到结果”。
models.py
class Jobs(models.Model):
ID = models.CharField(primary_key = True, max_length = 50)
JOB_TITLE = models.TextField(db_index=True)
JOB_COMPANY = models.TextField()
JOB_LOCATION = models.TextField(db_index=True)
JOB_SALARY = models.CharField(max_length= 200,null=True)
search_index.py
from haystack import indexes
from .models import Jobs
class JobIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
type = indexes.CharField(model_attr='JOB_TITLE')
location = indexes.CharField(model_attr='JOB_LOCATION')
def get_model(self):
return Jobs
def index_queryset(self,using=None):
print(self.get_model().objects.all()) # prints all the objects
return self.get_model().objects.all()
search.html
{% extends 'base.html' %}
{% block content %}
<h2>Searching</h2>
<form method="get" action=".">
<table>
{{ form.as_table }}
<tr>
<td> </td>
<td>
<input type="submit" value="Search">
</td>
</tr>
</table>
{% if query %}
<h3>Results</h3>
{% for result in object__list %}
<p>
<a href="{{ result.object.get_absolute_url }}">{{ result.object.JOB_TITLE }}</a>
</p>
{% empty %}
<p>No results found.</p>
{% endfor %}
<p>"PAGE": {{ page.object_list }} </p>
{% if page.has_previous or page.has_next %}
<div>
{% if page.has_previous %}<a href="?q={{ query }}&page={{ page.previous_page_number }}">{% endif %}« Previous{% if page.has_previous %}</a>{% endif %}
|
{% if page.has_next %}<a href="?q={{ query }}&page={{ page.next_page_number }}">{% endif %}Next »{% if page.has_next %}</a>{% endif %}
</div>
{% endif %}
{% else %}
{# Show some example queries to run, maybe query syntax, something else? #}
{% endif %}
</form>
{% endblock %}
jobs_text.txt(在templates\indexes\app中)
{{ object.JOB_COMPANY }}
{{ object.JOB_LOCATION }}
任何帮助都将不胜感激。以下是安装的软件包版本。
django haystack 3.0,django 3.2.5,pysolr 3.9.0,solr安装版本为8.9.0
暂无答案!
目前还没有任何答案,快来回答吧!