标签: django-haystack

使用属性的Django-haystack结果过滤?

有人能告诉我如何使用属性过滤django-haystack的全文搜索结果吗?我在他们的网站上浏览了教程,但我仍然确定如何使用干草堆.

例如,假设我有一个产品类:

class Product(models.Model):
    title = models.CharField(max_length=200)
    description = models.TextField()
    category = models.CharField(max_length=10)
    color = models.CharField(max_length=10)
Run Code Online (Sandbox Code Playgroud)

如果我想在标题和描述上提供全文搜索,并在类别和颜色上过滤(基于下拉列表,而不是自由文本) - 我需要做什么?我可以使用haystack附带的表单和视图吗?

谢谢.

django solr full-text-search django-haystack

3
推荐指数
1
解决办法
2426
查看次数

干草堆/飞快指数生成错误

我正试图用后嘶嘶声设置干草堆.当我尝试生成索引[或任何索引命令]时,我收到:

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)

python django whoosh django-haystack

3
推荐指数
1
解决办法
2357
查看次数

Django haystack不会添加到Solr索引.[与whoosh合作,与Solr失败]

在开发过程中,我使用了whoosh作为后端,现在想切换到solr.我安装了solr,将设置更改为HAYSTACK_SEARCH_ENGINE和HAYSTACK_SOLR_URL.

现在,当我尝试更新或重建索引时,它失败了 Failed to add documents to Solr: [Reason: None] .

对于所有查询返回0结果,所有搜索也都是错误的.如果我改变为嗖嗖,这项工作.但是,我有一个RealTimeSearch索引集,并且在模型创建期间,我没有得到关于无法写入搜索索引的警告.(我假设数据正在被写入solr索引.

通过直接进入solr启动的端口,我可以看到solr正在运行.

django solr whoosh django-haystack

3
推荐指数
1
解决办法
3195
查看次数

按日/周/月/年视图排序Solr搜索结果

拥有视频模型和搜索索引.使用Django-haystack和Solr.需要按日期/周/月/年的视频视图对结果进行排序.是否可以通过最后一天/周/月/年的观看信息更新搜索索引?

如果只需按日期和总计的视图排序,则可以仅为查看一天的视频更新索引,其中当前视图等于0.

每隔几个小时使用update_index看起来不是一个好主意,因为现在它需要30分钟,所以将来可以采取更多.现在,搜索索引仅针对使用Celery异步任务的已更改对象进行更新.

django solr django-haystack

3
推荐指数
1
解决办法
648
查看次数

无法将文档添加到Solr:[原因:未找到错误404]

我正在尝试使用django-haystack在Solr中为模型建立索引,但是它返回以下错误(使用rebuild_index或update_index时):

Failed to add documents to Solr: [Reason: Error 404 Not Found]
Run Code Online (Sandbox Code Playgroud)

这是search_indexes.py

from haystack import indexes
from haystack.indexes import SearchIndex
from jobpost.models import *



class JobIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    post_type = indexes.CharField(model_attr='post_type')
    location = indexes.CharField(model_attr='location')
    job_type = indexes.CharField(model_attr='job_type')
    company_name = indexes.CharField(model_attr='company_name')
    title = indexes.CharField(model_attr='title')

    def get_model(self):
        return jobpost

    def index_queryset(self,**kwargs):
        return self.get_model().objects.all()
Run Code Online (Sandbox Code Playgroud)

干草堆连接:

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
        'URL': 'http://127.0.0.1:8983/solr',

        'SITECONF': 'jobpost.search_sites'
    },
}
Run Code Online (Sandbox Code Playgroud)

我已生成schema.xml多次重新启动solr ..将其放置在solr / conf中..不知道是什么问题

django solr django-haystack

3
推荐指数
1
解决办法
2883
查看次数

干草堆多指数 - 即使有不同的search_index也索引相同

我有以下搜索

class ProductIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    destination = indexes.FacetIntegerField(
        model_attr='hotel__destination__id')
    country = indexes.FacetIntegerField(model_attr='hotel__country__id')
    hotel_class = indexes.FacetCharField(model_attr='hotel__hotel_class')
    hotel_type = indexes.FacetIntegerField(model_attr='hotel__hotel_type__id')


    def get_model(self):
        return Product

    def index_queryset(self, using=True):
        return self.get_model().objects.all()



class DestinationIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    content_auto = indexes.EdgeNgramField(model_attr="foo")
Run Code Online (Sandbox Code Playgroud)

并在settings.py中进行以下设置

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE':
        'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'http://127.0.0.1:9200/',
        'INDEX_NAME': 'haystack',
    },
    'autocomplete': {
        'ENGINE':
        'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'http://127.0.0.1:9200/',
        'INDEX_NAME': 'autcomplete',
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我说rebuild_indexes时,两个索引变得相同,它们根据两个索引类进行索引.但是我想要使用ProductIndex索引默认索引,并使用目标索引索引自动完成.

有任何想法吗?

python django django-haystack

3
推荐指数
1
解决办法
1979
查看次数

Django Haystack - 如何在没有词干的情况下强制精确的属性匹配?

我将 Django 1.5 与 django-haystack 2.0 和 elasticsearch 后端一起使用。我正在尝试通过精确的属性匹配进行搜索。但是,即使我同时使用__exact运算符和 Exact() 类,我也得到了“类似”的结果。我怎样才能防止这种行为?

例如:

# models.py
class Person(models.Model):
    name = models.TextField()


# search_indexes.py
class PersonIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    name = indexes.CharField(model_attr="name")

    def get_model(self):
        return Person

    def index_queryset(self, using=None):
        return self.get_model().objects.all()


# templates/search/indexes/people/person_text.txt
{{ object.name }}


>>> p1 = Person(name="Simon")
>>> p1.save()
>>> p2 = Person(name="Simons")
>>> p2.save()

$ ./manage.py rebuild_index

>>> person_sqs = SearchQuerySet().models(Person)
>>> person_sqs.filter(name__exact="Simons")
[<SearchResult: people.person (name=u'Simon')>
 <SearchResult: people.person (name=u'Simons')>]
>>> person_sqs.filter(name=Exact("Simons", clean=True))
[<SearchResult: people.person (name=u'Simon')> …
Run Code Online (Sandbox Code Playgroud)

django django-haystack elasticsearch

3
推荐指数
1
解决办法
1746
查看次数

无法让Elasticsearch与Django一起使用

我正在尝试将Django和Haystack与Elasticsearch一起用作Ubuntu 14.04的后端.我安装了Elasticsearch和Haystack.

我运行python manage.py runserver时收到的错误:

me@ubuntu:$ python manage.py runserver
Validating models...

0 errors found
January 31, 2015 - 17:40:37
Django version 1.5.4, using settings 'website_project.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
  File "/home/me/.pythonbrew/pythons/Python-2.7.5/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 72, in __call__
    return self.application(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 243, in __call__
    signals.request_started.send(sender=self.__class__)
  File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py", line 170, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/usr/local/lib/python2.7/dist-packages/haystack/__init__.py", …
Run Code Online (Sandbox Code Playgroud)

python django django-haystack elasticsearch

3
推荐指数
1
解决办法
2538
查看次数

如何在 Django 模板中解析“2015-01-01T00:00:00Z”?

在我的 Django html 模板中,我使用 haystack 以“2015-01-01T00:00:00Z”格式获取我的 SOLR facet_date 结果。如何在模板中以“01/01/2015”格式解析它?我的模板是

{{ facets.dates.created.start }}
Run Code Online (Sandbox Code Playgroud)

我应该在模板中添加什么“|date:”选项?谢谢!

python django django-templates django-haystack solr4

3
推荐指数
1
解决办法
3143
查看次数

Django haystack在弹性搜索中将LocationField创建为字符串而不是geo_point

我正在使用django 1.8.9,django-rest-framework,django-haystack和Elasticsearch,并且我正在尝试使LocationField正常工作,但是创建索引但是类型始终string不是geo_point,所以很明显没有地理搜索工作.

settings.py:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.gis',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django_extensions',
    'elasticsearch',
    'rest_framework',
    'haystack',
)
Run Code Online (Sandbox Code Playgroud)

requirements.txt:

Django==1.8.9
django-appconf==1.0.1
django-compressor==1.6
django-extensions==1.6.1
django-filter==0.11.0
django-haystack==2.4.1
djangorestframework==3.3.1
djangorestframework-jwt==1.7.2
ecdsa==0.13
elasticsearch==2.2.0
Fabric==1.10.2
future==0.15.2
geopy==1.11.0
gunicorn==19.4.1
Markdown==2.6.5
paramiko==1.16.0
psycopg2==2.6.1
pycrypto==2.6.1
PyJWT==1.4.0
python-dateutil==2.4.2
python-memcached==1.57
setproctitle==1.1.9
six==1.10.0
urllib3==1.14
Run Code Online (Sandbox Code Playgroud)

search_indexes.py:

from haystack import indexes
from blah.api.models import MyModel


class MyIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    description = indexes.CharField(model_attr='description')
    location = indexes.LocationField(model_attr='get_location')
    created = indexes.DateTimeField(model_attr='created')

    def get_model(self):
        return MyModel
Run Code Online (Sandbox Code Playgroud)

MyModel上的get_location属性:

from haystack.utils.geo …
Run Code Online (Sandbox Code Playgroud)

python django django-haystack elasticsearch

3
推荐指数
1
解决办法
453
查看次数