Add type filter

This commit is contained in:
Hongbo Wu
2022-11-23 17:41:09 +08:00
parent ffd7259523
commit 52b1cb8cfa
3 changed files with 23 additions and 4 deletions

View File

@ -26,6 +26,7 @@ export interface PubSubData {
image: string image: string
content: string content: string
readingProgressPercent: number readingProgressPercent: number
pageType: string
} }
enum EntityType { enum EntityType {

View File

@ -42,7 +42,7 @@ const parseSearchFilter = (filter: string): SearchFilter[] => {
} }
const parsed = parse(searchFilter, { const parsed = parse(searchFilter, {
keywords: ['subscription', 'content', 'is'], keywords: ['subscription', 'content', 'is', 'type'],
tokenize: true, tokenize: true,
}) })
if (parsed.offsets) { if (parsed.offsets) {
@ -51,15 +51,21 @@ const parseSearchFilter = (filter: string): SearchFilter[] => {
.map((offset) => offset as SearchParserKeyWordOffset) .map((offset) => offset as SearchParserKeyWordOffset)
for (const keyword of keywords) { for (const keyword of keywords) {
if (!keyword.value) {
continue
}
switch (keyword.keyword) { switch (keyword.keyword) {
case 'subscription': case 'subscription':
keyword.value && result.push(new SubscriptionFilter(keyword.value)) result.push(new SubscriptionFilter(keyword.value))
break break
case 'content': case 'content':
keyword.value && result.push(new ContentFilter(keyword.value)) result.push(new ContentFilter(keyword.value))
break break
case 'is': case 'is':
keyword.value && result.push(new ReadFilter(keyword.value)) result.push(new ReadFilter(keyword.value))
break
case 'type':
result.push(new ReadFilter(keyword.value))
break break
} }
} }

View File

@ -0,0 +1,12 @@
import { SearchFilter } from './index'
import { PubSubData } from '../index'
export class TypeFilter extends SearchFilter {
public isValid(data: PubSubData): boolean {
if (!data.pageType) {
return false
}
return this.query === '*' || data.pageType === this.query
}
}