complex keyword filters

This commit is contained in:
Chris Scoggins
2022-01-20 13:34:02 -06:00
parent bb226a221e
commit 28d3d8a1e0
6 changed files with 274 additions and 107 deletions

View File

@@ -31,7 +31,13 @@ class RecipeSearch():
self._search_prefs = SearchPreference() self._search_prefs = SearchPreference()
self._string = params.get('query').strip() if params.get('query', None) else None self._string = params.get('query').strip() if params.get('query', None) else None
self._rating = self._params.get('rating', None) self._rating = self._params.get('rating', None)
self._keywords = self._params.get('keywords', None) self._keywords = {
'or': self._params.get('keywords_or', None),
'and': self._params.get('keywords_and', None),
'or_not': self._params.get('keywords_or_not', None),
'and_not': self._params.get('keywords_and_not', None)
}
self._foods = self._params.get('foods', None) self._foods = self._params.get('foods', None)
self._books = self._params.get('books', None) self._books = self._params.get('books', None)
self._steps = self._params.get('steps', None) self._steps = self._params.get('steps', None)
@@ -42,7 +48,6 @@ class RecipeSearch():
self._sort_order = self._params.get('sort_order', None) self._sort_order = self._params.get('sort_order', None)
# TODO add save # TODO add save
self._keywords_or = str2bool(self._params.get('keywords_or', True))
self._foods_or = str2bool(self._params.get('foods_or', True)) self._foods_or = str2bool(self._params.get('foods_or', True))
self._books_or = str2bool(self._params.get('books_or', True)) self._books_or = str2bool(self._params.get('books_or', True))
@@ -88,7 +93,7 @@ class RecipeSearch():
self._new_recipes() self._new_recipes()
# self._last_viewed() # self._last_viewed()
# self._last_cooked() # self._last_cooked()
self.keyword_filters(keywords=self._keywords, operator=self._keywords_or) self.keyword_filters(**self._keywords)
self.food_filters(foods=self._foods, operator=self._foods_or) self.food_filters(foods=self._foods, operator=self._foods_or)
self.book_filters(books=self._books, operator=self._books_or) self.book_filters(books=self._books, operator=self._books_or)
self.rating_filter(rating=self._rating) self.rating_filter(rating=self._rating)
@@ -182,19 +187,31 @@ class RecipeSearch():
).values('recipe').annotate(count=Count('pk', distinct=True)).values('count') ).values('recipe').annotate(count=Count('pk', distinct=True)).values('count')
self._queryset = self._queryset.annotate(favorite=Coalesce(Subquery(favorite_recipes), 0)) self._queryset = self._queryset.annotate(favorite=Coalesce(Subquery(favorite_recipes), 0))
def keyword_filters(self, keywords=None, operator=True): def keyword_filters(self, **kwargs):
if not keywords: if all([kwargs[x] is None for x in kwargs]):
return return
if not isinstance(keywords, list): for kw_filter in kwargs:
keywords = [keywords] if not kwargs[kw_filter]:
if operator == True: continue
# TODO creating setting to include descendants of keywords a setting if not isinstance(kwargs[kw_filter], list):
self._queryset = self._queryset.filter(keywords__in=Keyword.include_descendants(Keyword.objects.filter(pk__in=keywords))) kwargs[kw_filter] = [kwargs[kw_filter]]
keywords = Keyword.objects.filter(pk__in=kwargs[kw_filter])
if 'or' in kw_filter:
f = Q(keywords__in=Keyword.include_descendants(keywords))
if 'not' in kw_filter:
self._queryset = self._queryset.exclude(f)
else: else:
# when performing an 'and' search returned recipes should include a parent OR any of its descedants self._queryset = self._queryset.filter(f)
# AND other keywords selected so filters are appended using keyword__id__in the list of keywords and descendants elif 'and' in kw_filter:
for kw in Keyword.objects.filter(pk__in=keywords): recipes = Recipe.objects.all()
self._queryset = self._queryset.filter(keywords__in=list(kw.get_descendants_and_self())) for kw in keywords:
if 'not' in kw_filter:
recipes = recipes.filter(keywords__in=kw.get_descendants_and_self())
else:
self._queryset = self._queryset.filter(keywords__in=kw.get_descendants_and_self())
if 'not' in kw_filter:
self._queryset = self._queryset.exclude(id__in=recipes.values('id'))
def food_filters(self, foods=None, operator=True): def food_filters(self, foods=None, operator=True):
if not foods: if not foods:
@@ -229,7 +246,7 @@ class RecipeSearch():
if rating == 0: if rating == 0:
self._queryset = self._queryset.filter(rating=0) self._queryset = self._queryset.filter(rating=0)
elif lessthan: elif lessthan:
self._queryset = self._queryset.filter(rating__lte=int(rating[1:])) self._queryset = self._queryset.filter(rating__lte=int(rating[1:])).exclude(rating=0)
else: else:
self._queryset = self._queryset.filter(rating__gte=int(rating)) self._queryset = self._queryset.filter(rating__gte=int(rating))

View File

@@ -630,15 +630,18 @@ class RecipeViewSet(viewsets.ModelViewSet):
# TODO split read and write permission for meal plan guest # TODO split read and write permission for meal plan guest
permission_classes = [CustomIsShare | CustomIsGuest] permission_classes = [CustomIsShare | CustomIsGuest]
pagination_class = RecipePagination pagination_class = RecipePagination
# TODO the boolean params below (keywords_or through new) should be updated to boolean types with front end refactored accordingly
query_params = [ query_params = [
QueryParam(name='query', description=_('Query string matched (fuzzy) against recipe name. In the future also fulltext search.')), QueryParam(name='query', description=_('Query string matched (fuzzy) against recipe name. In the future also fulltext search.')),
QueryParam(name='keywords', description=_('ID of keyword a recipe should have. For multiple repeat parameter.'), qtype='int'), QueryParam(name='keywords', description=_('ID of keyword a recipe should have. For multiple repeat parameter. Equivalent to keywords_or'), qtype='int'),
QueryParam(name='keywords_or', description=_('Keyword IDs, repeat for multiple Return recipes with any of the keywords'), qtype='int'),
QueryParam(name='keywords_and', description=_('Keyword IDs, repeat for multiple Return recipes with all of the keywords.'), qtype='int'),
QueryParam(name='keywords_or_not', description=_('Keyword IDs, repeat for multiple Exclude recipes with any of the keywords.'), qtype='int'),
QueryParam(name='keywords_and_not', description=_('Keyword IDs, repeat for multiple Exclude recipes with all of the keywords.'), qtype='int'),
QueryParam(name='foods', description=_('ID of food a recipe should have. For multiple repeat parameter.'), qtype='int'), QueryParam(name='foods', description=_('ID of food a recipe should have. For multiple repeat parameter.'), qtype='int'),
QueryParam(name='units', description=_('ID of unit a recipe should have.'), qtype='int'), QueryParam(name='units', description=_('ID of unit a recipe should have.'), qtype='int'),
QueryParam(name='rating', description=_('Rating a recipe should have. [0 - 5]'), qtype='int'), QueryParam(name='rating', description=_('Rating a recipe should have. [0 - 5]'), qtype='int'),
QueryParam(name='books', description=_('ID of book a recipe should be in. For multiple repeat parameter.')), QueryParam(name='books', description=_('ID of book a recipe should be in. For multiple repeat parameter.')),
QueryParam(name='keywords_or', description=_('If recipe should have all (AND=''false'') or any (OR=''<b>true</b>'') of the provided keywords.')),
QueryParam(name='foods_or', description=_('If recipe should have all (AND=''false'') or any (OR=''<b>true</b>'') of the provided foods.')), QueryParam(name='foods_or', description=_('If recipe should have all (AND=''false'') or any (OR=''<b>true</b>'') of the provided foods.')),
QueryParam(name='books_or', description=_('If recipe should be in all (AND=''false'') or any (OR=''<b>true</b>'') of the provided books.')), QueryParam(name='books_or', description=_('If recipe should be in all (AND=''false'') or any (OR=''<b>true</b>'') of the provided books.')),
QueryParam(name='internal', description=_('If only internal recipes should be returned. [''true''/''<b>false</b>'']')), QueryParam(name='internal', description=_('If only internal recipes should be returned. [''true''/''<b>false</b>'']')),

View File

@@ -141,9 +141,25 @@
</b-popover> </b-popover>
<!-- keywords filter --> <!-- keywords filter -->
<h5 v-if="search.expert_mode && search.keywords_fields > 1">{{ $t("Keywords") }}</h5>
<div class="row" v-if="ui.show_keywords"> <div class="row" v-if="ui.show_keywords">
<div class="col-12"> <div class="col-12">
<b-input-group class="mt-2" v-for="(x, i) in search.keyword_fields" :key="i"> <b-input-group class="mt-2" v-for="(x, i) in keywordFields" :key="i">
<template #prepend v-if="search.expert_mode">
<b-input-group-text style="width: 3em" @click="search.keywords_fields = search.keywords_fields + 1">
<i class="fas fa-plus-circle text-primary" v-if="x == search.keywords_fields && x < 4" />
</b-input-group-text>
<b-input-group-text
style="width: 3em"
@click="
search.keywords_fields = search.keywords_fields - 1
search.search_keywords[i].items = []
refreshData(false)
"
>
<i class="fas fa-minus-circle text-primary" v-if="x == search.keywords_fields && x > 1" />
</b-input-group-text>
</template>
<treeselect <treeselect
v-if="ui.tree_select" v-if="ui.tree_select"
v-model="search.search_keywords[i].items" v-model="search.search_keywords[i].items"
@@ -159,8 +175,8 @@
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0" style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
/> />
<generic-multiselect <generic-multiselect
@change="genericSelectChanged"
v-if="!ui.tree_select" v-if="!ui.tree_select"
@change="genericSelectChanged"
:parent_variable="`search_keywords::${i}`" :parent_variable="`search_keywords::${i}`"
:initial_selection="search.search_keywords[i].items" :initial_selection="search.search_keywords[i].items"
:model="Models.KEYWORD" :model="Models.KEYWORD"
@@ -170,12 +186,26 @@
></generic-multiselect> ></generic-multiselect>
<b-input-group-append> <b-input-group-append>
<b-input-group-text> <b-input-group-text>
<b-form-checkbox v-model="search.search_keywords[i].operator" name="check-button" @change="refreshData(false)" class="shadow-none" switch> <b-form-checkbox
<span class="text-uppercase" v-if="search.search_keywords_or">{{ $t("or") }}</span> v-model="search.search_keywords[i].operator"
name="check-button"
@change="refreshData(false)"
class="shadow-none"
switch
style="width: 4em"
>
<span class="text-uppercase" v-if="search.search_keywords[i].operator">{{ $t("or") }}</span>
<span class="text-uppercase" v-else>{{ $t("and") }}</span> <span class="text-uppercase" v-else>{{ $t("and") }}</span>
</b-form-checkbox> </b-form-checkbox>
</b-input-group-text> </b-input-group-text>
</b-input-group-append> </b-input-group-append>
<b-input-group-append v-if="search.expert_mode">
<b-input-group-text>
<b-form-checkbox v-model="search.search_keywords[i].not" name="check-button" @change="refreshData(false)" class="shadow-none">
<span class="text-uppercase">{{ $t("not") }}</span>
</b-form-checkbox>
</b-input-group-text>
</b-input-group-append>
</b-input-group> </b-input-group>
</div> </div>
</div> </div>
@@ -199,8 +229,8 @@
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0" style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
/> />
<generic-multiselect <generic-multiselect
@change="genericSelectChanged"
v-if="!ui.tree_select" v-if="!ui.tree_select"
@change="genericSelectChanged"
parent_variable="search_foods" parent_variable="search_foods"
:initial_selection="search.search_foods" :initial_selection="search.search_foods"
:model="Models.FOOD" :model="Models.FOOD"
@@ -210,7 +240,7 @@
></generic-multiselect> ></generic-multiselect>
<b-input-group-append> <b-input-group-append>
<b-input-group-text> <b-input-group-text>
<b-form-checkbox v-model="search.search_foods_or" name="check-button" @change="refreshData(false)" class="shadow-none" switch> <b-form-checkbox v-model="search.search_foods_or" name="check-button" @change="refreshData(false)" class="shadow-none" switch style="width: 4em">
<span class="text-uppercase" v-if="search.search_foods_or">{{ $t("or") }}</span> <span class="text-uppercase" v-if="search.search_foods_or">{{ $t("or") }}</span>
<span class="text-uppercase" v-else>{{ $t("and") }}</span> <span class="text-uppercase" v-else>{{ $t("and") }}</span>
</b-form-checkbox> </b-form-checkbox>
@@ -235,7 +265,7 @@
></generic-multiselect> ></generic-multiselect>
<b-input-group-append> <b-input-group-append>
<b-input-group-text> <b-input-group-text>
<b-form-checkbox v-model="search.search_books_or" name="check-button" @change="refreshData(false)" class="shadow-none" tyle="width: 100%" switch> <b-form-checkbox v-model="search.search_books_or" name="check-button" @change="refreshData(false)" class="shadow-none" style="width: 4em" switch>
<span class="text-uppercase" v-if="search.search_books_or">{{ $t("or") }}</span> <span class="text-uppercase" v-if="search.search_books_or">{{ $t("or") }}</span>
<span class="text-uppercase" v-else>{{ $t("and") }}</span> <span class="text-uppercase" v-else>{{ $t("and") }}</span>
</b-form-checkbox> </b-form-checkbox>
@@ -250,7 +280,7 @@
<div class="col-12"> <div class="col-12">
<b-input-group class="mt-2"> <b-input-group class="mt-2">
<treeselect <treeselect
v-model="search.search_ratings" v-model="search.search_rating"
:options="ratingOptions" :options="ratingOptions"
:flat="true" :flat="true"
:placeholder="$t('Ratings')" :placeholder="$t('Ratings')"
@@ -258,8 +288,16 @@
@input="refreshData(false)" @input="refreshData(false)"
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0" style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
/> />
<!-- <b-input-group-append>
<b-input-group-text style="width: 85px"> </b-input-group-text>
</b-input-group-append> -->
<b-input-group-append> <b-input-group-append>
<b-input-group-text style="width: 85px"></b-input-group-text> <b-input-group-text>
<b-form-checkbox v-model="search.search_rating_gte" name="check-button" @change="refreshData(false)" class="shadow-none" switch style="width: 4em">
<span class="text-uppercase" v-if="search.search_rating_gte">&gt;=</span>
<span class="text-uppercase" v-else>&lt;=</span>
</b-form-checkbox>
</b-input-group-text>
</b-input-group-append> </b-input-group-append>
</b-input-group> </b-input-group>
</div> </div>
@@ -279,7 +317,7 @@
></generic-multiselect> ></generic-multiselect>
<b-input-group-append> <b-input-group-append>
<b-input-group-text> <b-input-group-text>
<b-form-checkbox v-model="search.search_units_or" name="check-button" @change="refreshData(false)" class="shadow-none" tyle="width: 100%" switch> <b-form-checkbox v-model="search.search_units_or" name="check-button" @change="refreshData(false)" class="shadow-none" style="width: 4em" switch>
<span class="text-uppercase" v-if="search.search_units_or">{{ $t("or") }}</span> <span class="text-uppercase" v-if="search.search_units_or">{{ $t("or") }}</span>
<span class="text-uppercase" v-else>{{ $t("and") }}</span> <span class="text-uppercase" v-else>{{ $t("and") }}</span>
</b-form-checkbox> </b-form-checkbox>
@@ -339,8 +377,8 @@ import { ApiMixin, ResolveUrlMixin } from "@/utils/utils"
import LoadingSpinner from "@/components/LoadingSpinner" // TODO: is this deprecated? import LoadingSpinner from "@/components/LoadingSpinner" // TODO: is this deprecated?
import RecipeCard from "@/components/RecipeCard" import RecipeCard from "@/components/RecipeCard"
import GenericMultiselect from "@/components/GenericMultiselect" import GenericMultiselect from "@/components/GenericMultiselect"
import { Treeselect, LOAD_CHILDREN_OPTIONS } from "@riophae/vue-treeselect" //TODO: delete import { Treeselect, LOAD_CHILDREN_OPTIONS } from "@riophae/vue-treeselect"
import "@riophae/vue-treeselect/dist/vue-treeselect.css" //TODO: delete import "@riophae/vue-treeselect/dist/vue-treeselect.css"
import RecipeSwitcher from "@/components/Buttons/RecipeSwitcher" import RecipeSwitcher from "@/components/Buttons/RecipeSwitcher"
Vue.use(VueCookies) Vue.use(VueCookies)
@@ -366,15 +404,15 @@ export default {
search_input: "", search_input: "",
search_internal: false, search_internal: false,
search_keywords: [ search_keywords: [
{ items: [], operator: true }, { items: [], operator: true, not: false },
{ items: [], operator: true }, { items: [], operator: true, not: false },
{ items: [], operator: true }, { items: [], operator: true, not: false },
{ items: [], operator: true }, { items: [], operator: true, not: false },
], ],
search_foods: [], search_foods: [],
search_books: [], search_books: [],
search_units: [], search_units: [],
search_ratings: undefined, search_rating: undefined,
search_rating_gte: true, search_rating_gte: true,
search_keywords_or: true, search_keywords_or: true,
search_foods_or: true, search_foods_or: true,
@@ -382,7 +420,11 @@ export default {
search_units_or: true, search_units_or: true,
pagination_page: 1, pagination_page: 1,
expert_mode: false, expert_mode: false,
keyword_fields: 1, keywords_fields: 1,
food_fields: 1,
book_fields: 1,
rating_fields: 1,
unit_fields: 1,
}, },
ui: { ui: {
show_meal_plan: true, show_meal_plan: true,
@@ -410,6 +452,7 @@ export default {
computed: { computed: {
ratingOptions: function () { ratingOptions: function () {
let ratingCount = undefined let ratingCount = undefined
let label = undefined
if (Object.keys(this.facets?.Ratings ?? {}).length === 0) { if (Object.keys(this.facets?.Ratings ?? {}).length === 0) {
ratingCount = (x) => { ratingCount = (x) => {
return "" return ""
@@ -419,24 +462,52 @@ export default {
return ` (${x})` return ` (${x})`
} }
} }
let label = ""
if (this.search.search_rating_gte) { if (this.search.search_rating_gte) {
label = this.$t("and_up") label = (x) => {
if (x == 5) {
return ""
} else { } else {
label = this.$t("and_down") return this.$t("and_up")
} }
}
} else {
label = (x) => {
if (x == 1) {
return ""
} else {
return this.$t("and_down")
}
}
}
return [ return [
{ id: 5, label: "⭐⭐⭐⭐⭐" + ratingCount(this.facets.Ratings?.["5.0"] ?? 0) }, { id: 5, label: "⭐⭐⭐⭐⭐" + label(5) + ratingCount(this.facets.Ratings?.["5.0"] ?? 0) },
{ id: 4, label: "⭐⭐⭐⭐ " + this.$t("and_up") + ratingCount(this.facets.Ratings?.["4.0"] ?? 0) }, { id: 4, label: "⭐⭐⭐⭐ " + label() + ratingCount(this.facets.Ratings?.["4.0"] ?? 0) },
{ id: 3, label: "⭐⭐⭐ " + this.$t("and_up") + ratingCount(this.facets.Ratings?.["3.0"] ?? 0) }, { id: 3, label: "⭐⭐⭐ " + label() + ratingCount(this.facets.Ratings?.["3.0"] ?? 0) },
{ id: 2, label: "⭐⭐ " + this.$t("and_up") + ratingCount(this.facets.Ratings?.["2.0"] ?? 0) }, { id: 2, label: "⭐⭐ " + label() + ratingCount(this.facets.Ratings?.["2.0"] ?? 0) },
{ id: 1, label: "⭐ " + this.$t("and_up") + ratingCount(this.facets.Ratings?.["1.0"] ?? 0) }, { id: 1, label: "⭐ " + label(1) + ratingCount(this.facets.Ratings?.["1.0"] ?? 0) },
{ id: 0, label: this.$t("Unrated") + ratingCount(this.facets.Ratings?.["0.0"] ?? 0) }, { id: 0, label: this.$t("Unrated") + ratingCount(this.facets.Ratings?.["0.0"] ?? 0) },
] ]
}, },
expertMode: function () { expertMode: function () {
return this.ui.enable_expert && this.search.expert_mode return this.ui.enable_expert && this.search.expert_mode
}, },
keywordFields: function () {
return !this.expertMode ? 1 : this.search.keywords_fields
},
foodFields: function () {
return !this.expertMode ? 1 : this.search.food_fields
},
bookFields: function () {
return !this.expertMode ? 1 : this.search.book_fields
},
ratingFields: function () {
return !this.expertMode ? 1 : this.search.rating_fields
},
unitFields: function () {
return !this.expertMode ? 1 : this.search.unit_fields
},
}, },
mounted() { mounted() {
this.$nextTick(function () { this.$nextTick(function () {
@@ -478,7 +549,7 @@ export default {
} }
this.facets.Keywords = [] this.facets.Keywords = []
for (let x of this.search.search_keywords) { for (let x of this.search.search_keywords.map((x) => x.items).flat()) {
this.facets.Keywords.push({ id: x, name: "loading..." }) this.facets.Keywords.push({ id: x, name: "loading..." })
} }
@@ -532,37 +603,7 @@ export default {
methods: { methods: {
// this.genericAPI inherited from ApiMixin // this.genericAPI inherited from ApiMixin
refreshData: function (random) { refreshData: function (random) {
console.log(this.search.search_keywords) let params = this.buildParams(random)
this.random_search = random
let params = {
query: this.search.search_input,
keywords: this.search.search_keywords[0].items.map(function (A) {
return A?.["id"] ?? A
}),
foods: this.search.search_foods.map(function (A) {
return A?.["id"] ?? A
}),
rating: this.search.search_ratings,
units: this.search.search_units.map(function (A) {
return A["id"]
}),
books: this.search.search_books.map(function (A) {
return A["id"]
}),
keywordsOr: this.search.search_keywords_or,
foodsOr: this.search.search_foods_or,
booksOr: this.search.search_books_or,
unitsOr: this.search.search_units_or,
internal: this.search.search_internal,
random: this.random_search,
_new: this.ui.sort_by_new,
page: this.search.pagination_page,
pageSize: this.search.page_size,
}
if (!this.searchFiltered) {
params.options = { query: { last_viewed: this.ui.recently_viewed } }
}
// console.log(params, this.search.search_keywords[0], this.search.search_keywords[0].items)
this.genericAPI(this.Models.RECIPE, this.Actions.LIST, params) this.genericAPI(this.Models.RECIPE, this.Actions.LIST, params)
.then((result) => { .then((result) => {
window.scrollTo(0, 0) window.scrollTo(0, 0)
@@ -619,11 +660,13 @@ export default {
resetSearch: function () { resetSearch: function () {
this.search.search_input = "" this.search.search_input = ""
this.search.search_internal = false this.search.search_internal = false
this.search.search_keywords[0].items = [] this.search.search_keywords = this.search.search_keywords.map((x) => {
return { ...x, items: [] }
})
this.search.search_foods = [] this.search.search_foods = []
this.search.search_books = [] this.search.search_books = []
this.search.search_units = [] this.search.search_units = []
this.search.search_ratings = undefined this.search.search_rating = undefined
this.search.pagination_page = 1 this.search.pagination_page = 1
this.refreshData(false) this.refreshData(false)
}, },
@@ -682,16 +725,24 @@ export default {
} }
} }
}, },
buildParams: function () { buildParams: function (random) {
this.random_search = random
let rating = this.search.search_rating
if (rating !== undefined && !this.search.search_rating_gte) {
rating = rating * -1
}
// TODO check expertmode
this.addFields("keywords")
let params = { let params = {
...this.addFields("keywords"),
query: this.search.search_input, query: this.search.search_input,
keywords: this.search.search_keywords[0].items, foods: this.search.search_foods.map(function (A) {
foods: this.search.search_foods, return A?.["id"] ?? A
rating: this.search.search_ratings, }),
rating: rating,
books: this.search.search_books.map(function (A) { books: this.search.search_books.map(function (A) {
return A["id"] return A["id"]
}), }),
keywordsOr: this.search.search_keywords_or,
foodsOr: this.search.search_foods_or, foodsOr: this.search.search_foods_or,
booksOr: this.search.search_books_or, booksOr: this.search.search_books_or,
internal: this.search.search_internal, internal: this.search.search_internal,
@@ -703,6 +754,8 @@ export default {
if (!this.searchFiltered()) { if (!this.searchFiltered()) {
params.options = { query: { last_viewed: this.ui.recently_viewed } } params.options = { query: { last_viewed: this.ui.recently_viewed } }
} }
console.log(params)
return params
}, },
searchFiltered: function (ignore_string = false) { searchFiltered: function (ignore_string = false) {
let filtered = let filtered =
@@ -711,7 +764,7 @@ export default {
this.search?.search_books?.length === 0 && this.search?.search_books?.length === 0 &&
// this.settings?.pagination_page === 1 && // this.settings?.pagination_page === 1 &&
!this.random_search && !this.random_search &&
this.search?.search_ratings === undefined this.search?.search_rating === undefined
if (ignore_string) { if (ignore_string) {
return !filtered return !filtered
@@ -719,10 +772,57 @@ export default {
return !filtered && this.search?.search_input !== "" return !filtered && this.search?.search_input !== ""
} }
}, },
addFields(field) {
let fieldlist = this.search[`search_${field}`].slice(0, this.search[`${field}_fields`])
return {
[`${field}_or`]: fieldlist
.filter((x) => x.operator == true && x.not == false)
.map((x) => x.items)
.flat()
.map((x) => x?.id ?? x),
[`${field}_and`]: fieldlist
.filter((x) => x.operator == false && x.not == false)
.map((x) => x.items)
.flat()
.map((x) => x?.id ?? x),
[`${field}_or_not`]: fieldlist
.filter((x) => x.operator == true && x.not == true)
.map((x) => x.items)
.flat()
.map((x) => x?.id ?? x),
[`${field}_and_not`]: fieldlist
.filter((x) => x.operator == false && x.not == true)
.map((x) => x.items)
.flat()
.map((x) => x?.id ?? x),
}
},
}, },
} }
</script> </script>
<style src="vue-multiselect/dist/vue-multiselect.min.css"></style> <style src="vue-multiselect/dist/vue-multiselect.min.css"></style>
<style></style> <style>
.vue-treeselect__control {
border-radius: 0px !important;
height: 44px;
}
.multiselect__tags {
border-radius: 0px !important;
line-height: 22px;
}
/* copied from vue-multiselect */
.vue-treeselect__placeholder {
font-weight: 400;
font-family: inherit;
text-align: left;
font-size: 14px;
margin-bottom: 10px;
padding-top: 2px;
}
/* copied from vue-multiselect */
.vue-treeselect__control-arrow-container {
width: 30px;
}
</style>

View File

@@ -308,5 +308,6 @@
"show_books": "Show Books", "show_books": "Show Books",
"show_rating": "Show Rating", "show_rating": "Show Rating",
"show_units": "Show Units", "show_units": "Show Units",
"show_filters": "Show Filters" "show_filters": "Show Filters",
"not": "not"
} }

View File

@@ -433,7 +433,26 @@ export class Models {
name: "Recipe", name: "Recipe",
apiName: "Recipe", apiName: "Recipe",
list: { list: {
params: ["query", "keywords", "foods", "units", "rating", "books", "keywordsOr", "foodsOr", "booksOr", "internal", "random", "_new", "page", "pageSize", "options"], params: [
"query",
"keywords",
"keywords_or",
"keywords_and",
"keywords_or_not",
"keywords_and_not",
"foods",
"units",
"rating",
"books",
"foodsOr",
"booksOr",
"internal",
"random",
"_new",
"page",
"pageSize",
"options",
],
// 'config': { // 'config': {
// 'foods': {'type': 'string'}, // 'foods': {'type': 'string'},
// 'keywords': {'type': 'string'}, // 'keywords': {'type': 'string'},

View File

@@ -3054,12 +3054,15 @@ export interface UserPreference {
* @memberof UserPreference * @memberof UserPreference
*/ */
shopping_add_onhand?: boolean; shopping_add_onhand?: boolean;
<<<<<<< HEAD
/** /**
* *
* @type {boolean} * @type {boolean}
* @memberof UserPreference * @memberof UserPreference
*/ */
left_handed?: boolean; left_handed?: boolean;
=======
>>>>>>> complex keyword filters
} }
/** /**
@@ -5279,12 +5282,15 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
/** /**
* *
* @param {string} [query] Query string matched (fuzzy) against recipe name. In the future also fulltext search. * @param {string} [query] Query string matched (fuzzy) against recipe name. In the future also fulltext search.
* @param {number} [keywords] ID of keyword a recipe should have. For multiple repeat parameter. * @param {number} [keywords] ID of keyword a recipe should have. For multiple repeat parameter. Equivalent to keywords_or
* @param {number} [keywordsOr] Keyword IDs, repeat for multiple Return recipes with any of the keywords
* @param {number} [keywordsAnd] Keyword IDs, repeat for multiple Return recipes with all of the keywords.
* @param {number} [keywordsOrNot] Keyword IDs, repeat for multiple Exclude recipes with any of the keywords.
* @param {number} [keywordsAndNot] Keyword IDs, repeat for multiple Exclude recipes with all of the keywords.
* @param {number} [foods] ID of food a recipe should have. For multiple repeat parameter. * @param {number} [foods] ID of food a recipe should have. For multiple repeat parameter.
* @param {number} [units] ID of unit a recipe should have. * @param {number} [units] ID of unit a recipe should have.
* @param {number} [rating] Rating a recipe should have. [0 - 5] * @param {number} [rating] Rating a recipe should have. [0 - 5]
* @param {string} [books] ID of book a recipe should be in. For multiple repeat parameter. * @param {string} [books] ID of book a recipe should be in. For multiple repeat parameter.
* @param {string} [keywordsOr] If recipe should have all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided keywords.
* @param {string} [foodsOr] If recipe should have all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided foods. * @param {string} [foodsOr] If recipe should have all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided foods.
* @param {string} [booksOr] If recipe should be in all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided books. * @param {string} [booksOr] If recipe should be in all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided books.
* @param {string} [internal] If only internal recipes should be returned. [true/&lt;b&gt;false&lt;/b&gt;] * @param {string} [internal] If only internal recipes should be returned. [true/&lt;b&gt;false&lt;/b&gt;]
@@ -5295,7 +5301,7 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
*/ */
listRecipes: async (query?: string, keywords?: number, foods?: number, units?: number, rating?: number, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options: any = {}): Promise<RequestArgs> => { listRecipes: async (query?: string, keywords?: number, keywordsOr?: number, keywordsAnd?: number, keywordsOrNot?: number, keywordsAndNot?: number, foods?: number, units?: number, rating?: number, books?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options: any = {}): Promise<RequestArgs> => {
const localVarPath = `/api/recipe/`; const localVarPath = `/api/recipe/`;
// use dummy base URL string because the URL constructor only accepts absolute URLs. // use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
@@ -5316,6 +5322,22 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
localVarQueryParameter['keywords'] = keywords; localVarQueryParameter['keywords'] = keywords;
} }
if (keywordsOr !== undefined) {
localVarQueryParameter['keywords_or'] = keywordsOr;
}
if (keywordsAnd !== undefined) {
localVarQueryParameter['keywords_and'] = keywordsAnd;
}
if (keywordsOrNot !== undefined) {
localVarQueryParameter['keywords_or_not'] = keywordsOrNot;
}
if (keywordsAndNot !== undefined) {
localVarQueryParameter['keywords_and_not'] = keywordsAndNot;
}
if (foods !== undefined) { if (foods !== undefined) {
localVarQueryParameter['foods'] = foods; localVarQueryParameter['foods'] = foods;
} }
@@ -5332,10 +5354,6 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
localVarQueryParameter['books'] = books; localVarQueryParameter['books'] = books;
} }
if (keywordsOr !== undefined) {
localVarQueryParameter['keywords_or'] = keywordsOr;
}
if (foodsOr !== undefined) { if (foodsOr !== undefined) {
localVarQueryParameter['foods_or'] = foodsOr; localVarQueryParameter['foods_or'] = foodsOr;
} }
@@ -9669,12 +9687,15 @@ export const ApiApiFp = function(configuration?: Configuration) {
/** /**
* *
* @param {string} [query] Query string matched (fuzzy) against recipe name. In the future also fulltext search. * @param {string} [query] Query string matched (fuzzy) against recipe name. In the future also fulltext search.
* @param {number} [keywords] ID of keyword a recipe should have. For multiple repeat parameter. * @param {number} [keywords] ID of keyword a recipe should have. For multiple repeat parameter. Equivalent to keywords_or
* @param {number} [keywordsOr] Keyword IDs, repeat for multiple Return recipes with any of the keywords
* @param {number} [keywordsAnd] Keyword IDs, repeat for multiple Return recipes with all of the keywords.
* @param {number} [keywordsOrNot] Keyword IDs, repeat for multiple Exclude recipes with any of the keywords.
* @param {number} [keywordsAndNot] Keyword IDs, repeat for multiple Exclude recipes with all of the keywords.
* @param {number} [foods] ID of food a recipe should have. For multiple repeat parameter. * @param {number} [foods] ID of food a recipe should have. For multiple repeat parameter.
* @param {number} [units] ID of unit a recipe should have. * @param {number} [units] ID of unit a recipe should have.
* @param {number} [rating] Rating a recipe should have. [0 - 5] * @param {number} [rating] Rating a recipe should have. [0 - 5]
* @param {string} [books] ID of book a recipe should be in. For multiple repeat parameter. * @param {string} [books] ID of book a recipe should be in. For multiple repeat parameter.
* @param {string} [keywordsOr] If recipe should have all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided keywords.
* @param {string} [foodsOr] If recipe should have all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided foods. * @param {string} [foodsOr] If recipe should have all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided foods.
* @param {string} [booksOr] If recipe should be in all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided books. * @param {string} [booksOr] If recipe should be in all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided books.
* @param {string} [internal] If only internal recipes should be returned. [true/&lt;b&gt;false&lt;/b&gt;] * @param {string} [internal] If only internal recipes should be returned. [true/&lt;b&gt;false&lt;/b&gt;]
@@ -9685,8 +9706,8 @@ export const ApiApiFp = function(configuration?: Configuration) {
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
*/ */
async listRecipes(query?: string, keywords?: number, foods?: number, units?: number, rating?: number, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<InlineResponse2004>> { async listRecipes(query?: string, keywords?: number, keywordsOr?: number, keywordsAnd?: number, keywordsOrNot?: number, keywordsAndNot?: number, foods?: number, units?: number, rating?: number, books?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<InlineResponse2004>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.listRecipes(query, keywords, foods, units, rating, books, keywordsOr, foodsOr, booksOr, internal, random, _new, page, pageSize, options); const localVarAxiosArgs = await localVarAxiosParamCreator.listRecipes(query, keywords, keywordsOr, keywordsAnd, keywordsOrNot, keywordsAndNot, foods, units, rating, books, foodsOr, booksOr, internal, random, _new, page, pageSize, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
}, },
/** /**
@@ -11354,12 +11375,15 @@ export const ApiApiFactory = function (configuration?: Configuration, basePath?:
/** /**
* *
* @param {string} [query] Query string matched (fuzzy) against recipe name. In the future also fulltext search. * @param {string} [query] Query string matched (fuzzy) against recipe name. In the future also fulltext search.
* @param {number} [keywords] ID of keyword a recipe should have. For multiple repeat parameter. * @param {number} [keywords] ID of keyword a recipe should have. For multiple repeat parameter. Equivalent to keywords_or
* @param {number} [keywordsOr] Keyword IDs, repeat for multiple Return recipes with any of the keywords
* @param {number} [keywordsAnd] Keyword IDs, repeat for multiple Return recipes with all of the keywords.
* @param {number} [keywordsOrNot] Keyword IDs, repeat for multiple Exclude recipes with any of the keywords.
* @param {number} [keywordsAndNot] Keyword IDs, repeat for multiple Exclude recipes with all of the keywords.
* @param {number} [foods] ID of food a recipe should have. For multiple repeat parameter. * @param {number} [foods] ID of food a recipe should have. For multiple repeat parameter.
* @param {number} [units] ID of unit a recipe should have. * @param {number} [units] ID of unit a recipe should have.
* @param {number} [rating] Rating a recipe should have. [0 - 5] * @param {number} [rating] Rating a recipe should have. [0 - 5]
* @param {string} [books] ID of book a recipe should be in. For multiple repeat parameter. * @param {string} [books] ID of book a recipe should be in. For multiple repeat parameter.
* @param {string} [keywordsOr] If recipe should have all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided keywords.
* @param {string} [foodsOr] If recipe should have all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided foods. * @param {string} [foodsOr] If recipe should have all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided foods.
* @param {string} [booksOr] If recipe should be in all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided books. * @param {string} [booksOr] If recipe should be in all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided books.
* @param {string} [internal] If only internal recipes should be returned. [true/&lt;b&gt;false&lt;/b&gt;] * @param {string} [internal] If only internal recipes should be returned. [true/&lt;b&gt;false&lt;/b&gt;]
@@ -11370,8 +11394,8 @@ export const ApiApiFactory = function (configuration?: Configuration, basePath?:
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
*/ */
listRecipes(query?: string, keywords?: number, foods?: number, units?: number, rating?: number, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options?: any): AxiosPromise<InlineResponse2004> { listRecipes(query?: string, keywords?: number, keywordsOr?: number, keywordsAnd?: number, keywordsOrNot?: number, keywordsAndNot?: number, foods?: number, units?: number, rating?: number, books?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options?: any): AxiosPromise<InlineResponse2004> {
return localVarFp.listRecipes(query, keywords, foods, units, rating, books, keywordsOr, foodsOr, booksOr, internal, random, _new, page, pageSize, options).then((request) => request(axios, basePath)); return localVarFp.listRecipes(query, keywords, keywordsOr, keywordsAnd, keywordsOrNot, keywordsAndNot, foods, units, rating, books, foodsOr, booksOr, internal, random, _new, page, pageSize, options).then((request) => request(axios, basePath));
}, },
/** /**
* *
@@ -13063,12 +13087,15 @@ export class ApiApi extends BaseAPI {
/** /**
* *
* @param {string} [query] Query string matched (fuzzy) against recipe name. In the future also fulltext search. * @param {string} [query] Query string matched (fuzzy) against recipe name. In the future also fulltext search.
* @param {number} [keywords] ID of keyword a recipe should have. For multiple repeat parameter. * @param {number} [keywords] ID of keyword a recipe should have. For multiple repeat parameter. Equivalent to keywords_or
* @param {number} [keywordsOr] Keyword IDs, repeat for multiple Return recipes with any of the keywords
* @param {number} [keywordsAnd] Keyword IDs, repeat for multiple Return recipes with all of the keywords.
* @param {number} [keywordsOrNot] Keyword IDs, repeat for multiple Exclude recipes with any of the keywords.
* @param {number} [keywordsAndNot] Keyword IDs, repeat for multiple Exclude recipes with all of the keywords.
* @param {number} [foods] ID of food a recipe should have. For multiple repeat parameter. * @param {number} [foods] ID of food a recipe should have. For multiple repeat parameter.
* @param {number} [units] ID of unit a recipe should have. * @param {number} [units] ID of unit a recipe should have.
* @param {number} [rating] Rating a recipe should have. [0 - 5] * @param {number} [rating] Rating a recipe should have. [0 - 5]
* @param {string} [books] ID of book a recipe should be in. For multiple repeat parameter. * @param {string} [books] ID of book a recipe should be in. For multiple repeat parameter.
* @param {string} [keywordsOr] If recipe should have all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided keywords.
* @param {string} [foodsOr] If recipe should have all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided foods. * @param {string} [foodsOr] If recipe should have all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided foods.
* @param {string} [booksOr] If recipe should be in all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided books. * @param {string} [booksOr] If recipe should be in all (AND&#x3D;false) or any (OR&#x3D;&lt;b&gt;true&lt;/b&gt;) of the provided books.
* @param {string} [internal] If only internal recipes should be returned. [true/&lt;b&gt;false&lt;/b&gt;] * @param {string} [internal] If only internal recipes should be returned. [true/&lt;b&gt;false&lt;/b&gt;]
@@ -13080,8 +13107,8 @@ export class ApiApi extends BaseAPI {
* @throws {RequiredError} * @throws {RequiredError}
* @memberof ApiApi * @memberof ApiApi
*/ */
public listRecipes(query?: string, keywords?: number, foods?: number, units?: number, rating?: number, books?: string, keywordsOr?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options?: any) { public listRecipes(query?: string, keywords?: number, keywordsOr?: number, keywordsAnd?: number, keywordsOrNot?: number, keywordsAndNot?: number, foods?: number, units?: number, rating?: number, books?: string, foodsOr?: string, booksOr?: string, internal?: string, random?: string, _new?: string, page?: number, pageSize?: number, options?: any) {
return ApiApiFp(this.configuration).listRecipes(query, keywords, foods, units, rating, books, keywordsOr, foodsOr, booksOr, internal, random, _new, page, pageSize, options).then((request) => request(this.axios, this.basePath)); return ApiApiFp(this.configuration).listRecipes(query, keywords, keywordsOr, keywordsAnd, keywordsOrNot, keywordsAndNot, foods, units, rating, books, foodsOr, booksOr, internal, random, _new, page, pageSize, options).then((request) => request(this.axios, this.basePath));
} }
/** /**