web: parse search type prefixes into kind filters
This commit is contained in:
@@ -42,6 +42,27 @@ export const SEARCH_KINDS = [
|
||||
/** The default, no-narrowing kind. */
|
||||
export const DEFAULT_SEARCH_KIND = "";
|
||||
|
||||
/** Unquoted, whitespace-delimited t:/type: tokens; last supported token wins.
|
||||
* Unknown tokens and quoted text stay literal, including their whitespace.
|
||||
* The selector is a fallback; explicitly changing it removes tokens in the view.
|
||||
*/
|
||||
export function parseSearchQuery(value, selectedKind = DEFAULT_SEARCH_KIND) {
|
||||
const source = String(value ?? "");
|
||||
let kind = selectedKind;
|
||||
let hasType = false;
|
||||
const query = source.replace(/(?:[^\s"'\\]|\\[\s\S]|"(?:[^"\\]|\\[\s\S])*(?:"|$)|'(?:[^'\\]|\\[\s\S])*(?:'|$))+/g, (token) => {
|
||||
const match = /^(?:t|type):([a-z]+)$/i.exec(token);
|
||||
const candidate = match?.[1].toLowerCase();
|
||||
if (!candidate || !SEARCH_KINDS.some((option) => option.value === candidate)) return token;
|
||||
kind = candidate;
|
||||
hasType = true;
|
||||
return "";
|
||||
});
|
||||
return { query, kind, hasType };
|
||||
}
|
||||
|
||||
export const SEARCH_TYPE_HELP = "Add search text after the type filter (for example, t:pipeline plan). This server does not list results by type alone.";
|
||||
|
||||
/**
|
||||
* The orders the search sort control offers. "Relevance" keeps the server's own
|
||||
* ranking (score, then recency, then a stable kind/target tie-break); "Newest
|
||||
|
||||
Reference in New Issue
Block a user