Add type filter
This commit is contained in:
@ -26,6 +26,7 @@ export interface PubSubData {
|
||||
image: string
|
||||
content: string
|
||||
readingProgressPercent: number
|
||||
pageType: string
|
||||
}
|
||||
|
||||
enum EntityType {
|
||||
|
||||
@ -42,7 +42,7 @@ const parseSearchFilter = (filter: string): SearchFilter[] => {
|
||||
}
|
||||
|
||||
const parsed = parse(searchFilter, {
|
||||
keywords: ['subscription', 'content', 'is'],
|
||||
keywords: ['subscription', 'content', 'is', 'type'],
|
||||
tokenize: true,
|
||||
})
|
||||
if (parsed.offsets) {
|
||||
@ -51,15 +51,21 @@ const parseSearchFilter = (filter: string): SearchFilter[] => {
|
||||
.map((offset) => offset as SearchParserKeyWordOffset)
|
||||
|
||||
for (const keyword of keywords) {
|
||||
if (!keyword.value) {
|
||||
continue
|
||||
}
|
||||
switch (keyword.keyword) {
|
||||
case 'subscription':
|
||||
keyword.value && result.push(new SubscriptionFilter(keyword.value))
|
||||
result.push(new SubscriptionFilter(keyword.value))
|
||||
break
|
||||
case 'content':
|
||||
keyword.value && result.push(new ContentFilter(keyword.value))
|
||||
result.push(new ContentFilter(keyword.value))
|
||||
break
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
12
packages/rule-handler/src/search_filter/type_filter.ts
Normal file
12
packages/rule-handler/src/search_filter/type_filter.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user