Django搜索的Whoosh但是没有Haystack?

时间:2022-09-12 23:18:41

I'm just wondering what is exactly the functionality that haystack provides and if I need it.

我只是想知道haystack到底提供了什么功能,如果我需要的话。

I mean the search and indexing is done by whoosh. As far as I can tell, haystack is just offering ready made views, and forms. If I want to write my own form and views do I still need haystack? Am I missing something?

我的意思是搜索和索引是由whoosh完成的。据我所知,haystack只是提供现成的视图和表单。如果我想写我自己的表单和视图,我还需要haystack吗?我遗漏了什么东西?

P.S. I don't plan to use any other search engine than whoosh so I also don't need haystacks's multiple search engine wrapping.

另外,除了whoosh,我不打算使用任何搜索引擎,所以我也不需要haystack的多重搜索引擎包装。

1 个解决方案

#1


2  

Besides views, forms and a search engine-agnostic layer, the other powerful thing about Haystack is its ability to map Django models to something the search index understands. Using Haystack, you can easily specify which fields in a model should be indexed and how (see the SearchIndex API - http://django-haystack.readthedocs.org/en/latest/searchindex_api.html).

除了视图、表单和搜索引擎无关层之外,Haystack的另一个强大之处在于它能够将Django模型映射到搜索索引所理解的东西。使用Haystack,您可以很容易地指定模型中的哪些字段应该被索引以及如何索引(参见SearchIndex API—http://django-haystack.readthedocs.org/en/latest/searchindex_api)。

Once you have done that, you can then leverage the built-in management commands to (re)index your data when required.

一旦这样做了,您就可以利用内置的管理命令在需要时对数据进行索引。

It also comes with some nice templatetags to help present search results, like highlighting the matching bits.

它还附带了一些不错的模板标记,以帮助显示搜索结果,比如突出显示匹配的位。

Is there a particular reason that you don't want to use Haystack? It is a pretty non-intrusive plugin that lets you use as much of it as you need, and makes it easy to use more advanced functionality when you need it later down the road. In one of the sites I built, I only used the SearchIndex and SearchQuerySet APIs; I built my own views and forms. Ultimately, if you end up writing your own indexing and searching code, views and forms, you have basically re-written a large part of Haystack, in which case, you may want to consider using something that is in use out there and reasonably well tested.

你有什么特别的理由不想使用Haystack吗?它是一个非常非侵入性的插件,可以让你尽可能多地使用它,并使它在以后需要的时候更容易使用更高级的功能。在我建立的一个网站中,我只使用了SearchIndex和SearchQuerySet api;我建立了自己的观点和形式。最后,如果您最终编写了自己的索引和搜索代码、视图和表单,那么您基本上已经重写了Haystack的很大一部分,在这种情况下,您可能需要考虑使用一些正在使用并经过合理测试的东西。

That said, I have rolled my own 'Haystack' like layer in another project, mainly because the data source didn't map to the Django ORM. In that case, I wrote my own indexing scripts, and used PySolr to interface with my Apache Solr instance.

也就是说,我在另一个项目中使用了类似Haystack的层,主要是因为数据源没有映射到Django ORM。在这种情况下,我编写了自己的索引脚本,并使用PySolr与Apache Solr实例进行接口。

Given that Whoosh is written in Python, I'd assume it has a decent Python interface, so it shouldn't be too hard to do. I would only do it if there's something special about your scenario though.

考虑到Whoosh是用Python编写的,我假设它有一个不错的Python接口,所以做起来应该不难。我只会在你的场景中有特别的东西时才这么做。

#1


2  

Besides views, forms and a search engine-agnostic layer, the other powerful thing about Haystack is its ability to map Django models to something the search index understands. Using Haystack, you can easily specify which fields in a model should be indexed and how (see the SearchIndex API - http://django-haystack.readthedocs.org/en/latest/searchindex_api.html).

除了视图、表单和搜索引擎无关层之外,Haystack的另一个强大之处在于它能够将Django模型映射到搜索索引所理解的东西。使用Haystack,您可以很容易地指定模型中的哪些字段应该被索引以及如何索引(参见SearchIndex API—http://django-haystack.readthedocs.org/en/latest/searchindex_api)。

Once you have done that, you can then leverage the built-in management commands to (re)index your data when required.

一旦这样做了,您就可以利用内置的管理命令在需要时对数据进行索引。

It also comes with some nice templatetags to help present search results, like highlighting the matching bits.

它还附带了一些不错的模板标记,以帮助显示搜索结果,比如突出显示匹配的位。

Is there a particular reason that you don't want to use Haystack? It is a pretty non-intrusive plugin that lets you use as much of it as you need, and makes it easy to use more advanced functionality when you need it later down the road. In one of the sites I built, I only used the SearchIndex and SearchQuerySet APIs; I built my own views and forms. Ultimately, if you end up writing your own indexing and searching code, views and forms, you have basically re-written a large part of Haystack, in which case, you may want to consider using something that is in use out there and reasonably well tested.

你有什么特别的理由不想使用Haystack吗?它是一个非常非侵入性的插件,可以让你尽可能多地使用它,并使它在以后需要的时候更容易使用更高级的功能。在我建立的一个网站中,我只使用了SearchIndex和SearchQuerySet api;我建立了自己的观点和形式。最后,如果您最终编写了自己的索引和搜索代码、视图和表单,那么您基本上已经重写了Haystack的很大一部分,在这种情况下,您可能需要考虑使用一些正在使用并经过合理测试的东西。

That said, I have rolled my own 'Haystack' like layer in another project, mainly because the data source didn't map to the Django ORM. In that case, I wrote my own indexing scripts, and used PySolr to interface with my Apache Solr instance.

也就是说,我在另一个项目中使用了类似Haystack的层,主要是因为数据源没有映射到Django ORM。在这种情况下,我编写了自己的索引脚本,并使用PySolr与Apache Solr实例进行接口。

Given that Whoosh is written in Python, I'd assume it has a decent Python interface, so it shouldn't be too hard to do. I would only do it if there's something special about your scenario though.

考虑到Whoosh是用Python编写的,我假设它有一个不错的Python接口,所以做起来应该不难。我只会在你的场景中有特别的东西时才这么做。