The Any Tag filter works on the Videos, Archives and Docs searches (#958)

The filter modal on these pages offered "Any Tag", but only the Files search
sent it; the module searches had no `any_tag` field.  Docs also matched any of
the listed tag_names, while every other search requires all of them.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-11-11 19:21:06 -07:00 • committed by GitHub
parent a0f30a0a60
commit 2800112f3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 189 additions and 30 deletions

View file

@ -196,7 +196,7 @@ export async function tagChannelInfo(channelId, tagName) {
});
}
export async function searchVideos(offset, limit, channelId, searchStr, order_by, tagNames, headline, censored, deep) {
export async function searchVideos(offset, limit, channelId, searchStr, order_by, tagNames, headline, censored, deep, anyTag) {
// Build a search query to retrieve a list of videos from the API
offset = parseInt(offset || 0);
limit = parseInt(limit || DEFAULT_LIMIT);
@ -220,6 +220,9 @@ export async function searchVideos(offset, limit, channelId, searchStr, order_by
if (deep) {
body['deep'] = true;
}
if (anyTag) {
body['any_tag'] = true;
}
console.debug('searching videos', body);
@ -852,7 +855,7 @@ export async function saveCatalog(items) {
}
export async function searchArchives(offset, limit, domain, searchStr, order, tagNames, headline, deep) {
export async function searchArchives(offset, limit, domain, searchStr, order, tagNames, headline, deep, anyTag) {
// Build a search query to retrieve a list of videos from the API
offset = parseInt(offset || 0);
limit = parseInt(limit || DEFAULT_LIMIT);
@ -875,6 +878,9 @@ export async function searchArchives(offset, limit, domain, searchStr, order, ta
if (deep) {
body['deep'] = true;
}
if (anyTag) {
body['any_tag'] = true;
}
console.debug('searching archives', body);
const response = await apiPost(`${ARCHIVES_API}/search`, body);
@ -2438,7 +2444,7 @@ export async function getDoc(fileGroupId) {
}
export async function searchDocs(offset, limit, searchStr, order, tagNames, author, subject, mimetype, deep) {
export async function searchDocs(offset, limit, searchStr, order, tagNames, author, subject, mimetype, deep, anyTag) {
offset = parseInt(offset || 0);
limit = parseInt(limit || DEFAULT_LIMIT);
let body = {offset, limit};
@ -2463,6 +2469,9 @@ export async function searchDocs(offset, limit, searchStr, order, tagNames, auth
if (deep) {
body['deep'] = true;
}
if (anyTag) {
body['any_tag'] = true;
}
console.debug('searching docs', body);
const response = await apiPost(`${DOCS_API}/search`, body);

View file

@ -543,6 +543,7 @@ export const useSearchArchives = (defaultLimit) => {
const searchStr = searchParams.get('q') || '';
const order = searchParams.get('order');
const activeTags = searchParams.getAll('tag');
const anyTag = searchParams.get('anyTag') === 'true';
const {view} = useSearchView();
const headline = view === 'headline';
const {deep} = useSearchDeep();
@ -554,7 +555,7 @@ export const useSearchArchives = (defaultLimit) => {
setArchives(null);
try {
let [archives_, total] = await searchArchives(offset, limit, domain, searchStr, order, activeTags, headline,
deep);
deep, anyTag);
setArchives(archives_);
setTotalPages(calculateTotalPages(total, limit));
} catch (e) {
@ -571,7 +572,7 @@ export const useSearchArchives = (defaultLimit) => {
useEffect(() => {
localSearchArchives();
}, [searchStr, limit, domain, order, offset, JSON.stringify(activeTags), headline, deep]);
}, [searchStr, limit, domain, order, offset, JSON.stringify(activeTags), anyTag, headline, deep]);
const setSearchStr = (value) => {
updateQuery({q: value, o: 0, order: undefined});
@ -615,6 +616,7 @@ export const useSearchDocs = (defaultLimit) => {
const author = searchParams.get('author') || '';
const subject = searchParams.get('subject') || '';
const filter = searchParams.get('filter') || '';
const anyTag = searchParams.get('anyTag') === 'true';
const {deep} = useSearchDeep();
const [docs, setDocs] = useState(null);
@ -625,7 +627,7 @@ export const useSearchDocs = (defaultLimit) => {
try {
const mimetype = docFilterToMimetype(filter);
let [docs_, total] = await searchDocs(offset, limit, searchStr, order, activeTags, author, subject,
mimetype, deep);
mimetype, deep, anyTag);
setDocs(docs_);
setTotalPages(calculateTotalPages(total, limit));
} catch (e) {
@ -636,7 +638,7 @@ export const useSearchDocs = (defaultLimit) => {
useEffect(() => {
localSearchDocs();
}, [searchStr, limit, order, offset, JSON.stringify(activeTags), author, subject, filter, deep]);
}, [searchStr, limit, order, offset, JSON.stringify(activeTags), anyTag, author, subject, filter, deep]);
const setSearchStr = (value) => {
updateQuery({q: value, o: 0, order: undefined});
@ -686,7 +688,7 @@ export const useSearchVideos = (defaultLimit, channelId, order_by) => {
setLoading(true);
try {
let [videos_, total] = await searchVideos(offset, limit, channelId, searchStr, order, activeTags, headline,
censored, deep);
censored, deep, anyTag);
setVideos(videos_);
setTotalPages(calculateTotalPages(total, limit));
} catch (e) {
@ -699,7 +701,7 @@ export const useSearchVideos = (defaultLimit, channelId, order_by) => {
useEffect(() => {
localSearchVideos();
}, [searchStr, limit, channelId, offset, order_by, JSON.stringify(activeTags), headline, censored, deep]);
}, [searchStr, limit, channelId, offset, order_by, JSON.stringify(activeTags), anyTag, headline, censored, deep]);
const setSearchStr = (value) => {
updateQuery({q: value, o: 0, order: undefined});

View file

@ -2,12 +2,12 @@ import React from 'react';
import {act, renderHook} from '@testing-library/react';
import {render, screen} from '../test-utils';
import {
useBrowseFiles, usePages, useDriveTemperature, useDriveHealth, useSearchChannels, useSearchRecentFiles,
useSettings, useStatistics, useStatus, useVideoExtras,
useBrowseFiles, usePages, useDriveTemperature, useDriveHealth, useSearchArchives, useSearchChannels,
useSearchDocs, useSearchRecentFiles, useSearchVideos, useSettings, useStatistics, useStatus, useVideoExtras,
} from './customHooks';
import {
ApiDownError, filesSearch, getFiles, getSettings, getStatistics, getStatus, getVideoComments, getVideoDescription,
searchChannels,
ApiDownError, fetchDomains, filesSearch, getFiles, getSettings, getStatistics, getStatus, getVideoComments,
getVideoDescription, searchArchives, searchChannels, searchDocs, searchVideos,
} from '../api';
import {getControllerStats} from '../api/controller';
import {QueryContext, StatusContext} from '../contexts/contexts';
@ -51,6 +51,10 @@ jest.mock('../api', () => ({
getSettings: jest.fn(),
filesSearch: jest.fn(),
getFiles: jest.fn(),
fetchDomains: jest.fn(),
searchArchives: jest.fn(),
searchDocs: jest.fn(),
searchVideos: jest.fn(),
}));
jest.mock('../api/controller', () => ({
@ -769,3 +773,35 @@ describe('useBrowseFiles', () => {
expect(result.current.browseFiles).toEqual([{path: 'renamed/'}]);
});
});
describe('module searches send the Any Tag filter', () => {
// `anyTag` is the last argument of each search helper.
const cases = [
['useSearchVideos', () => useSearchVideos(), searchVideos],
['useSearchArchives', () => useSearchArchives(), searchArchives],
['useSearchDocs', () => useSearchDocs(), searchDocs],
];
beforeEach(() => {
fetchDomains.mockResolvedValue([[], 0]);
searchVideos.mockResolvedValue([[], 0]);
searchArchives.mockResolvedValue([[], 0]);
searchDocs.mockResolvedValue([[], 0]);
});
afterEach(() => jest.clearAllMocks());
it.each(cases)('%s passes anyTag=true from the URL', async (_, hook, search) => {
renderHook(hook, {wrapper: makeWrapper({anyTag: 'true'})});
await act(async () => {});
expect(search).toHaveBeenCalled();
expect(search.mock.calls.at(-1).at(-1)).toBe(true);
});
it.each(cases)('%s passes anyTag=false without it', async (_, hook, search) => {
renderHook(hook, {wrapper: makeWrapper()});
await act(async () => {});
expect(search).toHaveBeenCalled();
expect(search.mock.calls.at(-1).at(-1)).toBe(false);
});
});