fixed search facets and sub recipe

This commit is contained in:
vabene1111 2021-09-04 19:26:42 +02:00
parent 738387ccf0
commit 16d125a243
4 changed files with 16 additions and 10 deletions

View File

@ -51,7 +51,7 @@ def search_recipes(request, queryset, params):
if search_new == 'true':
queryset = (
queryset.annotate(new_recipe=Case(
When(created_at__gte=(datetime.now() - timedelta(days=7)), then=('pk')), default=Value(0),))
When(created_at__gte=(datetime.now() - timedelta(days=7)), then=('pk')), default=Value(0), ))
)
orderby += ['-new_recipe']
@ -123,9 +123,9 @@ def search_recipes(request, queryset, params):
# TODO add order by user settings - only do search rank and annotation if rank order is configured
search_rank = (
SearchRank('name_search_vector', search_query, cover_density=True)
+ SearchRank('desc_search_vector', search_query, cover_density=True)
+ SearchRank('steps__search_vector', search_query, cover_density=True)
SearchRank('name_search_vector', search_query, cover_density=True)
+ SearchRank('desc_search_vector', search_query, cover_density=True)
+ SearchRank('steps__search_vector', search_query, cover_density=True)
)
queryset = queryset.filter(query_filter).annotate(rank=search_rank)
orderby += ['-rank']
@ -174,7 +174,6 @@ def search_recipes(request, queryset, params):
return queryset
def get_facet(qs, request):
# NOTE facet counts for tree models include self AND descendants
facets = {}
@ -210,9 +209,9 @@ def get_facet(qs, request):
# TODO add book facet
facets['Books'] = []
facets['Recent'] = ViewLog.objects.filter(
created_by=request.user, space=request.space,
created_at__gte=datetime.now() - timedelta(days=14) # TODO make days of recent recipe a setting
).values_list('recipe__pk', flat=True)
created_by=request.user, space=request.space,
created_at__gte=datetime.now() - timedelta(days=14) # TODO make days of recent recipe a setting
).values_list('recipe__pk', flat=True)
return facets

View File

@ -252,7 +252,6 @@
select-label="{% trans 'Select' %}"
:id="'id_step_' + step.id + '_recipe'"
:custom-label="opt => recipes.find(x => x.id == opt).name"
:multiple="false"
:loading="recipes_loading"
@search-change="searchRecipes">
@ -615,6 +614,13 @@
this.$http.get("{% url 'api:recipe-detail' recipe.pk %}").then((response) => {
this.recipe = response.data;
this.loading = false
//TODO workaround function until view is properly refactored, loads name of selected sub recipe so the input can find its label
this.recipe.steps.forEach(s => {
if (s.step_recipe != null) {
this.recipes.push(s.step_recipe_data)
}
})
}).catch((err) => {
this.loading = false
console.log(err)

View File

@ -486,7 +486,7 @@ class RecipePagination(PageNumberPagination):
max_page_size = 100
def paginate_queryset(self, queryset, request, view=None):
self.facets = get_facet(queryset, request.query_params, request.space)
self.facets = get_facet(queryset, request)
return super().paginate_queryset(queryset, request, view)
def get_paginated_response(self, data):

View File

@ -337,6 +337,7 @@ export default {
this.$nextTick(function () {
if (this.$cookies.isKey(SETTINGS_COOKIE_NAME)) {
this.settings = Object.assign({}, this.settings, this.$cookies.get(SETTINGS_COOKIE_NAME))
this.refreshData(false)
}
let urlParams = new URLSearchParams(window.location.search);