This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring search to take advantage of ListableMixin fields.
- Loading branch information
Greg Turner
committed
Nov 22, 2016
1 parent
d73cdae
commit 29a5d1b
Showing
10 changed files
with
131 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Search in ICEkit | ||
|
||
ICEkit uses Haystack with an Elastic Search backend for its onsite search. | ||
|
||
It comes with a simple SearchIndex, `icekit.utils.search.AbstractLayoutIndex` | ||
which works well on content that: | ||
|
||
* Implements the `ListableMixin` for getting list content | ||
* Uses fluent contents (having a number of rich content placeholders) | ||
* Is publishable (the index queryset defaults to `objects.published()`) | ||
* Is polymorphic (the `django_ct` value always matches `get_model()`, rather | ||
than varying by the object being indexed. | ||
|
||
ICEkit and GLAMkit's default content types use this index: | ||
|
||
* Page (including LayoutPage, ArticleListingPage, etc.) | ||
* Article | ||
* Author | ||
|
||
And in optional libraries: | ||
* icekit_events.EventBase | ||
* icekit_press_releases.PressRelease | ||
* glamkit_collections.WorkBase | ||
* glamkit_collections.CreatorBase | ||
* etc. | ||
|
||
`AbstractLayoutIndex` renders the `search/indexes/icekit/default.txt` template | ||
which indexes ListableMixin content, all Fluent placeholders, and some common | ||
content fields. You can render a different template in your search index by | ||
redeclaring the `title` field. HTML tags are stripped and HTML entities are | ||
converted to unicode. | ||
|
||
## Using `AbstractLayoutIndex` | ||
|
||
As minimal example, create `search_indexes.py` on a publishable, `ListableMixin` | ||
model: | ||
|
||
from haystack import indexes | ||
from icekit.utils.search import AbstractLayoutIndex | ||
from . import models | ||
|
||
class MyModelIndex(AbstractLayoutIndex, indexes.Indexable): | ||
def get_model(self): | ||
return models.MyModel | ||
|
||
Publish the content you want to be indexed, then run `manage.py update_index`. | ||
|
||
## Search Page | ||
|
||
The `icekit.page_types.search_page` page plugin implements a search page. | ||
To use it for your site, create a search page, and preview/publish it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from haystack import indexes | ||
from icekit.utils.search import AbstractLayoutIndex | ||
from . import models | ||
|
||
class ArticleIndex(AbstractLayoutIndex, indexes.Indexable): | ||
def get_model(self): | ||
return models.Article |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,7 @@ | ||
# from haystack import indexes | ||
# | ||
# from django.conf import settings | ||
# from django.utils import translation | ||
# | ||
# from . import models | ||
# | ||
# | ||
# class AuthorIndex(indexes.SearchIndex, indexes.Indexable): | ||
# """ | ||
# Search index for `Author`. | ||
# """ | ||
# text = indexes.CharField(document=True, use_template=True) | ||
# name = indexes.CharField(model_attr='title', boost=2.0) | ||
# url = indexes.CharField(model_attr='get_absolute_url') | ||
# has_url = indexes.BooleanField(model_attr='get_absolute_url') | ||
# # We add this for autocomplete. | ||
# content_auto = indexes.EdgeNgramField(model_attr='title') | ||
# | ||
# def index_queryset(self, using=None): | ||
# """ Index only published authors """ | ||
# # TODO Hack to activate the site language if none is yet active, to | ||
# # avoid complaints about null language_code when traversing the | ||
# # `parent` relationship -- should probably do this elsewhere? | ||
# if not translation.get_language(): | ||
# translation.activate(settings.LANGUAGE_CODE) | ||
# return self.get_model().objects.published() | ||
# | ||
# def get_model(self): | ||
# """ | ||
# Get the model for the search index. | ||
# """ | ||
# return models.Author | ||
from haystack import indexes | ||
from icekit.utils.search import AbstractLayoutIndex | ||
from . import models | ||
|
||
class AuthorIndex(AbstractLayoutIndex, indexes.Indexable): | ||
def get_model(self): | ||
return models.Author |
13 changes: 0 additions & 13 deletions
13
icekit/page_types/author/templates/search/indexes/icekit_authors/author_text.txt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
from fluent_pages.integration.fluent_contents import FluentContentsPage | ||
from icekit.mixins import ListableMixin | ||
|
||
from icekit.publishing.models import PublishableFluentContentsPage | ||
|
||
|
||
class AbstractUnpublishableSearchPage(FluentContentsPage): | ||
class AbstractUnpublishableSearchPage(FluentContentsPage, ListableMixin): | ||
class Meta: | ||
abstract = True | ||
verbose_name = 'Search page' | ||
|
||
|
||
class AbstractSearchPage(PublishableFluentContentsPage): | ||
class AbstractSearchPage(PublishableFluentContentsPage, ListableMixin): | ||
class Meta: | ||
abstract = True | ||
verbose_name = 'Search page' |
24 changes: 24 additions & 0 deletions
24
icekit/page_types/search_page/migrations/0004_auto_20161122_2121.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('search_page', '0003_auto_20160810_1856'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='searchpage', | ||
name='boosted_search_terms', | ||
field=models.TextField(blank=True, help_text='Words (space-separated) added here are boosted in relevance for search results increasing the chance of this appearing higher in the search results.'), | ||
), | ||
migrations.AddField( | ||
model_name='searchpage', | ||
name='list_image', | ||
field=models.ImageField(upload_to=b'icekit/listable/list_image/', blank=True, help_text=b"image to use in listings. Default image is used if this isn't given"), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters