Collection Filter Error

Hi,
i have hundred of Words and i would like display a Collection of these words like Glossary. ABC... and so on
Ok all is fine, but the Letter "M" and "T" give me an error. All others are fine and displayed.
What i have done:

  1. I added an Index and a Metadata Column to Catalog.
  2. I wrote an Indexer
# -*- coding: utf8 -*-

@indexer(IDocument)
def initialIndexer(obj):
    
    if obj.title is None:        
        return None
    
    title = obj.title
    initial = title[:1]
    
    if isinstance(initial, str):
        initial = initial.decode('utf8').upper()
    
    if str("Ä").decode("utf8") == initial:
        initial = u"A"
    elif str("Ö").decode("utf8") == initial:
        initial = u"O"
    elif str("Ü").decode("utf8") == initial:
        initial = u"U"
    
    return initial
  1. I register an Indexmodifier for plone.app.querystring in configure.zxml
<configure
    xmlns="http://namespaces.zope.org/zope"
    i18n_domain="plonetheme.lexikon">
    
    <utility
        factory=".query_index_modifiers.initial"
        provides="plone.app.querystring.interfaces.IParsedQueryIndexModifier"
        name="initial"
        />

</configure>
  1. the modifier in query_index_modifiers.py
# -*- coding: utf8 -*-
from plone.app.querystring.interfaces import IParsedQueryIndexModifier
from plone.app.querystring.indexmodifiers.query_index_modifiers import base

class initial(base):
    pass
  1. I register a field for the Collection Edit View
<records
    interface="plone.app.querystring.interfaces.IQueryField"
    prefix="plone.app.querystring.field.initial"> 
        <value key="title" i18n:translate="">initial</value>
        <value key="description" i18n:translate="">The first initial Letter of Title</value>
        <value key="enabled">True</value>
        <value key="sortable">True</value>
        <value key="operations">
            <element>plone.app.querystring.operation.string.is</element>
        </value>
        <value key="group" i18n:translate="">Text</value>
    </records>

Ok, and now i get the following Error/Traceback, only by the Letter "M" and "T":

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module plone.app.querystring.querybuilder, line 97, in html_results
  Module plone.app.querystring.querybuilder, line 88, in __call__
  Module plone.app.querystring.querybuilder, line 169, in _makequery
  Module Products.CMFPlone.CatalogTool, line 394, in searchResults
  Module Products.ZCatalog.ZCatalog, line 604, in searchResults
  Module Products.ZCatalog.Catalog, line 1072, in searchResults
  Module Products.ZCatalog.Catalog, line 549, in search
  Module Products.PluginIndexes.common.UnIndex, line 426, in _apply_index
TypeError: can't compare datetime.datetime to unicode

Are these forbidden characters? Why Datetime? I'm clueless.

Postscript:
The URL's of the query in the Editform of Collection

Here is all ok:
/@@querybuilder_html_results?query.i:records=initial&query.o:records=plone.app.querystring.operation.string.is&query.v:records=A&sort_on=sortable_title

Here is the Error:
/@@querybuilder_html_results?query.i:records=initial&query.o:records=plone.app.querystring.operation.string.is&query.v:records=M&sort_on=sortable_title

Update:

in plone/app/querystring/querybuilder.py(170)_makequery()

/@@querybuilder_html_results?query.i:records=initial&query.o:records=plone.app.querystring.operation.string.is&query.v:records=N&sort_on=sortable_title

(Pdb) pp parsedquery
{
  'initial': {'query': 'N'},
  'path': {'query': ['/lexikon/lexikon/']},
  'sort_limit': 10,
  'sort_on': 'sortable_title'
}

/@@querybuilder_html_results?query.i:records=initial&query.o:records=plone.app.querystring.operation.string.is&query.v:records=M&sort_on=sortable_title

(Pdb) pp parsedquery
{
  'initial': {'query': datetime.datetime(2016, 6, 14, 0, 0)},
  'path': {'query': ['/lexikon/lexikon/']},
  'sort_limit': 10,
  'sort_on': 'sortable_title'
}

This observation indicates that for some reason, the "M" gave you a "DateTime" instead of the letter "M". Use the debugger to analyse earlier request processing to find out how this happened (it definitely looks very strange).

Can you try to clear and reindex the related index through the ZMI?

-aj

Yes, i have reindex the Catalog

The thing that bugs me about "initial" is that it's a name that could conceivably also be used to name an attribute that indicates a starting time. Just a random thought.

Ok, the Solution was a wrong indexmodifier. i took it from Subject Index Modifier and all was ok.

My query_index_modifiers.py:

# -*- coding: utf8 -*-
from zope.interface import implementer
from plone.app.querystring.interfaces import IParsedQueryIndexModifier

@implementer(IParsedQueryIndexModifier)

class Initial(object):
  
  def __call__(self, value):
    
     query = value['query']
    
    # query can be a unicode string
    if isinstance(query, unicode):
      query = query.encode("utf-8")
    
    value['query'] = query
    
    return ('initial', value)

Slightly off topic, but I have filtering on Creator and I just discovered that that it does not work for a Creator that has 'ø' in his name. (everything else works).

Making a new indexer for Creator and decode as you did could be a solution, or what do you think ?