summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-11-16 16:08:37 +1300
committerPaul Eggleton <paul.eggleton@linux.intel.com>2016-11-16 16:08:37 +1300
commita988b6ba085ca93832a16eb464d7992715e2edab (patch)
treedb7aa742f291132ce1ba2193205ca5237749e32a
parent43203c578ce856377751f9db7a0bf020ad8b0c5d (diff)
downloadopenembedded-core-contrib-a988b6ba085ca93832a16eb464d7992715e2edab.tar.gz
views: support querying class inheritance
It's a little crude and certainly not optimal performance-wise, but we can support querying for recipes that inherit a particular class without too much trouble. This allows you to add "inherits:cmake" to the query and have it return only recipes that inherit the cmake class. You can use more than one inherits: item to filter down to recipes that inherit all of the specified classes. Note: this does not otherwise change the behaviour of specifying multiple words - all of the words other than those that start with "inherits:" are treated as part of a single phrase that will be searched for - not separate keywords. Fixes [YOCTO #9879]. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
-rw-r--r--layerindex/views.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/layerindex/views.py b/layerindex/views.py
index 0933bf0e99..ae0220b762 100644
--- a/layerindex/views.py
+++ b/layerindex/views.py
@@ -376,6 +376,22 @@ class RecipeSearchView(ListView):
_check_url_branch(self.kwargs)
query_string = self.request.GET.get('q', '')
init_qs = Recipe.objects.filter(layerbranch__branch__name=self.kwargs['branch'])
+
+ # Support slightly crude search on inherits field
+ query_items = query_string.split()
+ inherits = []
+ query_terms = []
+ for item in query_items:
+ if item.startswith('inherits:'):
+ inherits.append(item.split(':')[1])
+ else:
+ query_terms.append(item)
+ if inherits:
+ # FIXME This is a bit ugly, perhaps we should consider having this as a one-many relationship instead
+ for inherit in inherits:
+ init_qs = init_qs.filter(Q(inherits=inherit) | Q(inherits__startswith=inherit + ' ') | Q(inherits__endswith=' ' + inherit) | Q(inherits__contains=' %s ' % inherit))
+ query_string = ' '.join(query_terms)
+
if query_string.strip():
order_by = ('pn', 'layerbranch__layer')