我正在尝试让./manage.py update_index --remove管理命令从搜索索引中删除结果.
我想删除这些对象,而不是删除它们时,只是在它们的时候:
enabled = models.BooleanField()
Run Code Online (Sandbox Code Playgroud)
领域是 False
我该怎么办?我还需要准备SearchIndex吗?
import datetime
from haystack.indexes import *
from haystack import site
from articles.models import Article
class ArticleIndex(SearchIndex):
text = CharField(document=True, use_template=True)
title = CharField(model_attr='title')
content = CharField(model_attr='content')
def get_queryset(self):
"""Used when the entire index for model is updated."""
return Article.site_published_objects.filter(enabled=True)
def get_updated_field(self):
return 'modified'
def remove_object(self):
pass
site.register(Article, ArticleIndex)
Run Code Online (Sandbox Code Playgroud)
谢谢.
我想按标题对我的django-haystack查询的结果进行排序.
from haystack.query import SearchQuerySet
for result in SearchQuerySet().all().order_by('result_title_sort'):
print result.result_title_sort
Run Code Online (Sandbox Code Playgroud)
我不断收到此错误:
字段"result_title_sort"中的术语多于文档,但是无法对标记化字段进行排序
这是我的haystack字段定义:
result_title_sort = CharField(indexed=True, model_attr='title')
Run Code Online (Sandbox Code Playgroud)
我应该如何定义该字段,以便对其进行排序?
我一直在读关于Haystack,飞快移动,Xapian等等.但是我并没有真正得到它们的用途以及它们之间的关系.例如,有人说
启用第三方应用搜索,而无需触及该应用的代码.
有些人可以向我解释一下这些用于提供一个很好的链接和简单到足以理解一个begginer.谢谢
我在我的Windows计算机上使用干草堆,但我意识到我的django应用程序需要其他模块,这些模块更容易在Linux上安装,因此我使用Ubuntu移动到我的VirtualBox.我用virtualenv在venv文件夹中安装了所有内容.基本上我的应用程序使用带有Whoosh后端的haystack.在view.py上,在导入行上,当我这样做from haystack.query import SearchQuerySet时抛出一个No module named query错误.什么想法可能是错的?这是整个错误.我怀疑我在Python路径上做错了.我在虚拟环境中用pip安装了所有东西.
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.4
Exception Type: ImportError
Exception Value:
No module named query
Exception Location: /home/app/dj/venv/theme/../theme/views.py in <module>, line 10
Python Executable: /home/app/dj/venv/bin/python
Python Version: 2.7.3
Python Path:
['/home/app/dj/venv/theme',
'/home/app/dj/venv/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
'/home/app/dj/venv/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
'/home/app/dj/venv/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
'/home/app/dj/venv/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
'/home/app/dj/venv/lib/python2.7',
'/home/app/dj/venv/lib/python2.7/plat-linux2',
'/home/app/dj/venv/lib/python2.7/lib-tk',
'/home/app/dj/venv/lib/python2.7/lib-old',
'/home/app/dj/venv/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/home/app/dj/venv/local/lib/python2.7/site-packages',
'/home/app/dj/venv/lib/python2.7/site-packages']
Run Code Online (Sandbox Code Playgroud) 鉴于url conf:
r'^(?P<some_var>[-a-z0-9\.]*[a-z0-9\.]\.\w+)/search/$'
Run Code Online (Sandbox Code Playgroud)
如何将命名组传递some_var给Haystack的SearchView?
我想覆盖SearchView.get_results()以执行额外的过滤器取决于some_var.
这是最好的方法吗?
我正在通过Whoosh 快速入门指南,除了我不能完全复制指南中的结果外,一切似乎都在工作.
我对Searcher对象有点了解,当我运行代码时
print(results[0])
Run Code Online (Sandbox Code Playgroud)
如果发现匹配,我不会得到实际结果,我只是回来
<Hit {}>
Run Code Online (Sandbox Code Playgroud)
而在教程中,输出是
{"title": "Second try", "path": "/b", "icon": "/icons/sheep.png"}
Run Code Online (Sandbox Code Playgroud)
这显然更有帮助!
知道我可能做错了什么吗?
我在url.py中有以下内容:
from haystack.forms import HighlightedModelSearchForm
from haystack.query import SearchQuerySet
from haystack.views import SearchView
from articles.models import Article
article_sqs = SearchQuerySet().models(Article)
urlpatterns = patterns('',
...
url(r'^article/search/$', SearchView(
template='articles/search/results.html',
searchqueryset=article_sqs,
results_per_page=10,
form_class=HighlightedModelSearchForm
), name='haystack_search'),
...
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我需要捕获搜索关键字来记录它.
我该如何捕捉它?
非常感谢您的帮助.
我正在尝试跟随干草堆教程.运行manage.py rebuild index时遇到错误
我收到以下错误:
WARNING: This will irreparably remove EVERYTHING from your search index.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y
Removing all documents from your index because you said so.
All documents removed.
/Users/heri0n/python_env/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2013-04-07 16:14:15.481145) while time zone support is active.
RuntimeWarning)
Indexing 1 notes.
Failed to add documents to Solr: [Reason: None]
<response><lst name="responseHeader"><int …Run Code Online (Sandbox Code Playgroud) 我尝试了在Haystack网站上给出的基本教程http://django-haystack.readthedocs.org/en/latest/tutorial.html,它的基本搜索工作正常.但是它的搜索无效,因为假设我的Note模块有3个text字段条目.
当我搜索
python结果:2和3文本字段.
python exam结果:第3个文本字段
但是在搜索时python flask它什么都没有.我想再次获得第2和第3个结果,因为有python关键字.
当搜索boot没有结果,但它应该显示第一个结果,它boot在引导词.
当pyton再次搜索时没有结果,但它应该显示第2和第3个结果,因为它只有1个h缺少来自python.
当bootstrap django再次搜索没有结果,但它应显示第1和第2结果.
所以,它看起来像我缺少干草堆的一些高级设置.
如何使其更有效的搜索,以便它给出更好的结果,而不仅仅是直接匹配?
我正在尝试使用Haystack和Whoosh在我的应用程序中进行索引和搜索.当我重建索引时,我得到了这样的结果:
删除所有文件.更新后端:默认默认值:后端不需要重建.跳绳
这是我的SearchIndex类:
class BlogIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True, template_name="snip_text.txt")
headline = indexes.CharField(model_attr="headline", null=True)
body = indexes.CharField(model_attr="body")
def get_model(self):
return Snip
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.filter(date__lte=timezone.now())
Run Code Online (Sandbox Code Playgroud)
这是我的blog_text.txt文件(位于templates/search/indexes/myapp /中):
{{ object.headline }}
{{ object.body }}
Run Code Online (Sandbox Code Playgroud)
我在设置文件中添加了haystack到INSTALLED_APPS及其配置.我的DB是sqlite(仅用于开发......).
我究竟做错了什么?
谢谢!
[R
UPDATE
创建一个这样的管理命令(根据需要命名文件 - 例如my_update_index.py)
from haystack.management.commands import update_index
class Command(update_index.Command):
pass
Run Code Online (Sandbox Code Playgroud)
对clear_index命令执行相同操作.
rebuild_index命令调用clear_index和update_index,因此即使你将创建一个新的rebuild命令它也不会工作(因为它正在寻找错误的命令).
只需要在重建索引时运行这两个命令,否则运行update_index命令.
还有一点需要注意:模板txt文件的文件夹名称必须与您尝试索引的模型完全相同(并且在您编写的Index Class中的位置无关紧要......).
当然,归功于@solarissmoke
django-haystack ×10
django ×9
python ×4
solr ×3
whoosh ×3
search ×2
indexing ×1
pythonpath ×1
xapian ×1