Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

test are passing

  • Loading branch information...
commit 0cf40987328a2c21a8a65a524d3dff599be5ecb5 1 parent cf152b8
Jens W. Klein authored June 29, 2012
6  src/souper/soup.py
@@ -106,16 +106,14 @@ def lazy(self, queryobject, sort_index=None, limit=None, sort_type=None,
106 106
 
107 107
     def clear(self):
108 108
         self.storage.__init__()
109  
-        request = self.context.REQUEST
110  
-        cachekey = self._cachekey
111  
-        del request[cachekey]
112 109
         self.rebuild()
113 110
 
114 111
     def rebuild(self):
115 112
         """trashed the existing catalog and creates a new one using the
116 113
         named utility ICatalogFactory.
117 114
         """
118  
-        self.storage.catalog = getUtility(ICatalogFactory, name=self.id)()
  115
+        self.storage.catalog = getUtility(ICatalogFactory,
  116
+                                          name=self.soup_name)()
119 117
         self.reindex()
120 118
 
121 119
     def reindex(self, records=None):
65  src/souper/soup.rst
Source Rendered
@@ -67,7 +67,7 @@ soup. It must be registered as utility with desired soup id.
67 67
     ...         catalog = Catalog()
68 68
     ...         userindexer = NodeAttributeIndexer('user')
69 69
     ...         catalog[u'user'] = CatalogFieldIndex(userindexer)
70  
-    ...         textindexer = NodeAttributeIndexer('user')
  70
+    ...         textindexer = NodeAttributeIndexer('text')
71 71
     ...         catalog[u'text'] = CatalogTextIndex(textindexer)
72 72
     ...         keywordindexer = NodeAttributeIndexer('keywords')
73 73
     ...         catalog[u'keywords'] = CatalogKeywordIndex(keywordindexer)
@@ -124,7 +124,7 @@ Add some more Records::
124 124
     >>> record.attrs['text'] = u'foo x y'
125 125
     >>> record.attrs['keywords'] = [u'1', u'4', u'5']
126 126
     >>> rid = soup.add(record)    
127  
-    >>> u1records = [r for r in soup.query(user=2*('user1',))]
  127
+    >>> u1records = [r for r in soup.query(Eq('user', 'user1'))]
128 128
     >>> u1records
129 129
     [<Record object 'None' at ...>, <Record object 'None' at ...>]
130 130
 
@@ -134,36 +134,38 @@ Change user attribute of one record::
134 134
 
135 135
 The query still returns the old result. The Record must be reindexed::
136 136
 
137  
-    >>> len(list(soup.query(user=2*('user1',))))
  137
+    >>> len(list(soup.query(Eq('user', 'user1'))))
138 138
     2
139 139
 
140 140
     >>> soup.reindex([u1records[0]])
141  
-    >>> len(list(soup.query(user=2*('user1',))))
  141
+    >>> len(list(soup.query(Eq('user', 'user1'))))
142 142
     1
143 143
 
144  
-    >>> len(list(soup.query(user=2*('user2',))))
  144
+    >>> len(list(soup.query(Eq('user', 'user2'))))
145 145
     2
146 146
 
147 147
 Check Text index::
148 148
 
149  
-    >>> len(list(soup.query(text='foo')))
  149
+    >>> from repoze.catalog.query import Contains 
  150
+    >>> len(list(soup.query(Contains('text', 'foo'))))
150 151
     3
151 152
 
152  
-    >>> len(list(soup.query(text='bar')))
  153
+    >>> len(list(soup.query(Contains('text', 'bar'))))
153 154
     2
154 155
 
155  
-    >>> len(list(soup.query(text='x')))
  156
+    >>> len(list(soup.query(Contains('text', 'x'))))
156 157
     1
157 158
 
158  
-    >>> len(list(soup.query(text='fo')))
  159
+    >>> len(list(soup.query(Contains('text', 'fo'))))
159 160
     0
160 161
 
161 162
 Check keyword index::
162 163
 
163  
-    >>> len(list(soup.query(keywords=['1'])))
  164
+    >>> from repoze.catalog.query import Any 
  165
+    >>> len(list(soup.query(Any('keywords', ['1']))))
164 166
     3
165 167
     
166  
-    >>> len(list(soup.query(keywords=[u'ü'])))
  168
+    >>> len(list(soup.query(Any('keywords', [u'ü']))))
167 169
     1
168 170
 
169 171
 You can reindex all records in soup at once::
@@ -175,7 +177,7 @@ You can reindex all records in soup at once::
175 177
 
176 178
     >>> all[-1].attrs['user'] = 'user3'
177 179
     >>> soup.reindex()
178  
-    >>> len(list(soup.query(user=2*('user3',))))
  180
+    >>> len(list(soup.query(Eq('user', 'user3'))))
179 181
     1
180 182
     
181 183
 Rebuild
@@ -185,21 +187,30 @@ You can also rebuild the catalog. In this case the catalog factory is called
185 187
 again and the new catalog is used. Lets modify catalog of our catalog factory.
186 188
 Never do this in production evironments::
187 189
 
188  
-    >>> from collective.soup.interfaces import INodeAttributeIndexer
189  
-    >>> from zope.catalog.field import FieldIndex
190  
-    >>> catalogfactory = getUtility(ICatalogFactory, name='mysoup')
191  
-    >>> catalogfactory.catalog[u'name'] = FieldIndex(field_name='name',
192  
-    ...                                   interface=INodeAttributeIndexer)
193  
-    >>> catalogfactory.catalog[u'name']
194  
-    <zope.catalog.field.FieldIndex object at ...>
  190
+    >>> @implementer(ICatalogFactory)
  191
+    ... class MySoupCatalogFactoryNew(object):
  192
+    ...
  193
+    ...     def __call__(self):
  194
+    ...         catalog = Catalog()
  195
+    ...         userindexer = NodeAttributeIndexer('user')
  196
+    ...         catalog[u'user'] = CatalogFieldIndex(userindexer)
  197
+    ...         textindexer = NodeAttributeIndexer('text')
  198
+    ...         catalog[u'text'] = CatalogTextIndex(textindexer)
  199
+    ...         keywordindexer = NodeAttributeIndexer('keywords')
  200
+    ...         catalog[u'keywords'] = CatalogKeywordIndex(keywordindexer)
  201
+    ...         nameindexer = NodeAttributeIndexer('name')
  202
+    ...         catalog[u'name'] = CatalogFieldIndex(nameindexer)
  203
+    ...         return catalog
  204
+    
  205
+    >>> provideUtility(MySoupCatalogFactoryNew(), name="mysoup")
195 206
 
196 207
 Set name attribute on some record data, reindex soup and check results::
197 208
 
198 209
     >>> all[0].attrs['name'] = 'name'
199 210
     >>> all[1].attrs['name'] = 'name'
200 211
     >>> all[2].attrs['name'] = 'name'
201  
-    >>> soup.reindex()
202  
-    >>> len(list(soup.query(name=2*('name',))))
  212
+    >>> soup.rebuild()
  213
+    >>> len(list(soup.query(Eq('name', 'name'))))
203 214
     3
204 215
 
205 216
 Delete
@@ -208,7 +219,7 @@ Delete
208 219
 Delete records::
209 220
 
210 221
     >>> del soup[all[0]]
211  
-    >>> len(list(soup.query(name=2*('name',))))
  222
+    >>> len(list(soup.query(Eq('name', 'name'))))
212 223
     2
213 224
     
214 225
 LazyRecords
@@ -217,16 +228,16 @@ LazyRecords
217 228
 For huge expected results we can query LazyRecords. They return the real record
218 229
 on call::
219 230
 
220  
-    >>> lazy = [l for l in soup.lazy(name=2*('name',))]
  231
+    >>> lazy = [l for l in soup.lazy(Eq('name', 'name'))]
221 232
     >>> lazy
222  
-    [<collective.soup.soup.LazyRecord object at ...>,
223  
-    <collective.soup.soup.LazyRecord object at ...>]
  233
+    [<souper.soup.LazyRecord object at ...>,
  234
+    <souper.soup.LazyRecord object at ...>]
224 235
 
225 236
     >>> lazy[0]()
226 237
     <Record object 'None' at ...>
227 238
 
228  
-    >>> soup = getSoup(site, u'mysoup')
229  
-    >>> len(list(soup.query(name=2*('name',))))
  239
+    >>> soup = get_soup(u'mysoup', context)
  240
+    >>> len(list(soup.query(Eq('name', 'name'))))
230 241
     2
231 242
 
232 243
 Clear soup

0 notes on commit 0cf4098

Please sign in to comment.
Something went wrong with that request. Please try again.