All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Eggleton <paul.eggleton@linux.intel.com>
To: yocto@yoctoproject.org
Subject: [layerindex-web][PATCH 4/4] views: support querying class inheritance
Date: Wed, 16 Nov 2016 16:18:34 +1300	[thread overview]
Message-ID: <1479266314-8574-4-git-send-email-paul.eggleton@linux.intel.com> (raw)
In-Reply-To: <1479266314-8574-1-git-send-email-paul.eggleton@linux.intel.com>

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>
---
 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



      parent reply	other threads:[~2016-11-16  3:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-16  3:18 [layerindex-web][PATCH 1/4] admin: add an action to duplicate a branch Paul Eggleton
2016-11-16  3:18 ` [layerindex-web][PATCH 2/4] utils: fix error in runcmd() if printerr=False Paul Eggleton
2016-11-16  3:18 ` [layerindex-web][PATCH 3/4] Record and display update logs Paul Eggleton
2016-11-16  3:18 ` Paul Eggleton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1479266314-8574-4-git-send-email-paul.eggleton@linux.intel.com \
    --to=paul.eggleton@linux.intel.com \
    --cc=yocto@yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.