[yocto] [layerindex-web][PATCH 4/4] views: support querying class inheritance
Paul Eggleton
paul.eggleton at linux.intel.com
Tue Nov 15 19:18:34 PST 2016
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 at linux.intel.com>
---
layerindex/views.py | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/layerindex/views.py b/layerindex/views.py
index 0933bf0..ae0220b 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')
--
2.5.5
More information about the yocto
mailing list