~bac/charmworld/tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/search.py

  • Committer: Tarmac
  • Author(s): Brad Crittenden
  • Date: 2014-07-16 16:39:51 UTC
  • mfrom: (515.1.1 ngram-inquiry)
  • Revision ID: tarmac-20140716163951-hunwr56yizg012h5
Make ngram searches work.

After the ngram search was deployed it was discovered to only work if 1) using
the API and 2) had autocomplete=true.

Inspecting the code showed the intent for ngram to be used in other
situations, and there was not documented rationale for only using it when
doing autocomplete.

The problem was simply in the query for non-autocomplete the field for the
ngrams was prefixed with 'data.' when it should not have been.

The ngrams fields were moved out of the charm and bundle fields and passed as
separate fields, treated like 'provides' and 'requires', to avoid the
prefixing.

As a result of this change, the search on the manage.jujucharms.com page now
uses ngrams too.

https://codereview.appspot.com/117810044/

R=makyo. Fixes: https://bugs.launchpad.net/bugs/1220909.

Approved by Juju Gui Bot, Matthew Scott.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
]
33
33
charm_free_text_fields = {
34
34
    'name': 10,
35
 
    'ngrams': None,
36
35
    'summary': 5,
37
36
    'description': 3,
38
37
    'config.options.description': None,
46
45
]
47
46
bundle_free_text_fields = {
48
47
    'name': 10,
49
 
    'ngrams': None,
50
48
    'basket_name': 5,
51
49
    'description': 3,
52
50
    'title': None,
353
351
                "fields": {
354
352
                    "ngrams": {
355
353
                        "type": "string",
356
 
                        "analyzer": "n3_20grams"
 
354
                        "analyzer": "n3_20grams",
357
355
                    },
358
356
                    "name": {
359
357
                        "type": "string",
490
488
 
491
489
            charm_dsl = {'filtered': {
492
490
                'query': make_query(
493
 
                    charm_fields, ['requires.*', 'provides.*']),
494
 
                'filter': {'type': {'value': CHARM}}
 
491
                    charm_fields, ['ngrams', 'requires.*', 'provides.*']),
 
492
                'filter': {'type': {'value': CHARM}},
495
493
            }}
496
494
            bundle_dsl = {'filtered': {
497
 
                'query': make_query(bundle_fields),
498
 
                'filter': {'type': {'value': BUNDLE}}
 
495
                'query': make_query(
 
496
                    bundle_fields, ['ngrams']),
 
497
                'filter': {'type': {'value': BUNDLE}},
499
498
            }}
500
499
            # Union the bundle_dsl and charm_dsl results
501
500
            dsl = {'bool': {'should': [bundle_dsl, charm_dsl]}}