Skip to contentSkip to conversation

views: support querying by layer name

PATCH Superseded Jose Lamego 2 participants 5 messages Apr 3, 2017 – Jun 15, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 views: support querying by layer name

This change supports querying recipes that belong to a specific layer by using the prefix "layer:" + the desired layer name, for example:
"layer: openembedded-core" and this string can be used by itself or combined with other supported options.

[YOCTO #6618]

---
 layerindex/views.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
layerindex/views.py +12 -1
index 65a536a..5b66892 100644
@@ -383,13 +383,16 @@ class RecipeSearchView(ListView):
         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
+        # Support slightly crude search on inherits/layer fields
         query_items = query_string.split()
         inherits = []
+        layers = []
         query_terms = []
         for item in query_items:
             if item.startswith('inherits:'):
                 inherits.append(item.split(':')[1])
+            elif item.startswith('layer:'):
+                layers.append(item.split(':')[1])
             else:
                 query_terms.append(item)
         if inherits:
@@ -397,6 +400,14 @@ class RecipeSearchView(ListView):
             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 layers:
+            for layer in layers:
+                init_qs = init_qs.filter(
+                    Q(layerbranch__layer__name=layer) |
+                    Q(layerbranch__layer__name__startswith=layer + ' ') |
+                    Q(layerbranch__layer__name__endswith=' ' + layer) |
+                    Q(layerbranch__layer__name__contains=' %s ' % layer))
+            query_string = ' '.join(query_terms)
 
         if query_string.strip():
             order_by = ('pn', 'layerbranch__layer')
Signature · 1 line
2.7.4
#1 lore raw

Hi Jose,

Sorry for the extreme delay reviewing this.

Quoted 17 lines · NZST Jose Lamego

This change supports querying recipes that belong to a specific layer by using the prefix "layer:" + the desired layer name, for example:
"layer: openembedded-core" and this string can be used by itself or combined with other supported options.

[YOCTO #6618]

---
 layerindex/views.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
layerindex/views.py +0 -0
index 65a536a..5b66892 100644

layerindex/views.py class RecipeSearchView(ListView): · line 384

Quoted 2 lines
layerindex/views.py +0 -0
@@ -383,13 +383,16 @@ class RecipeSearchView(ListView):
         query_string = self.request.GET.get('q', '')
         init_qs = 

Recipe.objects.filter(layerbranch__branch__name=self.kwargs['branch'])

Quoted 16 lines
layerindex/views.py +4 -1
-        # Support slightly crude search on inherits field
+        # Support slightly crude search on inherits/layer fields
         query_items = query_string.split()
         inherits = []
+        layers = []
         query_terms = []
         for item in query_items:
             if item.startswith('inherits:'):
                 inherits.append(item.split(':')[1])
+            elif item.startswith('layer:'):
+                layers.append(item.split(':')[1])
             else:
                 query_terms.append(item)
         if inherits:

layerindex/views.py class RecipeSearchView(ListView): · line 401

Quoted 2 lines
layerindex/views.py +0 -0
@@ -397,6 +400,14 @@ class RecipeSearchView(ListView):
             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))

layerindex/views.py class RecipeSearchView(ListView): · line 410

Quoted 9 lines
layerindex/views.py +8 -0
             query_string = ' '.join(query_terms)
+        if layers:
+            for layer in layers:
+                init_qs = init_qs.filter(
+                    Q(layerbranch__layer__name=layer) |
+                    Q(layerbranch__layer__name__startswith=layer + ' ') |
+                    Q(layerbranch__layer__name__endswith=' ' + layer) |
+                    Q(layerbranch__layer__name__contains=' %s ' % layer))
+            query_string = ' '.join(query_terms)

Could we instead determine which layers match the query (i.e. the IDs), and then do an layerbranch__layer__in (or layerbranch__layer__id__in, not sure which)? That way we can also return a specific message if no layers match the query. I'm not sure we really need the fuzzy matches either - just exact name match.

Cheers,
Paul

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre
#2 lore raw

PATCH v2 1/1 layerindex/views: support querying by layer name

In reply to Jose Lamego

This change supports querying recipes that belong to a specific layer by using the prefix "layer:" + the desired layer name, for example:
"layer: openembedded-core" and this string can be used by itself or combined with other supported options.

A descriptive error message is displayed when the query string has an unexpected formatting or a non-valid layer name is searched.

[YOCTO #6618]

---
 layerindex/views.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
layerindex/views.py +16 -1
index 65a536a..3eac3ac 100644
@@ -390,13 +390,28 @@ class RecipeSearchView(ListView):
         for item in query_items:
             if item.startswith('inherits:'):
                 inherits.append(item.split(':')[1])
+            # support searches by layer name
+            elif item.startswith('layer:'):
+                query_layername = item.split(':')[1].strip().lower()
+                if not query_layername:
+                    messages.add_message(self.request, messages.ERROR, 'The \
+layer name is expected to follow the \"layer:\" prefix without any spaces.')
+                query_layer = LayerBranch.objects.filter(
+                    layer__name=query_layername)
+                if query_layer:
+                    init_qs = init_qs.filter(
+                        layerbranch__layer__id=query_layer[0].id)
+                else:
+                    messages.add_message(self.request, messages.ERROR,
+                                         'No layer \"%s\" was found.'
+                                         % query_layername)
             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)
+        query_string = ' '.join(query_terms)
 
         if query_string.strip():
             order_by = ('pn', 'layerbranch__layer')
Signature · 1 line
2.7.4
#3 lore raw

Re: [layerindex-web][PATCH v2] layerindex/views: support querying by layer name

ping

Quoted 50 lines · Jose Lamego

This change supports querying recipes that belong to a specific layer by using the prefix "layer:" + the desired layer name, for example:
"layer: openembedded-core" and this string can be used by itself or combined with other supported options.

A descriptive error message is displayed when the query string has an unexpected formatting or a non-valid layer name is searched.

[YOCTO #6618]

---
 layerindex/views.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
layerindex/views.py +16 -1
index 65a536a..3eac3ac 100644
@@ -390,13 +390,28 @@ class RecipeSearchView(ListView):
         for item in query_items:
             if item.startswith('inherits:'):
                 inherits.append(item.split(':')[1])
+            # support searches by layer name
+            elif item.startswith('layer:'):
+                query_layername = item.split(':')[1].strip().lower()
+                if not query_layername:
+                    messages.add_message(self.request, messages.ERROR, 'The \
+layer name is expected to follow the \"layer:\" prefix without any spaces.')
+                query_layer = LayerBranch.objects.filter(
+                    layer__name=query_layername)
+                if query_layer:
+                    init_qs = init_qs.filter(
+                        layerbranch__layer__id=query_layer[0].id)
+                else:
+                    messages.add_message(self.request, messages.ERROR,
+                                         'No layer \"%s\" was found.'
+                                         % query_layername)
             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)
+        query_string = ' '.join(query_terms)
 
         if query_string.strip():
             order_by = ('pn', 'layerbranch__layer')
Signature · 1 line
Jose Lamego | OTC Embedded Platforms & Tools | GDC
#4 lore raw

Re: [layerindex-web][PATCH v2] layerindex/views: support querying by layer name

Hi Jose,

Sorry for the delay. The patch looks good except it displays two errors if there's no layer after the layer: prefix. I've fixed that myself and merged to layerindex-web master.

Thanks,
Paul

Quoted 18 lines · CEST Jose Lamego

ping

Quoted 15 lines · Jose Lamego

This change supports querying recipes that belong to a specific layer by using the prefix "layer:" + the desired layer name, for example:
"layer: openembedded-core" and this string can be used by itself or combined with other supported options.

A descriptive error message is displayed when the query string has an unexpected formatting or a non-valid layer name is searched.

[YOCTO #6618]

---
 layerindex/views.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
Quoted 13 lines

layerindex/views.py class RecipeSearchView(ListView): · line 397

Quoted 13 lines
layerindex/views.py +5 -0
index 65a536a..3eac3ac 100644
@@ -390,13 +390,28 @@ class RecipeSearchView(ListView):
         for item in query_items:
             if item.startswith('inherits:'):
                 inherits.append(item.split(':')[1])
+            # support searches by layer name
+            elif item.startswith('layer:'):
+                query_layername = item.split(':')[1].strip().lower()
+                if not query_layername:
+                    messages.add_message(self.request, messages.ERROR, 

'The \

Quoted 1 line

layerindex/views.py class RecipeSearchView(ListView): · line 398

Quoted 1 line
layerindex/views.py +1 -0
+layer name is expected to follow the \"layer:\" prefix without any 

spaces.')

Quoted 5 lines
Quoted 5 lines
layerindex/views.py +5 -0
+                query_layer = LayerBranch.objects.filter(
+                    layer__name=query_layername)
+                if query_layer:
+                    init_qs = init_qs.filter(
+                        layerbranch__layer__id=query_layer[0].id)
Quoted 8 lines

layerindex/views.py class RecipeSearchView(ListView):

Quoted 8 lines
layerindex/views.py +4 -0
+                else:
+                    messages.add_message(self.request, messages.ERROR,
+                                         'No layer \"%s\" was found.'
+                                         % query_layername)
             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

Quoted 2 lines

layerindex/views.py class RecipeSearchView(ListView): · line 413

Quoted 2 lines
layerindex/views.py +0 -0
             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))

Quoted 8 lines
Quoted 6 lines
layerindex/views.py +1 -1
-            query_string = ' '.join(query_terms)
+        query_string = ' '.join(query_terms)
 
         if query_string.strip():
             order_by = ('pn', 'layerbranch__layer')
Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre