(event, key, value)
| 3922 | out.push({ t: 'filter', kind, value: valRaw }); |
| 3923 | } else if (!valRaw) { |
| 3924 | continue; |
| 3925 | } else { |
| 3926 | const ftNorm = kind === 'fileType' && valRaw.toLowerCase() === 'zip' ? 'zip' : valRaw; |
| 3927 | out.push({ t: 'filter', kind, value: ftNorm }); |
| 3928 | } |
| 3929 | } else if (x.t === 'filterMulti') { |
| 3930 | const kind = String(x.kind || '').trim(); |
| 3931 | if (!kind || !['designer', 'license', 'parentModel', 'tag'].includes(kind)) continue; |
| 3932 | const vals = Array.isArray(x.values) ? x.values.map((v) => String(v).trim()).filter(Boolean) : []; |
| 3933 | if (vals.length === 0) continue; |
| 3934 | const combine = String(x.combine || 'OR').toUpperCase() === 'AND' ? 'AND' : 'OR'; |
| 3935 | out.push({ t: 'filterMulti', kind, values: vals, combine }); |
| 3936 | } |
| 3937 | } |
| 3938 | for (let i = 1; i < out.length; i++) { |
| 3939 | const a = out[i - 1]; |
| 3940 | const b = out[i]; |
| 3941 | if (a.t === 'op' && b.t === 'op' && a.op === b.op) { |
| 3942 | out.splice(i, 1); |
| 3943 | i--; |
| 3944 | } |
| 3945 | } |
| 3946 | while (out.length && (out[out.length - 1].t === 'op' || out[out.length - 1].t === 'not')) { |
| 3947 | out.pop(); |
| 3948 | } |
| 3949 | return out; |
| 3950 | } |
| 3951 | |
| 3952 | /** SQL fragment for a sidebar filter serialized into searchTokens ({ t: filter | filterMulti }). */ |
| 3953 | function compileSidebarFilterClauseToSQL(tok, filters, params) { |
| 3954 | if (tok.t === 'filterMulti') { |
| 3955 | const combine = tok.combine === 'AND' ? 'AND' : 'OR'; |
| 3956 | if (tok.kind === 'designer') { |
| 3957 | const cond = []; |
| 3958 | pushEqualityListCondition(cond, params, 'designer', tok.values.slice(), combine, !!filters.designerInverted, true); |
| 3959 | return cond[0] || '1'; |
| 3960 | } |
| 3961 | if (tok.kind === 'license') { |
| 3962 | const cond = []; |
| 3963 | pushEqualityListCondition(cond, params, 'license', tok.values.slice(), combine, !!filters.licenseInverted, false); |
| 3964 | return cond[0] || '1'; |
| 3965 | } |
| 3966 | if (tok.kind === 'parentModel') { |
| 3967 | const cond = []; |
| 3968 | pushEqualityListCondition(cond, params, 'parentModel', tok.values.slice(), combine, !!filters.parentModelInverted, false); |
| 3969 | return cond[0] || '1'; |
| 3970 | } |
| 3971 | if (tok.kind === 'tag') { |
| 3972 | const names = tok.values.slice(); |
| 3973 | const f = { |
| 3974 | tags: names, |
| 3975 | tagCombine: combine, |
| 3976 | tagInverted: !!filters.tagInverted, |
| 3977 | }; |
| 3978 | const cond = []; |
| 3979 | pushTagListSQL(cond, params, f); |
nothing calls this directly
no test coverage detected