Etienne Posthumus
unread,Jan 22, 2009, 10:44:06 AM1/22/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to solrpy
Here is a svn diff to revision 18 to fix some issues with the data
conversions when adding data.
Two things are changed:
1) The basic data conversions are moved inside the list handing loop,
so that it also converts items inside the list
2) Add support for datetime.date objects which dont have times
attached.
Index: solr.py
===================================================================
--- solr.py (revision 18)
+++ solr.py (working copy)
@@ -671,13 +671,7 @@
def __add(self, lst, fields):
lst.append(u'<doc>')
for field, value in fields.items():
- # Do some basic data conversion
- if isinstance(value, datetime.datetime):
- value = utc_to_string(value)
- elif isinstance(value, bool):
- value = value and 'true' or 'false'
-
# Handle multi-valued fields if values
# is passed in as a list/tuple
if not isinstance(value, (list, tuple)):
@@ -686,6 +680,14 @@
values = value
for value in values:
+ # Do some basic data conversion
+ if isinstance(value, datetime.date):
+ value = datetime.datetime.combine(value,
datetime.time(tzinfo=UTC()))
+ if isinstance(value, datetime.datetime):
+ value = utc_to_string(value)
+ elif isinstance(value, bool):
+ value = value and 'true' or 'false'
+
lst.append('<field name=%s>%s</field>' % (
(quoteattr(field),
escape(unicode(value)))))