~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/search.py

[r=sinzui][bug=1208477][author=abentley] Remove doctype attribute.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
# selecting any fields that may be integers, such as config.options.*.default,
25
25
# provides.*.interface.limit, or changes.revno.  Selecting an integer field
26
26
# causes a SearchParseException/NumberFormatException.
27
 
charm_exact_fields = [
28
 
    'owner',
29
 
    'series',
30
 
    'provides.*.interface',
31
 
    'requires.*.interface',
32
 
]
33
 
charm_free_text_fields = {
 
27
exact_fields = ['owner', 'series', 'provides.*.interface',
 
28
                'requires.*.interface']
 
29
free_text_fields = {
34
30
    'name': 10,
35
31
    'summary': 5,
36
32
    'description': 3,
39
35
    'services': None,
40
36
}
41
37
 
42
 
bundle_exact_fields = [
43
 
    'owner',
44
 
    'data.series',
45
 
]
46
 
bundle_free_text_fields = {
47
 
    'name': 10,
48
 
    'basket': 5,
49
 
    'description': 3,
50
 
    'title': None,
51
 
    'data.services': None,
52
 
}
53
38
 
54
39
CHARM = 'charm'
55
40
BUNDLE = 'bundle'
270
255
        if autocomplete:
271
256
            return {'prefix': {'name': text}}
272
257
 
273
 
        charm_fields = [field + ('' if boost is None else '^%d' % boost)
274
 
                        for field, boost in charm_free_text_fields.items()]
275
 
        charm_fields.extend(charm_exact_fields)
276
 
 
277
 
        bundle_fields = [field + ('' if boost is None else '^%d' % boost)
278
 
                         for field, boost in bundle_free_text_fields.items()]
279
 
        bundle_fields.extend(bundle_exact_fields)
280
 
 
 
258
        fields = [field + ('' if boost is None else '^%d' % boost)
 
259
                  for field, boost in free_text_fields.items()]
 
260
        fields.extend(exact_fields)
281
261
        if text != '':
282
262
            charm_dsl = {'filtered': {
283
263
                'query': {
284
264
                    'query_string': {
285
265
                        'query': text,
286
 
                        'fields': charm_fields,
 
266
                        'fields': fields,
287
267
                    }},
288
268
                'filter': {'type': {'value': CHARM}}
289
269
            }}
291
271
                'query': {
292
272
                    'query_string': {
293
273
                        'query': text,
294
 
                        'fields': bundle_fields,
 
274
                        'fields': fields,
295
275
                    }},
296
276
                'filter': {'type': {'value': BUNDLE}}
297
277
            }}
361
341
        result = self._client.get(self.index_name, doctype, id_)
362
342
        return result['_source']
363
343
 
364
 
    def get(self, charm_id, doctype=CHARM):
 
344
    def get(self, charm_id):
365
345
        try:
366
 
            return self._get_item(charm_id, doctype)
 
346
            return self._get_item(charm_id, CHARM)
367
347
        except ElasticHttpNotFoundError:
368
348
            return None
369
349
 
554
534
            copy.delete_index()
555
535
            raise
556
536
 
557
 
    def create_replacement(self, name=None, charms=None, bundles=None):
 
537
    def create_replacement(self, name=None, charms=None):
558
538
        """Create a replacement for this index.
559
539
 
560
540
        The mapping will not be this index's mapping, it will be the current
569
549
        with self.replacement(name) as copy:
570
550
            if charms is None:
571
551
                try:
572
 
                    charms = self.api_search(valid_only=False, doctype=CHARM)
 
552
                    charms = self.api_search(valid_only=False)
573
553
                except IndexMissing:
574
554
                    charms = []
575
555
            copy.index_charms(charms)
576
 
 
577
 
            if bundles is None:
578
 
                try:
579
 
                    bundles = self.api_search(valid_only=False, doctype=BUNDLE)
580
 
                except IndexMissing:
581
 
                    bundles = []
582
 
            copy.index_bundles(bundles)
583
556
            return copy
584
557
 
585
558