diff --git a/cookbook/migrations/0168_add_unit_searchfields.py b/cookbook/migrations/0168_add_unit_searchfields.py new file mode 100644 index 00000000..d6ba5ee6 --- /dev/null +++ b/cookbook/migrations/0168_add_unit_searchfields.py @@ -0,0 +1,20 @@ +from django.db import migrations + +from cookbook.models import SearchFields + + +def create_searchfields(apps, schema_editor): + SearchFields.objects.create(name='Units', field='steps__ingredients__unit__name') + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0167_userpreference_left_handed'), + ] + + operations = [ + migrations.RunPython( + create_searchfields + ), + ] diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 23d07088..878c7118 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -153,11 +153,15 @@ class FuzzyFilterMixin(ViewSetMixin, ExtendedRecipeMixin): ) else: # TODO have this check unaccent search settings or other search preferences? + filter = Q(name__icontains=query) + if any([self.model.__name__.lower() in x for x in self.request.user.searchpreference.unaccent.values_list('field', flat=True)]): + filter |= Q(name__unaccent__icontains=query) + self.queryset = ( self.queryset .annotate(starts=Case(When(name__istartswith=query, then=(Value(100))), default=Value(0))) # put exact matches at the top of the result set - .filter(name__icontains=query).order_by('-starts', 'name') + .filter(filter).order_by('-starts', 'name') ) updated_at = self.request.query_params.get('updated_at', None) diff --git a/vue/src/apps/RecipeSearchView/RecipeSearchView.vue b/vue/src/apps/RecipeSearchView/RecipeSearchView.vue index 46231b29..aa4f4289 100644 --- a/vue/src/apps/RecipeSearchView/RecipeSearchView.vue +++ b/vue/src/apps/RecipeSearchView/RecipeSearchView.vue @@ -161,7 +161,7 @@ :flat="true" :auto-load-root-options="false" searchNested - :placeholder="$t('Ingredients')" + :placeholder="$t('Foods')" :normalizer="normalizer" @input="refreshData(false)" style="flex-grow: 1; flex-shrink: 1; flex-basis: 0" diff --git a/vue/src/components/GenericMultiselect.vue b/vue/src/components/GenericMultiselect.vue index be26f545..b886fc25 100644 --- a/vue/src/components/GenericMultiselect.vue +++ b/vue/src/components/GenericMultiselect.vue @@ -117,6 +117,7 @@ export default { limit: this.limit, } this.genericAPI(this.model, this.Actions.LIST, options).then((result) => { + console.log(result) this.objects = this.sticky_options.concat(result.data?.results ?? result.data) if (this.nothingSelected && this.objects.length > 0) { this.objects.forEach((item) => {