* [layerindex-web][PATCH] views: support querying by layer name
@ 2017-04-03 19:31 Jose Lamego
2017-05-25 0:16 ` Paul Eggleton
2017-05-31 20:47 ` [layerindex-web][PATCH v2] layerindex/views: " Jose Lamego
0 siblings, 2 replies; 5+ messages in thread
From: Jose Lamego @ 2017-04-03 19:31 UTC (permalink / raw)
To: yocto
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]
Signed-off-by: Jose Lamego <jose.a.lamego@linux.intel.com>
---
layerindex/views.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/layerindex/views.py b/layerindex/views.py
index 65a536a..5b66892 100644
--- a/layerindex/views.py
+++ b/layerindex/views.py
@@ -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')
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [layerindex-web][PATCH] views: support querying by layer name
2017-04-03 19:31 [layerindex-web][PATCH] views: support querying by layer name Jose Lamego
@ 2017-05-25 0:16 ` Paul Eggleton
2017-05-31 20:47 ` [layerindex-web][PATCH v2] layerindex/views: " Jose Lamego
1 sibling, 0 replies; 5+ messages in thread
From: Paul Eggleton @ 2017-05-25 0:16 UTC (permalink / raw)
To: Jose Lamego; +Cc: yocto
Hi Jose,
Sorry for the extreme delay reviewing this.
On Tuesday, 4 April 2017 7:31:29 AM NZST Jose Lamego wrote:
> 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]
>
> Signed-off-by: Jose Lamego <jose.a.lamego@linux.intel.com>
> ---
> layerindex/views.py | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/layerindex/views.py b/layerindex/views.py
> index 65a536a..5b66892 100644
> --- a/layerindex/views.py
> +++ b/layerindex/views.py
> @@ -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)
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
--
Paul Eggleton
Intel Open Source Technology Centre
^ permalink raw reply [flat|nested] 5+ messages in thread
* [layerindex-web][PATCH v2] layerindex/views: support querying by layer name
2017-04-03 19:31 [layerindex-web][PATCH] views: support querying by layer name Jose Lamego
2017-05-25 0:16 ` Paul Eggleton
@ 2017-05-31 20:47 ` Jose Lamego
2017-06-15 13:19 ` Jose Lamego
1 sibling, 1 reply; 5+ messages in thread
From: Jose Lamego @ 2017-05-31 20:47 UTC (permalink / raw)
To: yocto
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]
Signed-off-by: Jose Lamego <jose.a.lamego@linux.intel.com>
---
layerindex/views.py | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/layerindex/views.py b/layerindex/views.py
index 65a536a..3eac3ac 100644
--- a/layerindex/views.py
+++ b/layerindex/views.py
@@ -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')
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [layerindex-web][PATCH v2] layerindex/views: support querying by layer name
2017-05-31 20:47 ` [layerindex-web][PATCH v2] layerindex/views: " Jose Lamego
@ 2017-06-15 13:19 ` Jose Lamego
2017-06-15 14:06 ` Paul Eggleton
0 siblings, 1 reply; 5+ messages in thread
From: Jose Lamego @ 2017-06-15 13:19 UTC (permalink / raw)
To: yocto, paul.eggleton
[-- Attachment #1.1: Type: text/plain, Size: 2585 bytes --]
ping
On 05/31/2017 03:47 PM, Jose Lamego wrote:
> 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]
>
> Signed-off-by: Jose Lamego <jose.a.lamego@linux.intel.com>
> ---
> layerindex/views.py | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/layerindex/views.py b/layerindex/views.py
> index 65a536a..3eac3ac 100644
> --- a/layerindex/views.py
> +++ b/layerindex/views.py
> @@ -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')
>
--
Jose Lamego | OTC Embedded Platforms & Tools | GDC
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 484 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [layerindex-web][PATCH v2] layerindex/views: support querying by layer name
2017-06-15 13:19 ` Jose Lamego
@ 2017-06-15 14:06 ` Paul Eggleton
0 siblings, 0 replies; 5+ messages in thread
From: Paul Eggleton @ 2017-06-15 14:06 UTC (permalink / raw)
To: Jose Lamego; +Cc: yocto
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
On Thursday, 15 June 2017 3:19:48 PM CEST Jose Lamego wrote:
> ping
>
> On 05/31/2017 03:47 PM, Jose Lamego wrote:
> > 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]
> >
> > Signed-off-by: Jose Lamego <jose.a.lamego@linux.intel.com>
> > ---
> > layerindex/views.py | 17 ++++++++++++++++-
> > 1 file changed, 16 insertions(+), 1 deletion(-)
> >
> > diff --git a/layerindex/views.py b/layerindex/views.py
> > index 65a536a..3eac3ac 100644
> > --- a/layerindex/views.py
> > +++ b/layerindex/views.py
> > @@ -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')
> >
>
>
--
Paul Eggleton
Intel Open Source Technology Centre
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-06-15 14:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-03 19:31 [layerindex-web][PATCH] views: support querying by layer name Jose Lamego
2017-05-25 0:16 ` Paul Eggleton
2017-05-31 20:47 ` [layerindex-web][PATCH v2] layerindex/views: " Jose Lamego
2017-06-15 13:19 ` Jose Lamego
2017-06-15 14:06 ` Paul Eggleton
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.