我正在使用Whoosh和Django-Haystack.我想在用户输入错误的单词时使用查询建议.
也许你的意思是"独角兽"
是否有必要使用其他搜索引擎?或者我可以通过Whoosh成功实现这一目标吗?
嗨,我使用带有 woosh 的 haystack 作为搜索引擎:
我的模型如下
class Person(models.Model):
personid = models.IntegerField(primary_key = True, db_column = 'PID')
firstname = models.CharField(max_length = 50, db_column = 'FIRSTNAME')
lastname = models.CharField(max_length = 50, db_column = 'LASTNAME')
class Meta:
db_table = '"TEST"."PERSON"'
managed = False
class TDoc(models.Model):
tdocid = models.IntegerField(primary_key = True, db_column = 'TDOCID')
person = models.ForeignKey(Person, db_column = 'PID')
content = models.TextField(db_column = 'CONTENT', blank = True)
filepath = models.TextField(db_column = 'FILEPATH', blank = True)
class Meta:
db_table = '"TEST"."TDOC"'
managed = False …Run Code Online (Sandbox Code Playgroud) 我正在尝试将搜索与django-haystack集成,
虽然它适用于"示例"后端,但当用whoosh替换后端时,它总是返回0结果.
settings.py:
HAYSTACK_DEFAULT_OPERATOR = 'AND'
HAYSTACK_SITECONF = 'search_sites'
HAYSTACK_SEARCH_ENGINE = 'whoosh'
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 20
HAYSTACK_WHOOSH_PATH = os.path.join(PROJECT_ROOT, 'search_index')
Run Code Online (Sandbox Code Playgroud)
search_sites.py
import haystack
haystack.autodiscover()
Run Code Online (Sandbox Code Playgroud)
配置文件/ search_indexes.py:
from haystack import indexes
from haystack import site
from profiles.models import Profile
class ProfileIndex(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
def index_queryset(self):
"""Used when the entire index for model is updated."""
return Profile.objects.all()
site.register(Profile, ProfileIndex)
Run Code Online (Sandbox Code Playgroud)
模板/搜索/索引/型材/ profile_text.txt:
{{ profile.name }}
{{ profile.description }}
Run Code Online (Sandbox Code Playgroud)
运行python manage.py rebuild_index回报:
All documents removed.
Indexing 60 profiles.
Run Code Online (Sandbox Code Playgroud)
在shell中运行以下代码时:
>>> from …Run Code Online (Sandbox Code Playgroud) 我正试图用后嘶嘶声设置干草堆.当我尝试生成索引[或任何索引命令]时,我收到:
TypeError: Item in ``from list'' not a string
Run Code Online (Sandbox Code Playgroud)
如果我完全删除我的search_indexes.py我得到相同的错误[所以我猜它根本找不到该文件]
什么可能导致这个错误?它设置为自动发现,我确定我的应用程序已安装,因为我正在使用它.
完全追溯:
Traceback (most recent call last):
File "./manage.py", line 17, in <module>
execute_manager(settings)
File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py", line 362, in execute_manager
utility.execute()
File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py", line 257, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Users/ghostrocket/Development/Redux/.dependencies/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/ghostrocket/Development/Redux/.dependencies/haystack/__init__.py", line 124, in <module>
handle_registrations()
File "/Users/ghostrocket/Development/Redux/.dependencies/haystack/__init__.py", line 121, in handle_registrations …Run Code Online (Sandbox Code Playgroud) 在开发过程中,我使用了whoosh作为后端,现在想切换到solr.我安装了solr,将设置更改为HAYSTACK_SEARCH_ENGINE和HAYSTACK_SOLR_URL.
现在,当我尝试更新或重建索引时,它失败了
Failed to add documents to Solr: [Reason: None]
.
对于所有查询返回0结果,所有搜索也都是错误的.如果我改变为嗖嗖,这项工作.但是,我有一个RealTimeSearch索引集,并且在模型创建期间,我没有得到关于无法写入搜索索引的警告.(我假设数据正在被写入solr索引.
通过直接进入solr启动的端口,我可以看到solr正在运行.
Python 2.5,Django 1.2.1,最近的干草堆,最近的飞快移动
这是我第一次深入研究Django-Haystack.我正在关注Haystack的"入门"指南,一切似乎都很顺利,直到我去构建索引.
所以,运行"manage.py rebuild_index"会向我发回信息:
Traceback (most recent call last):
File "/Users/steenb/Documents/Aptana Studio Workspace/bucksac/buckshr/manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Python/2.5/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Python/2.5/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.5/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.5/site-packages/django/core/management/base.py", line 218, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.5/site-packages/haystack/management/commands/rebuild_index.py", line 13, in handle
call_command('clear_index', **options)
File "/Library/Python/2.5/site-packages/django/core/management/__init__.py", line 166, in call_command
return klass.execute(*args, **defaults)
File "/Library/Python/2.5/site-packages/django/core/management/base.py", line 218, in execute
output = self.handle(*args, **options)
File …Run Code Online (Sandbox Code Playgroud) 我正在从索尔的Whoosh重做我的搜索应用程序.我现在正在从快速入门中学习.但每次我不得不处理字符串时,我一直遇到问题
>>>writer.add_document(iden=fil, content=F2T.file_to_text(fil_path))
ValueError: 'File Name.doc' is not unicode or sequence
然后:
>>>query = QueryParser("content", ix.schema).parse("first")
AssertionError: 'first' is not unicode
Run Code Online (Sandbox Code Playgroud)
这条线直接来自快速启动的turorial!Whoosh是否要求所有字段都是unicode?让我的应用程序识别unicode(它甚至不值得)真的很难.至于"不是unicode或序列",我理解字符串也是序列数据类型.
我一直在读关于Haystack,飞快移动,Xapian等等.但是我并没有真正得到它们的用途以及它们之间的关系.例如,有人说
启用第三方应用搜索,而无需触及该应用的代码.
有些人可以向我解释一下这些用于提供一个很好的链接和简单到足以理解一个begginer.谢谢
我正在通过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)
这显然更有帮助!
知道我可能做错了什么吗?
我正在尝试使用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