Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mozilla/kuma
...
head fork: mozilla/kuma
Checking mergeability… Don't worry, you can still create the pull request.
  • 6 commits
  • 8 files changed
  • 0 commit comments
  • 2 contributors
View
15 README.rst
@@ -6,10 +6,17 @@ Kuma is the platform that powers `MDN (developer.mozilla.org)
<https://developer.mozilla.org>`_
-It is a Django_ application.
+Development
+===========
-.. MozillaDeveloperNetowrk: https://support.mozilla.org/
-.. _Django: http://www.djangoproject.com/
+:Code: https://github.com/mozilla/kuma
+:Issues: http://mzl.la/mdn_backlog
+:Dev Docs: https://github.com/mozilla/kuma/blob/master/docs/installation-vagrant.rst
+:CI Server: https://ci.mozilla.org/job/mdn/
+:Mailing list: https://lists.mozilla.org/listinfo/dev-mdn
+:IRC: irc://irc.mozilla.org/mdndev
+:Servers: https://developer-dev.allizom.org/ (dev)
+ https://developer.allizom.org/ (stage)
-You can access the staging site at https://developer.allizom.org/
+ https://developer.mozilla.org/ (prod)
View
16 apps/search/index.py
@@ -6,7 +6,7 @@
from django.db import reset_queries
from elasticutils.contrib.django import get_es, S
-from elasticutils.contrib.django.models import DjangoMappingType
+from elasticutils.contrib.django import MappingType
from pyelasticsearch.exceptions import (ConnectionError, Timeout,
ElasticHttpNotFoundError)
@@ -56,8 +56,8 @@ def get_index():
return '%s-%s' % (settings.ES_INDEX_PREFIX, settings.ES_INDEXES['default'])
-class SearchMappingType(DjangoMappingType):
- """DjangoMappingType with correct index."""
+class SearchMappingType(MappingType):
+ """MappingType with correct index."""
@classmethod
def get_index(cls):
return get_index()
@@ -202,11 +202,14 @@ def recreate_index(es=None):
es = get_indexing_es()
mappings = {}
+ analysis = None
for name, mt in get_mapping_types().items():
mapping = mt.get_mapping()
if mapping is not None:
mappings[name] = {'properties': mapping}
+ analysis = mt.get_analysis()
+
index = get_index()
delete_index_if_exists(index)
@@ -220,7 +223,12 @@ def recreate_index(es=None):
# freak out if the inferred mapping is incompatible with the
# explicit mapping).
- es.create_index(index, settings={'mappings': mappings})
+ es.create_index(index, settings={'mappings': mappings,
+ 'settings':
+ {'index':
+ {'analysis': analysis}
+ }
+ })
def get_indexable(percent=100, mapping_types=None):
View
5 apps/search/templates/search/results.html
@@ -7,6 +7,11 @@
<li class="doc-result">
{% set url = '%s%s' % (settings.SITE_URL, url('wiki.document', doc.slug, locale=doc.locale)) %}
<h3><a href="{{ url }}">{{ doc.title }}</a></h3>
+ <div class="searchHighlight">
+ {% for match in doc._highlight['content'] %}
+ <span>{{ match|safe }}</span> ...
+ {% endfor %}
+ </div>
<div class="searchMeta"><a href="{{ url }}">{{ url }}</a></div>
<p><!-- match content here --></p>
</li>
View
6 apps/search/tests/__init__.py
@@ -36,8 +36,8 @@ def setUpClass(cls):
cls._old_es_index_prefix = settings.ES_INDEX_PREFIX
settings.ES_INDEX_PREFIX = settings.ES_INDEX_PREFIX + 'test'
# TODO: cleanup after upgarding test-utils (also in tearDownClass)
- cls._old_es_live_index = settings.__dict__['ES_LIVE_INDEX']
- settings.__dict__['ES_LIVE_INDEX'] = True
+ cls._old_es_live_index = settings.ES_LIVE_INDEX
+ settings.ES_LIVE_INDEX = True
@classmethod
def tearDownClass(cls):
@@ -51,7 +51,7 @@ def tearDownClass(cls):
# Restore old setting.
settings.ES_INDEX_PREFIX = cls._old_es_index_prefix
# TODO: cleanup after upgarding test-utils
- settings.__dict__['ES_LIVE_INDEX'] = cls._old_es_live_index
+ settings.ES_LIVE_INDEX = cls._old_es_live_index
def setUp(self):
if self.skipme:
View
8 apps/search/tests/test_tasks.py
@@ -3,19 +3,21 @@
from search.tests import ElasticTestCase
from wiki.models import DocumentType
-from wiki.tests import document
+from wiki.tests import revision
class TestLiveIndexing(ElasticTestCase):
+ fixtures = ['test_users.json',]
+
def test_live_indexing_docs(self):
S = DocumentType.search
count_before = S().count()
- d = document(title='Testing live index', save=True)
+ r = revision(save=True)
self.refresh()
eq_(count_before + 1, S().count())
- d.delete()
+ r.document.delete()
self.refresh()
eq_(count_before, S().count())
View
3  apps/search/views.py
@@ -38,8 +38,9 @@ def search(request):
results = DocumentType.search()
if search_query:
- results = results.query(or_={'title': search_query,
+ results = (results.query(or_={'title': search_query,
'content': search_query})
+ .highlight('content'))
result_count = results.count()
results = results[start:end]
View
20 apps/wiki/models.py
@@ -21,11 +21,11 @@
from django.core.urlresolvers import resolve
from django.db import models, transaction
from django.http import Http404
-from django.utils.http import http_date
+from django.utils.html import strip_tags
from south.modelsinspector import add_introspection_rules
import constance.config
-from elasticutils.contrib.django.models import Indexable
+from elasticutils.contrib.django import Indexable
from tidings.models import NotificationsMixin
from search.index import SearchMappingType, register_mapping_type
@@ -1536,7 +1536,7 @@ def extract_document(cls, obj_id, obj=None):
'title': obj.title,
'slug': obj.slug,
'locale': obj.locale,
- 'content': obj.rendered_html
+ 'content': strip_tags(obj.rendered_html)
}
@classmethod
@@ -1546,7 +1546,7 @@ def get_mapping(cls):
'title': {'type': 'string'},
'slug': {'type': 'string'},
'locale': {'type': 'string', 'index': 'not_analyzed'},
- 'content': {'type': 'string', 'analyzer': 'snowball'}
+ 'content': {'type': 'string', 'analyzer': 'wikiMarkup'}
}
@classmethod
@@ -1559,6 +1559,18 @@ def get_indexable(cls):
.values_list('id', flat=True)
)
+ @classmethod
+ def get_analysis(cls):
+ return {
+ 'analyzer': {
+ 'wikiMarkup': {
+ 'type': 'standard',
+ 'char_filter': 'html_strip'
+ }
+ }
+ }
+
+
class ReviewTag(TagBase):
"""A tag indicating review status, mainly for revisions"""
2  vendor
@@ -1 +1 @@
-Subproject commit 621b0612911353f86af6c399e7b881d782a8a1c1
+Subproject commit 31bc66bf169b8dd9a65f98b179bcdb098d9d9ee2

No commit comments for this range

Something went wrong with that request. Please try again.