De-emphasise recipes where there is a more preferred version available

If another recipe exists with the same name in a different layer and
that other layer is "older" (by layer ID) and is a software or base
layer then lighten the recipe entry in the search results as it may
not be the preferred version (e.g. recipes in BSP or distro layers may
have been customised specifically for the machine or distro).

This has had a performance impact on the recipes list; as a result
showing all recipes by default has been disabled. If the user really
wants to see all recipes they can just leave the search box blank and
hit the search button.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2013-03-20 12:04:54 +00:00
parent 42d710b640
commit 342ff28648
4 changed files with 41 additions and 4 deletions

1
TODO
View File

@ -10,7 +10,6 @@ Later:
* Add link to the all layers and all recipes tables from the layer details page?
* Display no-results found message when search does not return any results (all tables)
* Change behaviour of filter menus to stay open so that you can check / uncheck multiple items
* Show recipes from non-software/base layers differently in recipes list
* Show layer type in layer detail?
* Usage links in list page?
* Avoid page content changing size depending on whether scrollbar is there or not?

View File

@ -156,3 +156,7 @@ padding: 8px;
background-color: white;
height: 100%;
}
.muted a {
color: #66B8E0;
}

View File

@ -247,9 +247,32 @@ class RecipeSearchView(ListView):
init_qs = Recipe.objects.filter(layerbranch__branch__name=self.request.session.get('branch', 'master'))
if query_string.strip():
entry_query = simplesearch.get_query(query_string, ['pn', 'summary', 'description', 'filename'])
return init_qs.filter(entry_query).order_by('pn', 'layerbranch__layer')
qs = init_qs.filter(entry_query).order_by('pn', 'layerbranch__layer')
else:
return init_qs.order_by('pn', 'layerbranch__layer')
if 'q' in self.request.GET:
qs = init_qs.order_by('pn', 'layerbranch__layer')
else:
# It's a bit too slow to return all records by default, and most people
# won't actually want that (if they do they can just hit the search button
# with no query string)
return Recipe.objects.none()
# Add extra column so we can show "duplicate" recipes from other layers de-emphasised
# (it's a bit crude having to do this using SQL but I couldn't find a better way...)
return qs.extra(
select={
'preferred_count': """SELECT COUNT(1)
FROM layerindex_recipe AS recipe2
, layerindex_layerbranch as branch2
, layerindex_layeritem as layer2
WHERE branch2.id = recipe2.layerbranch_id
AND layer2.id = branch2.layer_id
AND layer2.layer_type in ('S', 'A')
AND recipe2.pn = layerindex_recipe.pn
AND recipe2.layerbranch_id < layerindex_recipe.layerbranch_id
"""
},
)
def get_context_data(self, **kwargs):
context = super(RecipeSearchView, self).get_context_data(**kwargs)

View File

@ -50,7 +50,7 @@
<tbody>
{% for recipe in recipe_list %}
<tr>
<tr {% if recipe.preferred_count > 0 %}class="muted"{% endif %}>
<td><a href="{% url recipe recipe.id %}">{{ recipe.name }}</a></td>
<td>{{ recipe.pv }}</td>
<td>{{ recipe.short_desc }}</td>
@ -77,3 +77,14 @@
{% endautoescape %}
{% endblock %}
{% block scripts %}
<script>
$(document).ready(function() {
firstfield = $("#filter-form input:text").first()
if( ! firstfield.val() )
firstfield.focus()
});
</script>
{% endblock %}