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:
parent
57deb86205
commit
ffc3707094
9 changed files with 86 additions and 19 deletions
25
README.txt
25
README.txt
|
@ -183,14 +183,21 @@ predicates:
|
||||||
[(u'has type', '.loops/concepts/hasType'),
|
[(u'has type', '.loops/concepts/hasType'),
|
||||||
(u'subconcept', '.loops/concepts/standard')]
|
(u'subconcept', '.loops/concepts/standard')]
|
||||||
|
|
||||||
Searchable Text Adapter
|
Index attributes adapter
|
||||||
-----------------------
|
------------------------
|
||||||
|
|
||||||
>>> from loops.concept import IndexAttributes
|
>>> from loops.concept import IndexAttributes
|
||||||
>>> idx = IndexAttributes(cc2)
|
>>> idx = IndexAttributes(cc2)
|
||||||
>>> idx.text()
|
>>> idx.text()
|
||||||
u'cc2 Zope 3'
|
u'cc2 Zope 3'
|
||||||
|
|
||||||
|
>>> idx.title()
|
||||||
|
u'cc2 Zope 3'
|
||||||
|
|
||||||
|
>>> idx.type()
|
||||||
|
'loops:concept:unknown'
|
||||||
|
|
||||||
|
|
||||||
Resources and what they have to do with Concepts
|
Resources and what they have to do with Concepts
|
||||||
================================================
|
================================================
|
||||||
|
|
||||||
|
@ -259,6 +266,20 @@ below) via the getClients() method:
|
||||||
>>> conc[0] is cc1
|
>>> conc[0] is cc1
|
||||||
True
|
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
|
Views/Nodes: Menus, Menu Items, Listings, Pages, etc
|
||||||
====================================================
|
====================================================
|
||||||
|
|
|
@ -120,18 +120,17 @@ class ConceptView(BaseView):
|
||||||
if request.get('action') != 'search':
|
if request.get('action') != 'search':
|
||||||
return []
|
return []
|
||||||
searchTerm = request.get('searchTerm', None)
|
searchTerm = request.get('searchTerm', None)
|
||||||
|
searchType = request.get('searchType', None)
|
||||||
|
if searchTerm or searchType:
|
||||||
|
criteria = {}
|
||||||
if searchTerm:
|
if searchTerm:
|
||||||
|
criteria['loops_title'] = searchTerm
|
||||||
|
if searchType:
|
||||||
|
criteria['loops_type'] = (searchType)
|
||||||
cat = zapi.getUtility(ICatalog)
|
cat = zapi.getUtility(ICatalog)
|
||||||
result = cat.searchResults(loops_text=searchTerm)
|
result = cat.searchResults(**criteria)
|
||||||
else:
|
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]
|
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]
|
|
||||||
return self.viewIterator(result)
|
return self.viewIterator(result)
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
|
|
|
@ -37,7 +37,7 @@ from zope.security.proxy import removeSecurityProxy
|
||||||
|
|
||||||
from loops.interfaces import IConcept, IDocument, IMediaAsset
|
from loops.interfaces import IConcept, IDocument, IMediaAsset
|
||||||
from loops.resource import MediaAsset
|
from loops.resource import MediaAsset
|
||||||
from loops.target import getTargetTypes
|
from loops.target import getTargetTypes, getTargetTypesForSearch
|
||||||
from loops import util
|
from loops import util
|
||||||
from loops.browser.common import BaseView
|
from loops.browser.common import BaseView
|
||||||
from loops.browser.concept import ConceptView
|
from loops.browser.concept import ConceptView
|
||||||
|
@ -203,15 +203,29 @@ class ConfigureView(BaseView):
|
||||||
def targetTypes(self):
|
def targetTypes(self):
|
||||||
return util.KeywordVocabulary(getTargetTypes())
|
return util.KeywordVocabulary(getTargetTypes())
|
||||||
|
|
||||||
|
def targetTypesForSearch(self):
|
||||||
|
return util.KeywordVocabulary(getTargetTypesForSearch())
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def search(self):
|
def search(self):
|
||||||
request = self.request
|
request = self.request
|
||||||
if request.get('action') != 'search':
|
if request.get('action') != 'search':
|
||||||
return []
|
return []
|
||||||
searchTerm = request.get('searchTerm', None)
|
searchTerm = request.get('searchTerm', None)
|
||||||
|
searchType = request.get('searchType', None)
|
||||||
|
if searchTerm or searchType:
|
||||||
|
criteria = {}
|
||||||
if searchTerm:
|
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)
|
cat = zapi.getUtility(ICatalog)
|
||||||
result = cat.searchResults(loops_text=searchTerm)
|
result = cat.searchResults(**criteria)
|
||||||
else:
|
else:
|
||||||
result = (list(self.loopsRoot.getConceptManager().values())
|
result = (list(self.loopsRoot.getConceptManager().values())
|
||||||
+ list(self.loopsRoot.getResourceManager().values()))
|
+ list(self.loopsRoot.getResourceManager().values()))
|
||||||
|
|
|
@ -124,8 +124,8 @@
|
||||||
tal:attributes="value searchTerm" />
|
tal:attributes="value searchTerm" />
|
||||||
<span i18n:translate="">Type</span>
|
<span i18n:translate="">Type</span>
|
||||||
<select name="searchType">
|
<select name="searchType">
|
||||||
<option value="*">Any</option>
|
<option>Any</option>
|
||||||
<tal:types repeat="type view/targetTypes">
|
<tal:types repeat="type view/targetTypesForSearch">
|
||||||
<option value=".loops/concepts/topic"
|
<option value=".loops/concepts/topic"
|
||||||
i18n:translate=""
|
i18n:translate=""
|
||||||
tal:attributes="value type/token;
|
tal:attributes="value type/token;
|
||||||
|
|
|
@ -308,3 +308,12 @@ class IndexAttributes(object):
|
||||||
context = self.context
|
context = self.context
|
||||||
return ' '.join((zapi.getName(context), context.title,))
|
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,))
|
||||||
|
|
||||||
|
|
|
@ -460,7 +460,16 @@ class IIndexAttributes(Interface):
|
||||||
by an adapter.
|
by an adapter.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def title():
|
||||||
|
""" Return a text containing title and similar attributes to be
|
||||||
|
indexed by a full-text index.
|
||||||
|
"""
|
||||||
|
|
||||||
def text():
|
def text():
|
||||||
""" Return a text with all parts to be indexed by a full-text index.
|
""" 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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,13 @@ class IndexAttributes(object):
|
||||||
|
|
||||||
def text(self):
|
def text(self):
|
||||||
context = self.context
|
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__))
|
||||||
|
|
||||||
|
|
|
@ -150,3 +150,11 @@ def getTargetTypes():
|
||||||
('loops.resource.Document', _(u'Document')),
|
('loops.resource.Document', _(u'Document')),
|
||||||
('loops.resource.MediaAsset', _(u'Media Asset')),
|
('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')),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue