[Grok-dev] Assertion error when quering TextIndex

Sebastian Ware sebastian at urbantalk.se
Tue Jun 26 13:46:56 EDT 2007


It works like a charm :)

Is this really simple stuff? Or should I try to write a little newbie  
tutorial on seaching?

Mvh Sebastian

26 jun 2007 kl. 19.38 skrev Kevin Smith:

>
>
> Sebastian Ware wrote:
>> Maybe I am making a silly mistake, but I am doing this...
>>
>> from hurry.query.query import Query, Text
>>
>> class ContentIndexes(grok.Indexes):
>>     grok.site(ProtonCMS)
>>     grok.context(interfaces.IProtonObject)
>>     grok.name('proton_catalog')
>>
>>     text_body = index.Text(attribute='body')
>>     body = index.Field(attribute='body')
>>
>> ...and this works...
>>
>> def search_content(self, search_term):
>>     result = Query().searchResults(
>>                      query.Eq(('proton_catalog', 'body'),  
>> search_term)
>>                      )
>>     return result
>>
>> ...but this gives a ComponentLookupError...
>>
>> def search_content(self, search_term):
>>     result = Query().searchResults(
>>                      Text( ('', 'text_body'), search_term)
>>                      )
> Since it's a named catalog, "proton_catalog" needs to be referenced  
> explicitly.
>
> def search_content(self, search_term):
>    result = Query().searchResults(
>                     Text( ('proton_catalog', 'text_body'),  
> search_term)
>                     )
>
>
>
>
>>     return result
>>
>> ...the traceback...
>>
>>   File "/Users/sebastianware/GrokProjects/ProtonCMS/src/protoncms/ 
>> app.py", line 31, in search_content
>>     result = Query().searchResults(Text( ('', 'text_body'),  
>> search_term))
>>   File "/Users/sebastianware/GrokProjects/ProtonCMS/eggs/ 
>> hurry.query-0.9.2-py2.4.egg/hurry/query/query.py", line 20, in  
>> searchResults
>>     results = query.apply()
>>   File "/Users/sebastianware/GrokProjects/ProtonCMS/eggs/ 
>> hurry.query-0.9.2-py2.4.egg/hurry/query/query.py", line 128, in apply
>>     index = self.getIndex()
>>   File "/Users/sebastianware/GrokProjects/ProtonCMS/eggs/ 
>> hurry.query-0.9.2-py2.4.egg/hurry/query/query.py", line 123, in  
>> getIndex
>>     index = super(Text, self).getIndex()
>>   File "/Users/sebastianware/GrokProjects/ProtonCMS/eggs/ 
>> hurry.query-0.9.2-py2.4.egg/hurry/query/query.py", line 113, in  
>> getIndex
>>     catalog = zapi.getUtility(ICatalog, self.catalog_name)
>>   File "/opt/zope3.3/lib/python/zope/component/_api.py", line 207,  
>> in getUtility
>>     raise ComponentLookupError(interface, name)
>> ComponentLookupError: (<InterfaceClass  
>> zope.app.catalog.interfaces.ICatalog>, '')
>>
>>
>> Mvh Sebastian
>>
>> 26 jun 2007 kl. 18.43 skrev Kevin Smith:
>>
>>> Here's some sample code.
>>>
>>> # setup index
>>> class SearchableTextIndex(grok.Indexes):
>>>    grok.site(MySite)
>>>    grok.context(ISearchableText)
>>>
>>>    searchabletext  = index.Text()
>>>
>>> # search function
>>> from hurry.query.query import Query, Text
>>> def search_text(text):
>>>    results = Query().searchResults(
>>>        Text( ('', 'searchabletext'), text)
>>>        )
>>>    return results
>>>
>>>
>>> HTH,
>>>
>>> Kevin Smith
>>>
>>> Sebastian Ware wrote:
>>>> I can't find an example in the DocTest that performs a TextIndex  
>>>> search. It only has FieldIndex, SetIndex and ValueIndex  
>>>> (hurry.query.0.9.2). I try to mimic the FieldIndex search (that  
>>>> works) but I get an assertion error.
>>>>
>>>> I can see the "text_body' index in the Zope 3 management  
>>>> screens, and it would shows 3 documents and 53 words indexed.
>>>>
>>>> This is the traceback:
>>>>
>>>>   File "/Users/sebastianware/GrokProjects/ProtonCMS/src/ 
>>>> protoncms/app.py", line 32, in content_list
>>>>     result = Query().searchResults(query.Eq(('proton_catalog',  
>>>> 'text_body'), search_term))
>>>>   File "/Users/sebastianware/GrokProjects/ProtonCMS/eggs/ 
>>>> hurry.query-0.9.2-py2.4.egg/hurry/query/query.py", line 20, in  
>>>> searchResults
>>>>     results = query.apply()
>>>>   File "/Users/sebastianware/GrokProjects/ProtonCMS/eggs/ 
>>>> hurry.query-0.9.2-py2.4.egg/hurry/query/query.py", line 144, in  
>>>> apply
>>>>     return self.getIndex().apply((self.value, self.value))
>>>>   File "/Users/sebastianware/GrokProjects/ProtonCMS/eggs/ 
>>>> hurry.query-0.9.2-py2.4.egg/hurry/query/query.py", line 134, in  
>>>> getIndex
>>>>     assert IFieldIndex.providedBy(index)
>>>> AssertionError
>>>>
>>>> Mvh Sebastian
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Grok-dev mailing list
>>>> Grok-dev at zope.org
>>>> http://mail.zope.org/mailman/listinfo/grok-dev
>>>>
>>
>> _______________________________________________
>> Grok-dev mailing list
>> Grok-dev at zope.org
>> http://mail.zope.org/mailman/listinfo/grok-dev
>>



More information about the Grok-dev mailing list