Work in progress: indexing and searching

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1099 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2006-02-26 16:30:00 +00:00
parent 57deb86205
commit ffc3707094
9 changed files with 86 additions and 19 deletions

View file

@ -183,13 +183,20 @@ predicates:
[(u'has type', '.loops/concepts/hasType'),
(u'subconcept', '.loops/concepts/standard')]
Searchable Text Adapter
-----------------------
Index attributes adapter
------------------------
>>> from loops.concept import IndexAttributes
>>> idx = IndexAttributes(cc2)
>>> idx.text()
u'cc2 Zope 3'
>>> idx.title()
u'cc2 Zope 3'
>>> idx.type()
'loops:concept:unknown'
Resources and what they have to do with Concepts
================================================
@ -259,6 +266,20 @@ below) via the getClients() method:
>>> conc[0] is cc1
True
Index attributes adapter
------------------------
>>> from loops.resource import IndexAttributes
>>> idx = IndexAttributes(doc1)
>>> idx.text()
u'doc1 Zope Info'
>>> idx.title()
u'doc1 Zope Info'
>>> idx.type()
'loops:resource:Document'
Views/Nodes: Menus, Menu Items, Listings, Pages, etc
====================================================

View file

@ -71,7 +71,7 @@ class BaseView(object):
def typeTitle(self):
voc = util.KeywordVocabulary(getTargetTypes())
token = '.'.join((self.context.__module__,
self.context.__class__.__name__))
self.context.__class__.__name__))
term = voc.getTermByToken(token)
return term.title

View file

@ -120,18 +120,17 @@ class ConceptView(BaseView):
if request.get('action') != 'search':
return []
searchTerm = request.get('searchTerm', None)
if searchTerm:
searchType = request.get('searchType', None)
if searchTerm or searchType:
criteria = {}
if searchTerm:
criteria['loops_title'] = searchTerm
if searchType:
criteria['loops_type'] = (searchType)
cat = zapi.getUtility(ICatalog)
result = cat.searchResults(loops_text=searchTerm)
result = cat.searchResults(**criteria)
else:
result = self.loopsRoot.getConceptManager().values()
searchType = request.get('searchType', '*')
# TODO: query catalog for type
if not searchType:
result = [r for r in result if r.conceptType is None]
elif searchType != '*':
type = self.loopsRoot.loopsTraverse(searchType)
result = [r for r in result if r.conceptType == type]
result = [r for r in result if r.conceptType is None]
return self.viewIterator(result)
@Lazy

View file

@ -37,7 +37,7 @@ from zope.security.proxy import removeSecurityProxy
from loops.interfaces import IConcept, IDocument, IMediaAsset
from loops.resource import MediaAsset
from loops.target import getTargetTypes
from loops.target import getTargetTypes, getTargetTypesForSearch
from loops import util
from loops.browser.common import BaseView
from loops.browser.concept import ConceptView
@ -203,15 +203,29 @@ class ConfigureView(BaseView):
def targetTypes(self):
return util.KeywordVocabulary(getTargetTypes())
def targetTypesForSearch(self):
return util.KeywordVocabulary(getTargetTypesForSearch())
@Lazy
def search(self):
request = self.request
if request.get('action') != 'search':
return []
searchTerm = request.get('searchTerm', None)
if searchTerm:
searchType = request.get('searchType', None)
if searchTerm or searchType:
criteria = {}
if searchTerm:
criteria['loops_title'] = searchTerm
if searchType:
if searchType.endswith('*'):
start = searchType[:-1]
end = start + '\x7f'
else:
start = end = searchType
criteria['loops_type'] = (start, end)
cat = zapi.getUtility(ICatalog)
result = cat.searchResults(loops_text=searchTerm)
result = cat.searchResults(**criteria)
else:
result = (list(self.loopsRoot.getConceptManager().values())
+ list(self.loopsRoot.getResourceManager().values()))

View file

@ -124,8 +124,8 @@
tal:attributes="value searchTerm" />
<span i18n:translate="">Type</span>
<select name="searchType">
<option value="*">Any</option>
<tal:types repeat="type view/targetTypes">
<option>Any</option>
<tal:types repeat="type view/targetTypesForSearch">
<option value=".loops/concepts/topic"
i18n:translate=""
tal:attributes="value type/token;

View file

@ -308,3 +308,12 @@ class IndexAttributes(object):
context = self.context
return ' '.join((zapi.getName(context), context.title,))
def title(self):
return self.text()
def type(self):
context = self.context
conceptType = context.conceptType
typeName = conceptType is None and 'unknown' or zapi.getName(conceptType)
return ':'.join(('loops:concept', typeName,))

View file

@ -460,7 +460,16 @@ class IIndexAttributes(Interface):
by an adapter.
"""
def title():
""" Return a text containing title and similar attributes to be
indexed by a full-text index.
"""
def text():
""" Return a text with all parts to be indexed by a full-text index.
"""
def type():
""" Return a string that identifies the type of the object.
"""

View file

@ -128,6 +128,13 @@ class IndexAttributes(object):
def text(self):
context = self.context
return ' '.join((zapi.getName(context), context.title,))
return ' '.join((zapi.getName(context), context.title, context.data)).strip()
def title(self):
context = self.context
return ' '.join((zapi.getName(context), context.title,)).strip()
def type(self):
context = self.context
return ':'.join(('loops:resource', context.__class__.__name__))

View file

@ -150,3 +150,11 @@ def getTargetTypes():
('loops.resource.Document', _(u'Document')),
('loops.resource.MediaAsset', _(u'Media Asset')),
)
def getTargetTypesForSearch():
# TODO: provide full list of concept types
return (('loops:concept:*', _(u'Any Concept')),
('loops:resource:Document', _(u'Document')),
('loops:resource:MediaAsset', _(u'Media Asset')),
)