- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经阅读了入门文档和网络上的其他几个示例。这就是我的 search_indexes.py 的样子:
from haystack.indexes import *
from haystack import site
from models import Entry
class EntryIndex(SearchIndex):
text = CharField(document=True)
headline = CharField(model_attr='headline')
subheadline = CharField(model_attr='subheadline')
category = CharField(model_attr='category__name')
author = CharField(model_attr='get_author')
email = CharField(model_attr='get_email')
tags = CharField(model_attr='tags')
content = CharField(model_attr='content')
def get_queryset(self):
return Entry.objects.exclude(dt_published=None).order_by('-is_featured', '-dt_published', '-dt_written', 'headline')
site.register(Entry, EntryIndex)
但是当我搜索时,我没有得到任何结果。奇怪的是,如果我使用搜索短语“a”或任何其他单个字母,我看到了该死的东西中的每一个条目。
无论如何...在我看来,搜索引擎没有在任何字段中查找。 :/
此行以下的任何内容都不那么相关(它有效,相信我):
<小时/>我的看法:
from haystack.views import SearchView
class CustomSearchView(SearchView):
def __name__(self):
return "CustomSearchView"
def extra_context(self):
return common(self.request)
def search(request):
return CustomSearchView(template='news/search_results.html')(request)
和search_results.html:
{% extends "content.html" %}
{% load tagging_tags %}
{% load highlight %}
{% block title %}Viðskiptablaðið - Leitarniðurstöður{% endblock %}
{% block left_content %}
<h2>Search</h2>
<form method="get">
<table>
{{ form.as_table }}
<tr>
<td> </td>
<td>
<input type="submit" value="Search">
</td>
</tr>
</table>
{% if query %}
<h3>Results</h3>
{% for result in page.object_list %}
{% highlight result.summary with request.GET.q %}
{% highlight result.object.headline with request.GET.q %}
<p>
<a href="{{ result.object.get_absolute_url }}">{{ result.object.headline }}</a>
</p>
{% empty %}
<p>No results found.</p>
{% endfor %}
{% 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 %}
最佳答案
好的,文档里有,但我觉得还不够清楚。
你要做的是以某种方式声明要搜索的数据(我认为这就是整个要点:
headline = CharField(model_attr='headline')
subheadline = CharField(model_attr='subheadline')
等等...)
好了,哭够了。
你所要做的就是
text = CharField(document=True, use_template=True)
然后制作一个模板,就我而言:
搜索/indexes/news/entry_text.txt
{{ object.headline }}
{{ object.subheadline }}
{{ object.get_author }}
{{ object.get_email }}
{{ object.category.name }}
{{ object.tags }}
{{ object.content }}
漂亮,它有效。
关于django - Django Haystack 搜索中没有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3841084/
我正在阅读 Haystack 的“入门”指南,并尝试使用 Haystack 为我的网站实现 Whoosh 后端。我成功设置了整个项目,还可以在我的 search.html 模板上看到搜索框。我无法建立
我正在尝试使用 django haystack 制作自定义搜索表单,我只是从 haystack 的文档中修改: 表格.py from django import forms from haystack
我是 Django 和 Haystack 的新手...我需要知道如何按日期/时间戳对搜索结果进行排序,最近的排在最前面。 这是我的模型.py: class adsText(models.Model):
我在一个应用程序中使用 Haystack,它非常完美。它正在索引我需要的一切。但是,现在我创建了另一个应用程序,具有不同的模型和内容,我想用 Haystack 索引它。我的想法是在我的网站上创建两个不
我想根据返回的不同模型名称(类)对结果进行分面。是否有捷径可寻? 最佳答案 您是否尝试添加 SearchIndex字段与此信息?例如。 class NoteIndex(SearchIndex, ind
我想在我博客的 base.html 模板上使用 django-haystack 的搜索表单,但结果在不同的模板页面上,我该怎么做? 最佳答案 构造表单以将数据提交到正确的 URL,
我使用 Haystack 进行搜索,返回的结果 SearchQuerySet 包含 None 元素: >> SearchQuerySet().models(Question, Document, Id
我在 Django 中使用 Haystack 和 Whoosh 在 search_index.py 我有这个 class PageIndex(RealTimeSearchIndex): tex
我正在使用 Haystack和 Whoosh使用来自 Geonames 的城市数据搜索自定义应用程序项目。 我只导入了少量 Geonames 城市数据(22917 条记录)。我想按城市人口对结果进行排
我将 Django 1.5.1 与 django-haystack 2.1.0 和 whoosh 2.5.2 后端一起使用: 模型.py: GENDER_CHOICES = ( (u'M',
我在生产服务器上安装 django-haystack 时遇到问题。 当我运行以下任何命令时,出现错误No module named haystack: python manage.pysyncdb p
我正在尝试为只搜索单词的一部分(如果我没记错的话,根据 Haystack 文档称为 autocomplete)实现生成结果。 示例: 搜索 "gol" 结果 "goldfish" 我尝试了什么? 我按
我在 Django Haystack 1.2.5 中遇到了一些问题。我需要提升一个领域,但显然它不起作用。我正在使用 Solr 1.4.1。 我的指数: class JobsTextIndex(ind
我有两个模型: 模型.py class model1 (models.Model): field1_model1 = models.CharField() filed2_model1 =
我正在尝试获取 MultiValueField被索引,但它只是不工作。这是我所拥有的: 类 Public_PollIndex(SearchIndex): text = CharField(model_
我已经使用 Django Haystack 一段时间了,它很棒!我有一个相当繁重的网站,其中的数据需要不时更新(15 到 30 分钟)。 使用 python manage.py update_inde
有没有办法制作 django-haystack 的 {% highlight %}模板标签显示传入的完整变量,而不是在第一次匹配之前删除所有内容? 我是这样使用它的: {% highlight thr
在我的领域中,内容是“示例”。我不仅想找到确切的单词“example”,我还想找到“examp”。我怎样才能做到这一点?有没有选择。找不到任何东西。 最佳答案 如果您只想搜索以某个字符串开头的对象,那
我已经使用 Solr 在 Haystack 中正确配置了拼写建议的所有内容,但是,当使用 SearchView 时,suggestion 上下文变量未设置。我意识到这是由于 https://githu
使用elasticsearch(2.x),django-haystack(2.8.0),drf-haystack(1.8.6)我建立了搜索。一切工作正常,除了我不能同时搜索多个字段。现在,我只能搜索(
我是一名优秀的程序员,十分优秀!