add identifier index, is used for 'TypeInstances' property
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2884 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									abd3bb6dfb
								
							
						
					
					
						commit
						3dc2a3b24d
					
				
					 6 changed files with 74 additions and 10 deletions
				
			
		
							
								
								
									
										49
									
								
								common.py
									
										
									
									
									
								
							
							
						
						
									
										49
									
								
								common.py
									
										
									
									
									
								
							|  | @ -219,9 +219,11 @@ class NameChooser(BaseNameChooser): | ||||||
|         '\xdc': 'Ue', '\xfc': 'ue', '\xdf': 'ss'} |         '\xdc': 'Ue', '\xfc': 'ue', '\xdf': 'ss'} | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # virtual attributes | # virtual attributes/properties | ||||||
| 
 | 
 | ||||||
| class ContainerAttribute(object): | #class ContainerAttribute(object): | ||||||
|  | #class ContainedCollection(object): | ||||||
|  | class TypeInstances(object): | ||||||
|     """ Use objects within a ConceptManager object for a collection attribute. |     """ Use objects within a ConceptManager object for a collection attribute. | ||||||
|     """ |     """ | ||||||
| 
 | 
 | ||||||
|  | @ -237,6 +239,14 @@ class ContainerAttribute(object): | ||||||
|     def typeConcept(self): |     def typeConcept(self): | ||||||
|         return self.context[self.typeName] |         return self.context[self.typeName] | ||||||
| 
 | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def typeToken(self): | ||||||
|  |         return 'loops:concept:' + self.typeName | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def typePredicate(self): | ||||||
|  |         return self.context.getTypePredicate() | ||||||
|  | 
 | ||||||
|     def create(self, id, **kw): |     def create(self, id, **kw): | ||||||
|         from loops.concept import Concept |         from loops.concept import Concept | ||||||
|         from loops.setup import addAndConfigureObject |         from loops.setup import addAndConfigureObject | ||||||
|  | @ -250,11 +260,17 @@ class ContainerAttribute(object): | ||||||
|         del self.context[self.prefix + id] |         del self.context[self.prefix + id] | ||||||
| 
 | 
 | ||||||
|     def get(self, id, default=None, langInfo=None): |     def get(self, id, default=None, langInfo=None): | ||||||
|         return adapted(self.context.get(self.prefix + id, default), |         #return adapted(self.context.get(self.prefix + id, default), | ||||||
|                        langInfo=self.langInfo) |         #               langInfo=self.langInfo) | ||||||
|  |         from loops.expert import query | ||||||
|  |         result = (query.Identifier(id) & query.Type(self.typeToken)).apply() | ||||||
|  |         for obj in query.getObjects(result): | ||||||
|  |             return adapted(obj, langInfo=self.langInfo) | ||||||
|  |         else: | ||||||
|  |             return default | ||||||
| 
 | 
 | ||||||
|     def __iter__(self): |     def __iter__(self): | ||||||
|         for c in self.typeConcept.getChildren([self.context.getTypePredicate()]): |         for c in self.typeConcept.getChildren([self.typePredicate]): | ||||||
|             yield adapted(c, langInfo=self.langInfo) |             yield adapted(c, langInfo=self.langInfo) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -318,6 +334,29 @@ class ChildRelationSet(RelationSet): | ||||||
|             yield adapted(c, langInfo=self.langInfo) |             yield adapted(c, langInfo=self.langInfo) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | # property descriptors | ||||||
|  | 
 | ||||||
|  | class RelationSetProperty(object): | ||||||
|  | 
 | ||||||
|  |     def __init__(self, predicateName): | ||||||
|  |         self.predicateName = predicateName | ||||||
|  | 
 | ||||||
|  |     def __get__(self, inst, class_=None): | ||||||
|  |         if inst is None: | ||||||
|  |             return self | ||||||
|  |         return self.factory(inst, self.predicateName) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class ParentRelationSetProperty(RelationSetProperty): | ||||||
|  | 
 | ||||||
|  |     factory = ParentRelationSet | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class ChildRelationSetProperty(RelationSetProperty): | ||||||
|  | 
 | ||||||
|  |     factory = ChildRelationSet | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| # caching (TBD) | # caching (TBD) | ||||||
| 
 | 
 | ||||||
| def cached(obj): | def cached(obj): | ||||||
|  |  | ||||||
							
								
								
									
										17
									
								
								concept.py
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								concept.py
									
										
									
									
									
								
							|  | @ -397,13 +397,18 @@ class IndexAttributes(object): | ||||||
|     def __init__(self, context): |     def __init__(self, context): | ||||||
|         self.context = context |         self.context = context | ||||||
| 
 | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def adapted(self): | ||||||
|  |         return adapted(self.context) | ||||||
|  | 
 | ||||||
|     def text(self): |     def text(self): | ||||||
|         ctx = self.context |         #ctx = self.context | ||||||
|         #return ' '.join((getName(ctx), ctx.title,)) |         #return ' '.join((getName(ctx), ctx.title,)) | ||||||
|         description = ctx.description |         description = self.context.description | ||||||
|         if isinstance(description, I18NValue): |         if isinstance(description, I18NValue): | ||||||
|             description = ' '.join(description.values()) |             description = ' '.join(description.values()) | ||||||
|         actx = adapted(ctx) |         #actx = adapted(ctx) | ||||||
|  |         actx = self.adapted | ||||||
|         indexAttrs = getattr(actx, '_textIndexAttributes', ()) |         indexAttrs = getattr(actx, '_textIndexAttributes', ()) | ||||||
|         #return ' '.join([getName(ctx), ctx.title, ctx.description] + |         #return ' '.join([getName(ctx), ctx.title, ctx.description] + | ||||||
|         return ' '.join([self.title(), description] + |         return ' '.join([self.title(), description] + | ||||||
|  | @ -431,6 +436,12 @@ class IndexAttributes(object): | ||||||
|                 creators.append(principal.title) |                 creators.append(principal.title) | ||||||
|         return creators |         return creators | ||||||
| 
 | 
 | ||||||
|  |     def identifier(self): | ||||||
|  |         id = getattr(self.adapted, 'identifier', None) | ||||||
|  |         if id is None: | ||||||
|  |             return getName(self) | ||||||
|  |         return id | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| # events | # events | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -41,6 +41,7 @@ from loops import util | ||||||
| titleIndex = ('', 'loops_title') | titleIndex = ('', 'loops_title') | ||||||
| textIndex = ('', 'loops_text') | textIndex = ('', 'loops_text') | ||||||
| typeIndex = ('', 'loops_type') | typeIndex = ('', 'loops_type') | ||||||
|  | identifierIndex = ('', 'loops_identifier') | ||||||
| stateIndex = ('', 'loops_state') | stateIndex = ('', 'loops_state') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -54,6 +55,10 @@ def Title(value): | ||||||
| def Text(value): | def Text(value): | ||||||
|     return BaseText(textIndex, value) |     return BaseText(textIndex, value) | ||||||
| 
 | 
 | ||||||
|  | @implementer(IQuery) | ||||||
|  | def Identifier(value): | ||||||
|  |     return Eq(identifierIndex, value) | ||||||
|  | 
 | ||||||
| @implementer(IQuery) | @implementer(IQuery) | ||||||
| def Type(value): | def Type(value): | ||||||
|     if value.endswith('*'): |     if value.endswith('*'): | ||||||
|  |  | ||||||
|  | @ -586,13 +586,13 @@ class IConceptRelation(IDyadicRelation): | ||||||
| # interfaces for catalog indexes | # interfaces for catalog indexes | ||||||
| 
 | 
 | ||||||
| class IIndexAttributes(Interface): | class IIndexAttributes(Interface): | ||||||
|     """ Attributes odr methods providing index values. Typically provided |     """ Attributes or methods providing index values. Typically provided | ||||||
|         by an adapter. |         by an adapter. | ||||||
|     """ |     """ | ||||||
| 
 | 
 | ||||||
|     def title(): |     def title(): | ||||||
|         """ Return a text containing title and similar attributes to be |         """ Return a text containing title and similar attributes to be | ||||||
|             indexed by a full-text index. |             indexed by the title index. | ||||||
|         """ |         """ | ||||||
| 
 | 
 | ||||||
|     def text(): |     def text(): | ||||||
|  | @ -603,6 +603,11 @@ class IIndexAttributes(Interface): | ||||||
|         """ Return a string that identifies the type of the object. |         """ Return a string that identifies the type of the object. | ||||||
|         """ |         """ | ||||||
| 
 | 
 | ||||||
|  |     def identifier(): | ||||||
|  |         """ Returns a value that may be used for identifying an object within | ||||||
|  |             a restricted range, e.g. the instances of a type. | ||||||
|  |         """ | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| # types stuff | # types stuff | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -535,6 +535,9 @@ class IndexAttributes(object): | ||||||
|                 creators.append(principal.title) |                 creators.append(principal.title) | ||||||
|         return creators |         return creators | ||||||
| 
 | 
 | ||||||
|  |     def identifier(self): | ||||||
|  |         return getName(self) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class ResourceTypeSourceList(object): | class ResourceTypeSourceList(object): | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -157,6 +157,7 @@ class TestSite(object): | ||||||
|         component.provideUtility(catalog, ICatalog) |         component.provideUtility(catalog, ICatalog) | ||||||
|         catalog['loops_title'] = TextIndex('title', IIndexAttributes, True) |         catalog['loops_title'] = TextIndex('title', IIndexAttributes, True) | ||||||
|         catalog['loops_text'] = TextIndex('text', IIndexAttributes, True) |         catalog['loops_text'] = TextIndex('text', IIndexAttributes, True) | ||||||
|  |         catalog['loops_identifier'] = FieldIndex('identifier', IIndexAttributes, True) | ||||||
|         catalog['loops_type'] = FieldIndex('tokenForSearch', IType, False) |         catalog['loops_type'] = FieldIndex('tokenForSearch', IType, False) | ||||||
|         catalog['loops_state'] = KeywordIndex('tokens', IStatefulIndexInfo, False) |         catalog['loops_state'] = KeywordIndex('tokens', IStatefulIndexInfo, False) | ||||||
|         component.provideAdapter(ConceptIndexAttributes) |         component.provideAdapter(ConceptIndexAttributes) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm