kopia lustrzana https://github.com/wagtail/wagtail
Search query normalisation no longer removes punctuation #5416
rodzic
10bbfec93c
commit
3754d34caa
|
@ -65,6 +65,7 @@ Changelog
|
|||
* Fix: Move focus to the pages explorer menu when open (Helen Chapman)
|
||||
* Fix: Clicking the privacy toggle while the page is still loading no longer loads the wrong data in the page (Helen Chapman)
|
||||
* Fix: Added missing `is_stored_locally` method to `AbstractDocument` (jonny5532)
|
||||
* Fix: Query model no longer removes punctuation as part of string normalisation (William Blackie)
|
||||
|
||||
|
||||
2.5.1 (07.05.2019)
|
||||
|
|
|
@ -381,6 +381,7 @@ Contributors
|
|||
* Fidel Ramos
|
||||
* Quadric
|
||||
* jonny5532
|
||||
* William Blackie
|
||||
|
||||
Translators
|
||||
===========
|
||||
|
|
|
@ -96,6 +96,7 @@ Bug fixes
|
|||
* ``Page.copy()`` no longer copies child objects when the accesssor name is included in ``exclude_fields_in_copy`` (Karl Hobley)
|
||||
* Clicking the privacy toggle while the page is still loading no longer loads the wrong data in the page (Helen Chapman)
|
||||
* Added missing ``is_stored_locally`` method to ``AbstractDocument`` (jonny5532)
|
||||
* Query model no longer removes punctuation as part of string normalisation (William Blackie)
|
||||
|
||||
|
||||
Upgrade considerations
|
||||
|
|
|
@ -33,17 +33,17 @@ class TestHitCounter(TestCase):
|
|||
|
||||
class TestQueryStringNormalisation(TestCase):
|
||||
def setUp(self):
|
||||
self.query = models.Query.get("Hello World!")
|
||||
self.query = models.Query.get(" Hello World! ")
|
||||
|
||||
def test_normalisation(self):
|
||||
self.assertEqual(str(self.query), "hello world")
|
||||
self.assertEqual(str(self.query), "hello world!")
|
||||
|
||||
def test_equivilant_queries(self):
|
||||
def test_equivalent_queries(self):
|
||||
queries = [
|
||||
"Hello World",
|
||||
"Hello World!!",
|
||||
"hello world",
|
||||
"Hello' world",
|
||||
" Hello World!",
|
||||
"Hello World! ",
|
||||
"hello world!",
|
||||
" Hello world! ",
|
||||
]
|
||||
|
||||
for query in queries:
|
||||
|
@ -52,7 +52,8 @@ class TestQueryStringNormalisation(TestCase):
|
|||
def test_different_queries(self):
|
||||
queries = [
|
||||
"HelloWorld",
|
||||
"Hello orld!!",
|
||||
"HelloWorld!"
|
||||
" Hello World! ",
|
||||
"Hello",
|
||||
]
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import operator
|
||||
import re
|
||||
import string
|
||||
from functools import partial, reduce
|
||||
|
||||
# Reduce any iterable to a single value using a logical OR e.g. (a | b | ...)
|
||||
|
@ -22,11 +21,8 @@ def normalise_query_string(query_string):
|
|||
# Convert query_string to lowercase
|
||||
query_string = query_string.lower()
|
||||
|
||||
# Strip punctuation characters
|
||||
query_string = ''.join([c for c in query_string if c not in string.punctuation])
|
||||
|
||||
# Remove double spaces
|
||||
query_string = ' '.join(query_string.split())
|
||||
# Remove leading, trailing and multiple spaces
|
||||
query_string = re.sub(' +', ' ', query_string).strip()
|
||||
|
||||
return query_string
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue