是否可以将Django Haystack搜索与"内置"QuerySet过滤操作相结合,特别是使用Q()实例和SearchQuerySet不支持的查找类型进行过滤?无论是哪种顺序:
haystack-searched -> queryset-filtered
Run Code Online (Sandbox Code Playgroud)
要么
queryset-filtered -> haystack-searched
Run Code Online (Sandbox Code Playgroud)
浏览Django Haystack文档没有给出任何指示如何执行此操作.
我正在尝试使用Django-haystack Beta 2.0.0设置Solr 3.6.0.
运行./manage.py build_solr_schemaschema.xml并将其移动到conf目录后,在访问时http://localhost:8983/solr/admin,我收到的错误与此线程中生成的错误完全相同.
org.apache.solr.common.SolrException: No cores were created, please check the logs for errors
java.lang.RuntimeException: Can't find resource 'stopwords_en.txt' in classpath or 'solr/./conf/', cwd=/home/randall/startupsearch_live/apache-solr-3.6.0/example
在线程的底部,用户提到必须编辑schema.xml以匹配stopwords_en.txt到/ example/solr/conf /目录,我通过符号链接和编辑stopwords.txt的所有实例来完成.到生成的schema.xml文件中的/solr/conf/stopwords_en.txt.但是,同样的错误仍然存在,输出略有不同:
java.lang.RuntimeException: Can't find resource '/solr/conf/stopwords_en.txt' in classpath or 'solr/./conf/', cwd=/home/randall/startupsearch_live/apache-solr-3.6.0/example
我必须编辑哪个文件才能解决此问题?
我想知道,我如何使用django-rest-framework从get请求中提供分页的json结果q=thisterm.
我理解干草堆结束使用SearchQuerySet.filter(content=q)但是如何使用此查询集序列化和创建api视图.我不确定使用哪个视图集,也不确定我在其余部分需要做的基本逻辑.
任何帮助,将不胜感激.
谢谢
我在我的网站上使用django-haystack搜索页面.我基本上已经完成了,但对订购不太满意,不太确定haystack如何决定如何订购.
我知道我可以通过使用order_by覆盖SearchQuerySet 但完全超越它.假设我想强制搜索按库存(BooleanField)进行排序,以便库存中的产品显示在顶部,但随后会像通常那样执行其他操作.我怎么做?
我试过把order_by('-in_stock', 'content')图形内容当作默认使用的内容,但它产生了非常不同的结果,如果我只是让它做自己的排序.
感谢您对此事的任何意见!
各种助推类型如何在django,django-haystack和solr中协同工作?
我无法将最明显的搜索结果首先显示出来.如果我搜索caring for others并获得10个结果,则带有标题的对象caring for others在结果之后显示为第二个caring for yourself.
我有文件提升Category对象factor = 2.0 - ((the mptt tree level)/10)因此根节点为1.9,第二级为1.8,第三级为1.7,依此类推.(或190%,180%,170%......等等)
boost=1.5150%的正面因素推动了产权提升boost=.550%的负面因素
我目前没有提高任何搜索条件.
我想得到一个结果列表类别和文章(我忽略文章,直到我得到我的类别结果直接).类别加权高于文章,标题加权高于内容.此外,我正在尝试将根类别节点加权高于子节点.
我觉得我在某个地方错过了一个关键概念.
我正在使用haystack的内置搜索表单和搜索视图.
我正在使用以下package/lib版本:
Django==1.4.1
django-haystack==1.2.7
pysolr==2.1.0-beta
Run Code Online (Sandbox Code Playgroud)
我的索引类
class CategoryIndex(SearchIndex):
"""Categorization -> Category"""
text = CharField(document=True, use_template=True, boost=.5)
title = CharField(model_attr='title', boost=1.5)
content = CharField(model_attr='content', boost=.5)
autocomplete = EdgeNgramField(model_attr='title')
def prepare_title(self, object):
return object.title
def prepare(self, obj):
data = super(CategoryIndex, self).prepare(obj)
base_boost = …Run Code Online (Sandbox Code Playgroud) 我有一个项目列表:
i = SearchQuerySet().models(Item)
Run Code Online (Sandbox Code Playgroud)
现在,每个项目i都有一个属性,price
我想缩小价格信息不可用的结果以及属于给定范围的价格信息
就像是
i.narrow('price:( None OR [300 TO 400 ] )')
Run Code Online (Sandbox Code Playgroud)
怎么办?
这让我有点生气,但看起来应该很简单.
我正在使用Django和Haystack并且有一个包含允许null的IntegerField的搜索索引.这基于Django中的相关模型,但我认为这不重要.例如:
class ThingIndex(indexes.ModelSearchIndex, indexes.Indexable):
group = indexes.IntegerField(model_attr='group__id', null=True)
class Meta:
model = Thing
Run Code Online (Sandbox Code Playgroud)
我有时希望我的Haystack查询返回此字段的None/Null项,所以我在搜索表单的__init__中进行过滤,但我无法获得查询来执行此操作.我尝试过的最明显的方法是:
self.searchqueryset.filter(group__isnull=True) # how to do it on a regular Django queryset
Run Code Online (Sandbox Code Playgroud)
但这不会返回任何记录.
现在我正在解决这个问题:
self.searchqueryset.exclude(group__in=range(1,100))
Run Code Online (Sandbox Code Playgroud)
哪个有效,但显然不是它应该做的方式:)
有人可以帮忙吗?
谢谢!
我正在使用django-haystack(v 2.3.1)与solr(v 5.0.0)和pysolr(v 3.0.0).我一直在下面的教程,并建立了类似myapp/search_indexes.py和search/indexes/myapp/mymodel_text.txt文件.
./manage.py build_solr_schema > schema.xml 工作正常,我已将其复制到$ SOLR_HOME/conf/schema.xml.
我尝试时会出现问题./manage.py rebuild_index.首先,我要求确认:
警告:这将从连接"default"中的搜索索引中无可挽回地删除所有内容.
此后您的选择是从备份还原或通过rebuild_index命令重建.
你确定要继续吗?[y/N] y
然后,它失败了:
从您的索引中删除所有文档,因为您这样说.
无法清除Solr索引:[原因:未找到错误404]
已删除所有文档.
索引6个故事
无法向Solr添加文档:[原因:找不到错误404]
我的连接设置是:
#settings.py
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://127.0.0.1:8983/solr',
},
}
Run Code Online (Sandbox Code Playgroud)
如果我导航到此网址,我可以看到solr管理页面.我确保端口8983对于solr是开放的(以及Django开发服务器的8000).
我觉得我可能没有提供足够的连接信息,但还有什么可以检查?
更新:
虽然我解决了这个问题,但还有更多问题,所有这些都是通过使用solr(v.4.7.0)来修复的,因为django-haystack还没有为solr 5做好准备(有一个与此相关的问题但是我再也无法在github上找到它.
我对搜索实现很陌生,在我学习的同时忍受我!
所以我的宠物项目是一个食谱站点,每个食谱可以有n个步骤.该模型看起来像:
class Recipe(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
hotness = models.ForeignKey(Hotness)
recipe_diet = models.ManyToManyField(DietType)
ingredients = models.ManyToManyField(Ingredient, through="RecipeIngredient")
class DietType(models.Model):
diet_type = models.CharField(max_length=50)
description = models.TextField(null=True, blank=True)
class RecipeIngredient(models.Model):
recipe = models.ForeignKey(Recipe)
ingredient = models.ForeignKey(Ingredient)
quantifier = models.ForeignKey(Quantifier)
quantity = models.FloatField()
class RecipeSteps(models.Model):
step_number = models.IntegerField()
description = models.TextField()
recipe = models.ForeignKey(Recipe)
Run Code Online (Sandbox Code Playgroud)
(简称简称)
我想索引所有这些:Recipe,RecipeIngredient,DietType和Steps ... DietType和RecipeIngredient似乎工作正常,但步骤不是.我假设这与'RelatedSearchQuerySet'的使用有关?
这是我的search_indexes.py:
from haystack import indexes
from recipes.models import Recipe
class RecipeIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr='title')
ingredients = indexes.MultiValueField(indexed=True, …Run Code Online (Sandbox Code Playgroud) 我使用django haystack和xapian作为后端搜索引擎.我正在使用FacetedSearchView和FacetedSearchForm面对搜索.我已经searchqueryset转到了FacetSearchView我的urls.py文件中.
但问题是我无法searchqueryset在模板中访问它.我想要做的就是计算searchqueryset找到的对象数量.
在shell中我可以用S实现它earchQuerySet().filter(content="foo").count(),我怎样才能在模板中做到这一点?请指导.我想要与搜索匹配的对象总数.
django-haystack ×10
django ×9
python ×4
solr ×4
pysolr ×2
search ×1
stop-words ×1
whoosh ×1
xapian ×1