Skip to content

Commit

Permalink
refactor: Improve search functionality in paperStorage
Browse files Browse the repository at this point in the history
This commit refactors the search functionality in the paperStorage module to handle null or undefined values for the paper abstract.
  • Loading branch information
yueyueL committed Sep 8, 2024
1 parent 8619886 commit 51c755f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/renderer/storage/paperStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const paperStorage = {
async searchPapers(query: string) {
return db.papers.filter(paper =>
paper.title.toLowerCase().includes(query.toLowerCase()) ||
paper.abstract.toLowerCase().includes(query.toLowerCase())
(paper.abstract ?? '').toLowerCase().includes(query.toLowerCase())
).toArray()
},

Expand Down Expand Up @@ -178,7 +178,7 @@ export const paperStorage = {
if (searchQuery) {
collection = collection.filter(paper =>
paper.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
paper.abstract.toLowerCase().includes(searchQuery.toLowerCase())
(paper.abstract ?? '').toLowerCase().includes(searchQuery.toLowerCase())
)
}

Expand All @@ -197,7 +197,7 @@ export const paperStorage = {

if (tagFilter && tagFilter.length > 0) {
collection = collection.filter(paper =>
paper.tags && tagFilter.every(tag => paper.tags.includes(tag))
paper.tags !== undefined && tagFilter.every(tag => paper.tags!.includes(tag))
)
}

Expand Down Expand Up @@ -227,7 +227,7 @@ export const paperStorage = {
// Remove the tag from all papers
const papers = await db.papers.where('tags').anyOf(tag.name).toArray()
for (const paper of papers) {
const updatedTags = paper.tags.filter(t => t !== tag.name)
const updatedTags = paper.tags?.filter(t => t !== tag.name) ?? []
await db.papers.update(paper.id!, { tags: updatedTags })
}
})
Expand All @@ -239,7 +239,7 @@ export const paperStorage = {

const papers = await db.papers.where('tags').anyOf(tag.name).toArray()
for (const paper of papers) {
const updatedTags = paper.tags.filter(t => t !== tag.name)
const updatedTags = paper.tags?.filter(t => t !== tag.name) ?? []
await db.papers.update(paper.id!, { tags: updatedTags })
}
}
Expand Down
23 changes: 12 additions & 11 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,18 @@ export interface ChatboxAILicenseDetail {
export type ChatboxAIModel = 'chatboxai-3.5' | 'chatboxai-4'

export interface Paper {
id?: number;
title: string;
authors: string[];
url: string;
venue: string;
year: number;
source: string;
doi: string;
publisher?: string;
abstract?: string;
tags?: string[];
id?: number
title: string
authors: string[]
url: string
venue: string
year: number
source: string
doi: string
uniqueId?: string
publisher?: string
abstract?: string
tags?: string[]
}

// Add this new interface
Expand Down
3 changes: 0 additions & 3 deletions src/types/cheerio.d.ts

This file was deleted.

0 comments on commit 51c755f

Please sign in to comment.