Last active
August 29, 2015 14:09
-
-
Save xaralis/6848b427c43b20534299 to your computer and use it in GitHub Desktop.
Elastic search v Djangu česky
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
you@computer:~$ elasticsearch --config=/usr/local/opt/elasticsearch/config/elasticsearch.yml | |
[2014-11-10 10:41:49,409][INFO ][node ] [Toad-In-Waiting] version[1.3.4], pid[99851], build[a70f3cc/2014-09-30T09:07:17Z] | |
[2014-11-10 10:41:49,411][INFO ][node ] [Toad-In-Waiting] initializing ... | |
[2014-11-10 10:41:58,357][INFO ][node ] [Toad-In-Waiting] initialized | |
[2014-11-10 10:41:58,358][INFO ][node ] [Toad-In-Waiting] starting ... | |
[2014-11-10 10:41:58,491][INFO ][transport ] [Toad-In-Waiting] bound_address {inet[/127.0.0.1:9300]}, publish_address {inet[/127.0.0.1:9300]} | |
[2014-11-10 10:41:58,511][INFO ][discovery ] [Toad-In-Waiting] xaralis/oIhw_OW3Trim_30_TOz_Mw | |
[2014-11-10 10:42:01,527][INFO ][cluster.service ] [Toad-In-Waiting] new_master [Toad-In-Waiting][oIhw_OW3Trim_30_TOz_Mw][matrix][inet[/127.0.0.1:9300]], reason: zen-disco-join (elected_as_master) | |
[2014-11-10 10:42:01,558][INFO ][http ] [Toad-In-Waiting] bound_address {inet[/127.0.0.1:9200]}, publish_address {inet[/127.0.0.1:9200]} | |
[2014-11-10 10:42:01,559][INFO ][node ] [Toad-In-Waiting] started |
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
ELASTICSEARCH_INDEX_SETTINGS = { | |
'settings': { | |
'analysis': { | |
'analyzer' : { | |
'cs_hunspell': { | |
'type': 'custom', | |
'tokenizer': 'standard', | |
'filter': ['stopwords_CZ', 'lowercase', 'hunspell_CZ', 'asciifolding', 'stopwords_CZ', 'remove_duplicities'] | |
} | |
}, | |
'filter': { | |
'stopwords_CZ': { | |
'type': 'stop', | |
'stopwords': ["právě", "že", "_czech_"], | |
'ignore_case': True | |
}, | |
'hunspell_CZ': { | |
'type': 'hunspell', | |
'locale': 'cs_CZ', | |
'dedup': True, | |
'recursion_level': 0 | |
}, | |
'remove_duplicities': { | |
'type': 'unique', | |
'only_on_same_position': True | |
} | |
} | |
} | |
} | |
} | |
ELASTICSEARCH_DEFAULT_ANALYZER = 'cs_hunspell' |
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
HAYSTACK_CONNECTIONS = { | |
'default': { | |
'ENGINE': 'elasticstack.backends.ConfigurableElasticSearchEngine', | |
'URL': '127.0.0.1:9200', | |
'INDEX_NAME': 'my_custom_index', | |
}, | |
} |
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
INSTALLED_APPS = [ | |
... | |
'haystack', | |
'elasticstack', | |
... | |
] |
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
{{ object.title }} | |
{{ object.author.get_full_name }} | |
{{ object.perex|striptags }} | |
{{ object.content|striptags }} |
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
you@computer:/projects/myproject$ python manage.py rebuild_index --noinput | |
Removing all documents from your index because you said so. | |
All documents removed. | |
Indexing 164 Stránky |
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
{% extends 'base.html' %} | |
{% block content %} | |
<h2>Vyhledávání</h2> | |
<form method="get" action="."> | |
<table> | |
{{ form.as_table }} | |
<tr> | |
<td> </td> | |
<td> | |
<input type="submit" value="Hledat"> | |
</td> | |
</tr> | |
</table> | |
{% if query %} | |
<h3>Výsledky</h3> | |
{% for result in page.object_list %} | |
<p> | |
<a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a> | |
</p> | |
{% empty %} | |
<p>Nic nebylo nalezeno.</p> | |
{% endfor %} | |
{% if page.has_previous or page.has_next %} | |
<div> | |
{% if page.has_previous %}<a href="?q={{ query }}&page={{ page.previous_page_number }}">{% endif %}« Předchozí{% if page.has_previous %}</a>{% endif %} | |
| | |
{% if page.has_next %}<a href="?q={{ query }}&page={{ page.next_page_number }}">{% endif %}Následující »{% if page.has_next %}</a>{% endif %} | |
</div> | |
{% endif %} | |
{% endif %} | |
</form> | |
{% endblock %} |
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
from haystack import indexes | |
from myproject.app import models | |
class PageIndex(indexes.SearchIndex, indexes.Indexable): | |
text = indexes.CharField(document=True, use_template=True) | |
title = indexes.CharField(model_attr='title', boost=5) | |
def get_model(self): | |
return models.Page | |
def index_queryset(self, using=None): | |
return self.get_model().objects.published() |
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
... | |
(r'^vyhledavani/', include('haystack.urls')), | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment