~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/search.py

  • Committer: Curtis Hovey
  • Date: 2013-08-20 22:05:56 UTC
  • mfrom: (358 charmworld)
  • mto: This revision was merged to the branch mainline in revision 359.
  • Revision ID: curtis@canonical.com-20130820220556-zhm7woolfb0hs81x
Merged tip.

Show diffs side-by-side

added added

removed removed

Lines of Context:
190
190
        charm_properties = dict(
191
191
            (name, {'type': 'string', 'index': 'not_analyzed'})
192
192
            for name in charm_exact_index)
 
193
 
 
194
        CHARM_TEXT_INDEX = (
 
195
            'summary',
 
196
            'description',
 
197
        )
 
198
        charm_properties.update(dict(
 
199
            (name, {'type': 'string'}) for name in CHARM_TEXT_INDEX))
 
200
 
 
201
        CHARM_INTEGER_INDEX = (
 
202
            'downloads',
 
203
            'downloads_in_past_30_days',
 
204
            'downloads_in_past_7_days',
 
205
            'downloads_in_past_half_year',
 
206
        )
 
207
        charm_properties.update(dict(
 
208
            (name, {'type': 'long'}) for name in CHARM_INTEGER_INDEX))
 
209
 
 
210
        charm_properties['date_created'] = {
 
211
            'type': 'date',
 
212
        }
 
213
        charm_properties['is_featured'] = {
 
214
            'type': 'boolean',
 
215
        }
 
216
        charm_properties['store_data'] = {
 
217
            'properties': {
 
218
                'errors': {'type': 'string'},
 
219
            }
 
220
        }
 
221
        # XXX Abel Deuring 2013-08-19 bug=1194907: The fields requires
 
222
        # and provides are user defined dictionaries. We can't specify
 
223
        # all possible keys. This partly reintroduces a large mapping;
 
224
        # the proper way to fix this is described in bug 1194907.
 
225
        charm_properties['requires'] = {
 
226
            'type': 'object',
 
227
            'dynamic': True,
 
228
        }
 
229
        charm_properties['provides'] = {
 
230
            'type': 'object',
 
231
            'dynamic': True,
 
232
        }
 
233
 
193
234
        charm_properties['config'] = {
194
235
            'properties': {
195
236
                'options': {
218
259
            for name in bundle_exact_index)
219
260
 
220
261
        with translate_error():
221
 
            for (name, properties) in ((CHARM, charm_properties),
222
 
                                       (BUNDLE, bundle_properties)):
 
262
            for (name, properties, dynamic) in (
 
263
                    (CHARM, charm_properties, False),
 
264
                    (BUNDLE, bundle_properties, True)):
223
265
                self._client.put_mapping(self.index_name, name, {
224
266
                    name: {
 
267
                        'type': 'object',
 
268
                        'dynamic': dynamic,
225
269
                        'properties': properties,
226
270
                    }
227
271
                })
645
689
    return new_index
646
690
 
647
691
 
648
 
def update(index_client):
 
692
def update(index_client, force_reindex=False):
649
693
    """Update the index to use the current mapping.
650
694
 
651
695
    If the index isn't present, a new index is created and aliased to it.
654
698
    """
655
699
    actual_client = index_client
656
700
    try:
657
 
        index_client.put_mapping()
 
701
        if force_reindex:
 
702
            actual_client = reindex(index_client)
 
703
        else:
 
704
            index_client.put_mapping()
658
705
    except IncompatibleMapping:
659
706
        actual_client = reindex(index_client)
660
707
    except IndexMissing: