Skip to content

Commit

Permalink
feat:搜索结果中增加排除功能
Browse files Browse the repository at this point in the history
  • Loading branch information
manone2077 authored and fzlins committed Jan 14, 2025
1 parent a274eca commit 73a0c32
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions resource/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@
"reSearch": "Re-search",
"showCategory": "Category",
"filterSearchResults": "Filter search results",
"filterSearchResultsExclude": "Exclude search results",
"noResultsSites": "Site with 0 result:",
"failedSites": "Failed site:",
"reSearchFailedSites": "Re-search failed site",
Expand Down
1 change: 1 addition & 0 deletions resource/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
"reSearch": "重新再搜索",
"showCategory": "分类",
"filterSearchResults": "过滤搜索结果",
"filterSearchResultsExclude": "排除指定词的搜索结果",
"noResultsSites": "无结果站点:",
"failedSites": "失败站点:",
"reSearchFailedSites": "重试失败的站点",
Expand Down
36 changes: 17 additions & 19 deletions src/options/views/search/SearchTorrent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default Vue.extend({
siteContentMenus: {} as any,
clientContentMenus: [] as any,
filterKey: "",
filterKeyExclude: "",
// 已过滤的数据
filteredDatas: [] as any,
showFailedSites: false,
Expand Down Expand Up @@ -1785,26 +1786,23 @@ export default Vue.extend({
* @param items
* @param search
*/
searchResultFilter(items: any[], search: string) {
search = search.toString().toLowerCase();
this.filteredDatas = [];
if (search.trim() === "") return items;

// 以空格分隔要过滤的关键字
let searchs = search.split(" ");

this.filteredDatas = items.filter((item: SearchResultItem) => {
// 过滤标题和副标题
let source = (item.title + (item.subTitle || "")).toLowerCase();
let result = true;
searchs.forEach((key) => {
if (key.trim() != "") {
result = result && source.indexOf(key) > -1;
}
});
return result;
searchResultFilter(items:any[], search:string) {
// 将输入参数拆分为包含和排除关键字
const [include, exclude] = search.split("<@>");
const includes = include.toLowerCase().trim().split(" ").filter(key => key !== "");
const excludes = exclude.toLowerCase().trim().split(" ").filter(key => key !== "");

// 过滤数据项
const filteredItems = items.filter(item => {
// 将项目标题和副标题组合并转化为小写
const source = (item.title + (item.subTitle || "")).toLowerCase();

const includeResult = includes.length === 0 || includes.some(key => source.includes(key));
const excludeResult = excludes.length === 0 || !excludes.some(key => source.includes(key));

return includeResult && excludeResult;
});
return this.filteredDatas;
return filteredItems;
},

getIMDbIdFromDouban(doubanId: string) {
Expand Down
11 changes: 10 additions & 1 deletion src/options/views/search/SearchTorrent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,15 @@
hide-details
enterkeyhint="search"
></v-text-field>

<v-text-field
v-model="filterKeyExclude"
append-icon="block"
:label="$t('searchTorrent.filterSearchResultsExclude')"
single-line
hide-details
enterkeyhint="search"
></v-text-field>
</div>
</v-flex>
</v-card-title>
Expand Down Expand Up @@ -517,7 +526,7 @@
<!-- 数据表格 -->
<v-data-table
v-model="selected"
:search="filterKey"
:search="filterKey+'<@>'+filterKeyExclude"
:custom-filter="searchResultFilter"
:headers="headers"
:items="datas"
Expand Down

0 comments on commit 73a0c32

Please sign in to comment.