Skip to content

Commit

Permalink
Merge pull request #64 from nazrulworld/master
Browse files Browse the repository at this point in the history
Issue #63 Now ensuring we unicode string value would work for both py…
  • Loading branch information
nazrulworld authored Aug 22, 2019
2 parents 4be9b75 + 0532c70 commit 77e71cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion collective/elasticsearch/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __getitem__(self, key):
raise IndexError

if key >= 0:
result_key = (key / self.bulk_size) * self.bulk_size
result_key = int(key / self.bulk_size) * self.bulk_size
start = result_key
result_index = key % self.bulk_size
elif key < 0:
Expand Down
17 changes: 13 additions & 4 deletions collective/elasticsearch/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import logging
import random
import six
import time
import traceback
import transaction
Expand Down Expand Up @@ -161,8 +162,12 @@ def get_index_data(obj, es):

# Ignore errors in converting to unicode, so json.dumps
# does not barf when we're trying to send data to ES.
if isinstance(value, str):
value = unicode(value, 'utf-8', 'ignore')
if six.PY2:
if isinstance(value, str):
value = six.text_type(value, 'utf-8', 'ignore')
else:
if isinstance(value, bytes):
value = value.decode('utf-8', 'ignore')

index_data[index_name] = value

Expand All @@ -175,8 +180,12 @@ def get_index_data(obj, es):
if indexer is not None:
try:
val = indexer()
if isinstance(value, str):
val = unicode(val, 'utf-8', 'ignore')
if six.PY2:
if isinstance(value, str):
value = six.text_type(value, 'utf-8', 'ignore')
else:
if isinstance(value, bytes):
value = value.decode('utf-8', 'ignore')
index_data[name] = val
except Exception:
logger.error('Error indexing value: %s: %s\n%s' % (
Expand Down
2 changes: 2 additions & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
3.0.4 (unreleased)
------------------

- `Issue#63 <https://github.com/collective/collective.elasticsearch/issues/63>`_ Now ensuring unicode value would for both python2 and python3 case. [nazrulworld]

- Now possible to search by other than `Title`, `Description` and `SearchableText` indexes. [nazrulworld]


Expand Down

0 comments on commit 77e71cf

Please sign in to comment.