English 中文(简体)
Django-haystack使用属性过滤结果?
原标题:Django-haystack result filtering using attributes?

难道有人能举一个例子,说明如何利用属性,对全文检索结果进行过滤? 我在自己的网站上通过该辅导,但对于如何使用“灰色”。

For instance, let s say I have a class Product:

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)

If I want to provide fulltext search on title & description, and filtering (based on drop-down lists, not free text) on category and color - what do I need to do? Can I use the forms and views that come with haystack?

感谢。

问题回答

您是否在<上读到 rel=“nofollow noreferer”>?tutorial/documentation上载于django-haystack网站? 它通过一个根据<代码>说明<>/代码>模式的作者进行过滤的实例,在开始辅导时采用这一模式。

与沙斯特克和搜寻不同的另一种选择是:django-filter<>/code>,由Alex Gaynor提供,它允许你根据模型内容而不是指数对田地进行过滤。 因此,可将其用于按<代码>django-haystack索引的模型。 http://github.com/alex/django-filter”rel=“nofollow noretinger”>here。 笔记中有好的笔记,其中包括测试显示所有功能。

如果我们总结一下如何增加面对的灰色。

  1. you need to add faceted fields to your index model
 title =  CharField(model_attr= title , faceted=True)
 description =  CharField(model_attr= description , faceted=True)
  1. change your queryset to
  sqs = SearchQuerySet().facet( title ).facet( description )
  1. use faceted versions of search form and view that haystack provides in urls.py use this
  url(r ^$ , FacetedSearchView(form_class=FacetedSearchForm, searchqueryset=sqs), name= haystack_search ),
  1. http://docs.haystacksearch.org/dev/faceting.html#display-the-facets-in-the-template”rel=“nofollow”

  2. 重建你的指数,以了解面对的影响

 
   python manage.py rebuild_index




相关问题
Acronyms with Sphinx search engine

how can i index acronyms like m.i.a. ? when i search for mia , i get results for mia and not m.i.a. . when i search for m.i.a. , i get nothing at all. edit: solution looks roughly like: ...

Querying multiple index in django-sphinx

The django-sphinx documentation shows that django-sphinx layer also supports some basic querying over multiple indexes. http://github.com/dcramer/django-sphinx/blob/master/README.rst from ...

Adding Search to Ruby on Rails - Easy Question

I am trying to figure out how to add search to my rails application. I am brand new so go slow. I have created a blog and done quite a bit of customizing including adding some AJAX, pretty proud of ...

Searching and ranking short phrases (e.g. movie titles)

I m trying to improve our search capabilities for short phrases (in our case movie titles) and am currently looking at SQL Server 2008 Full Text Search, which provides some of the functionality we ...

Will Full text search consider indexes?

Ok I have a full text search index created on my JobsToDo table, but what I m concerned about is if this is rendering my other indexes on the table useless. I have a normal nonclustered index on the ...

Lucene.NET on shared hosting

I m trying to get Lucene.NET to work on a shared hosting environment. Mascix over on codeproject outlines here how he got this to work on godaddy. I m attempting this on isqsolutions. Both ...

Hibernate Search or Compass

I can t seem to find any recent talk on the choice. Back in 06 there was criticism on Hibernate Search as being incomplete and not being ready to compete with Compass, is it now? Has anyone used both ...

热门标签