mateclaw/mateclaw-server/src/main/java/vip/mate/tool/search/SearchQuery.java

43 lines
1.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package vip.mate.tool.search;
/**
* 搜索查询参数封装 — 借鉴 openclaw 的丰富工具参数设计
*
* @param query 搜索关键词(必须)
* @param freshness 时间范围过滤day / week / month / year可选
* @param language 语言偏好zh-CN / en / auto可选
* @param count 最大结果数1-10默认 5可选
*
* @author MateClaw Team
*/
public record SearchQuery(
String query,
String freshness,
String language,
Integer count
) {
private static final int DEFAULT_COUNT = 5;
private static final int MAX_COUNT = 10;
/** 从裸 query 字符串构建(向后兼容) */
public static SearchQuery of(String query) {
return new SearchQuery(query, null, null, null);
}
/** 获取 count带默认值和上界限制 */
public int resolvedCount() {
if (count == null || count <= 0) return DEFAULT_COUNT;
return Math.min(count, MAX_COUNT);
}
/** freshness 是否有效 */
public boolean hasFreshness() {
return freshness != null && !freshness.isBlank();
}
/** language 是否有效 */
public boolean hasLanguage() {
return language != null && !language.isBlank() && !"auto".equalsIgnoreCase(language);
}
}