Skip to content

Commit 1d73648

Browse files
committed
Merge branch 'feature/mobile-search' into hotfix/3.19.52
# Conflicts: # external/@worldbrain/memex-common
2 parents 4f4708e + 5c26489 commit 1d73648

File tree

16 files changed

+49
-278
lines changed

16 files changed

+49
-278
lines changed

src/copy-paster/AnnotationSearchCopyPaster.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import CopyPaster, { Props as CopyPasterProps } from './CopyPaster'
3-
import type { UnifiedSearchParams } from 'src/search/background/types'
43
import type { Template } from './types'
4+
import type { UnifiedSearchParams } from '@worldbrain/memex-common/lib/search/types'
55

66
export interface Props
77
extends Omit<CopyPasterProps, 'renderTemplate' | 'renderPreview'> {

src/copy-paster/PageSearchCopyPaster.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import CopyPaster, { Props as CopyPasterProps } from './CopyPaster'
3-
import type { UnifiedSearchParams } from 'src/search/background/types'
43
import type { Template } from './types'
4+
import type { UnifiedSearchParams } from '@worldbrain/memex-common/lib/search/types'
55

66
export interface Props
77
extends Omit<CopyPasterProps, 'renderTemplate' | 'renderPreview'> {

src/copy-paster/background/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Template } from '../types'
2-
import type { UnifiedSearchParams } from 'src/search/background/types'
2+
import type { UnifiedSearchParams } from '@worldbrain/memex-common/lib/search/types'
33

44
export interface RemoteCopyPasterInterface {
55
createTemplate(args: Omit<Template, 'id'>): Promise<number>

src/dashboard-refactor/logic.test.util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const setPageSearchResult: DataSeederCreator<StandardSearchResponse> = (
5454
await storageManager.collection('annotations').createObject({
5555
...annot,
5656
})
57-
if (annot.isShared) {
57+
if (annot['isShared']) {
5858
await storageManager
5959
.collection('sharedAnnotationMetadata')
6060
.createObject({
@@ -68,7 +68,7 @@ export const setPageSearchResult: DataSeederCreator<StandardSearchResponse> = (
6868
id: idCounter++,
6969
annotation: annot.url,
7070
createdWhen: new Date(),
71-
privacyLevel: annot.isBulkShareProtected
71+
privacyLevel: annot['isBulkShareProtected']
7272
? AnnotationPrivacyLevels.SHARED_PROTECTED
7373
: AnnotationPrivacyLevels.SHARED,
7474
})

src/dashboard-refactor/logic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ export class DashboardLogic extends UILogic<State, Events> {
15811581
byId: {
15821582
[event.noteId]: {
15831583
comment: { $set: existing.comment },
1584-
color: { $set: event.color as RGBAColor },
1584+
color: { $set: event.color as string },
15851585
},
15861586
},
15871587
},
@@ -3674,7 +3674,7 @@ export class DashboardLogic extends UILogic<State, Events> {
36743674
lists: { $set: nextLists },
36753675
color: {
36763676
$set: (event.color ??
3677-
existing.color) as RGBAColor,
3677+
existing.color) as string,
36783678
},
36793679
},
36803680
},

src/dashboard-refactor/search-results/components/search-copy-paster.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
PageSearchCopyPaster,
77
} from 'src/copy-paster'
88
import { SearchType } from '../types'
9-
import { UnifiedSearchParams } from 'src/search/background/types'
9+
import type { UnifiedSearchParams } from '@worldbrain/memex-common/lib/search/types'
1010
import Icon from '@worldbrain/memex-common/lib/common-ui/components/icon'
1111
import { PopoutBox } from '@worldbrain/memex-common/lib/common-ui/components/popout-box'
1212
import { TooltipBox } from '@worldbrain/memex-common/lib/common-ui/components/tooltip-box'

src/dashboard-refactor/search-results/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import { RemoteSyncSettingsInterface } from 'src/sync-settings/background/types'
6565
import TutorialBox from '@worldbrain/memex-common/lib/common-ui/components/tutorial-box'
6666
import { SpaceSearchSuggestion } from '@worldbrain/memex-common/lib/editor'
6767
import type { HighlightColor } from '@worldbrain/memex-common/lib/common-ui/components/highlightColorPicker/types'
68-
import { splitQueryIntoTerms } from 'src/search/background/utils'
68+
import { splitQueryIntoTerms } from '@worldbrain/memex-common/lib/search/terms-search'
6969

7070
const timestampToString = (timestamp: number) =>
7171
timestamp === -1 ? undefined : formatDayGroupTime(timestamp)

src/dashboard-refactor/search-results/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export interface NoteData {
142142
selector?: Anchor
143143
isShared?: boolean
144144
isBulkShareProtected?: boolean
145-
color?: RGBAColor
145+
color?: string
146146
isInFocus?: boolean
147147
}
148148

src/dashboard-refactor/search-results/util.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type {
22
StandardSearchResponse,
33
SearchResultPage,
4-
UnifiedSearchPaginationParams,
54
SearchResultAnnotation,
65
} from 'src/search/background/types'
6+
import type { UnifiedSearchPaginationParams } from '@worldbrain/memex-common/lib/search/types'
77
import type {
88
PageData,
99
PageResult,
@@ -177,12 +177,12 @@ const annotationToNoteData = (
177177
return {
178178
url: annotation.url,
179179
pageUrl: annotation.pageUrl,
180-
highlight: annotation.body,
180+
highlight: annotation['body'],
181181
comment: annotation.comment,
182-
tags: annotation.tags ?? [],
182+
tags: [],
183183
lists,
184-
selector: annotation.selector,
185-
color: annotation.color as RGBAColor,
184+
selector: annotation['selector'],
185+
color: annotation['color'],
186186
createdWhen: annotation.createdWhen,
187187
displayTime: new Date(
188188
annotation.lastEdited ?? annotation.createdWhen,
@@ -193,8 +193,8 @@ const annotationToNoteData = (
193193
...getInitialNoteResultState(),
194194
editNoteForm: {
195195
inputValue: annotation.comment ?? '',
196-
bodyInputValue: annotation.body ?? '',
197-
tags: annotation.tags ?? [],
196+
bodyInputValue: annotation['body'] ?? '',
197+
tags: [],
198198
lists,
199199
isTagPickerShown: false,
200200
isListPickerShown: false,

src/dashboard-refactor/util.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ import type {
33
TermsSearchOpts,
44
UnifiedSearchPaginationParams,
55
UnifiedSearchParams,
6-
} from 'src/search/background/types'
7-
import type { PageResult } from './search-results/types'
8-
import {
9-
initNormalizedState,
10-
NormalizedState,
11-
} from '@worldbrain/memex-common/lib/common-ui/utils/normalized-state'
12-
import { EVENT_PROVIDER_DOMAINS } from '@worldbrain/memex-common/lib/constants'
6+
} from '@worldbrain/memex-common/lib/search/types'
137
import type {
148
PageAnnotationsCacheInterface,
159
UnifiedList,

src/search/background/index.ts

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@ import { makeRemotelyCallable } from 'src/util/webextensionRPC'
77
import type {
88
RemoteSearchInterface,
99
SearchResultPage,
10-
UnifiedSearchParams,
1110
UnifiedBlankSearchParams,
12-
UnifiedTermsSearchParams,
11+
UnifiedSearchLookupData,
12+
} from './types'
13+
import type {
1314
ResultDataByPage,
15+
UnifiedSearchParams,
1416
IntermediarySearchResult,
1517
UnifiedSearchPaginationParams,
16-
UnifiedSearchLookupData,
17-
} from './types'
18+
} from '@worldbrain/memex-common/lib/search/types'
19+
import {
20+
needToFilterSearchByUrl,
21+
sortSearchResult,
22+
} from '@worldbrain/memex-common/lib/search/utils'
23+
import {
24+
splitQueryIntoTerms,
25+
unifiedTermsSearch,
26+
} from '@worldbrain/memex-common/lib/search/terms-search'
1827
import { SearchError, BadTermError } from './errors'
1928
import type { PageIndexingBackground } from 'src/page-indexing/background'
2029
import {
@@ -37,14 +46,7 @@ import type {
3746
Visit,
3847
FavIcon,
3948
} from '@worldbrain/memex-common/lib/types/core-data-types/client'
40-
import {
41-
sortSearchResult,
42-
queryAnnotationsByTerms,
43-
queryPagesByTerms,
44-
splitQueryIntoTerms,
45-
sliceSearchResult,
46-
needToFilterSearchByUrl,
47-
} from './utils'
49+
import { queryAnnotationsByTerms, queryPagesByTerms } from './utils'
4850
import { AnnotationPrivacyLevels } from '@worldbrain/memex-common/lib/annotations/types'
4951
import { SPECIAL_LIST_IDS } from '@worldbrain/memex-common/lib/storage/modules/lists/constants'
5052
import {
@@ -678,53 +680,6 @@ export default class SearchBackground {
678680
}
679681
}
680682

681-
private async unifiedTermsSearch(
682-
params: UnifiedTermsSearchParams,
683-
): Promise<IntermediarySearchResult> {
684-
const resultDataByPage: ResultDataByPage = new Map()
685-
686-
const [pages, annotations] = await Promise.all([
687-
params.queryPages(params.terms, params.phrases),
688-
params.queryAnnotations(params.terms, params.phrases),
689-
])
690-
691-
// Add in all the annotations to the results
692-
const annotsByPage = groupBy(annotations, (a) => a.pageUrl)
693-
for (const [pageId, annots] of Object.entries(annotsByPage)) {
694-
const sortedAnnots = annots.sort(
695-
(a, b) => b.lastEdited.valueOf() - a.lastEdited.valueOf(),
696-
)
697-
resultDataByPage.set(pageId, {
698-
annotations: sortedAnnots,
699-
// This gets overwritten in the next loop by the latest visit/bookmark time (if exist in this results "page")
700-
latestPageTimestamp: sortedAnnots[0].lastEdited.valueOf(),
701-
oldestTimestamp: 0,
702-
})
703-
}
704-
705-
// Add in all the pages to the results
706-
for (const { id, latestTimestamp } of pages) {
707-
const annotations = resultDataByPage.get(id)?.annotations ?? []
708-
resultDataByPage.set(id, {
709-
annotations,
710-
latestPageTimestamp: latestTimestamp,
711-
oldestTimestamp: 0,
712-
})
713-
}
714-
715-
await this.filterUnifiedSearchResultsByFilters(resultDataByPage, params)
716-
717-
// Paginate!
718-
const sortedResultPages = sortSearchResult(resultDataByPage)
719-
const paginatedResults = sliceSearchResult(sortedResultPages, params)
720-
721-
return {
722-
oldestResultTimestamp: null,
723-
resultDataByPage: paginatedResults,
724-
resultsExhausted: paginatedResults.size < params.limit,
725-
}
726-
}
727-
728683
private async unifiedIntermediarySearch(
729684
params: UnifiedSearchParams & UnifiedSearchPaginationParams,
730685
): Promise<IntermediarySearchResult> {
@@ -781,8 +736,9 @@ export default class SearchBackground {
781736
params.phrases = phrases
782737
params.terms = terms
783738
params.matchTermsFuzzyStartsWith = matchTermsFuzzyStartsWith
784-
return this.unifiedTermsSearch({
739+
return unifiedTermsSearch({
785740
...params,
741+
storageManager: this.options.storageManager,
786742
queryPages: queryPagesByTerms(this.options.storageManager, params),
787743
queryAnnotations: queryAnnotationsByTerms(
788744
this.options.storageManager,

src/search/background/types.ts

Lines changed: 8 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import type { User } from 'src/social-integration/types'
21
import type SearchStorage from './storage'
3-
import type { Annotation } from 'src/annotations/types'
42
import type { PageIndexingBackground } from 'src/page-indexing/background'
5-
import type { Annotation as _Annotation } from '@worldbrain/memex-common/lib/types/core-data-types/client'
3+
import type { Annotation } from '@worldbrain/memex-common/lib/types/core-data-types/client'
64
import type { AnnotationPrivacyLevels } from '@worldbrain/memex-common/lib/annotations/types'
5+
import type {
6+
UnifiedSearchParams,
7+
UnifiedSearchPaginationParams,
8+
} from '@worldbrain/memex-common/lib/search/types'
79

810
export type SearchResultAnnotation = Annotation & {
911
lists: number[]
@@ -25,6 +27,9 @@ export interface SearchResultPage {
2527
text: string
2628
}
2729

30+
/**
31+
* @deprecated
32+
*/
2833
export interface AnnotSearchParams {
2934
/** Main text to search against annot (pre-processed). */
3035
query?: string
@@ -73,13 +78,6 @@ export interface AnnotsByPageUrl {
7378
[pageUrl: string]: Annotation[]
7479
}
7580

76-
export interface SocialSearchParams extends AnnotSearchParams {
77-
usersInc?: User[]
78-
usersExc?: User[]
79-
hashtagsInc?: string[]
80-
hashtagsExc?: string[]
81-
}
82-
8381
export interface StandardSearchResponse {
8482
resultsExhausted: boolean
8583
totalCount?: number
@@ -103,47 +101,6 @@ export interface RemoteSearchInterface {
103101
}>
104102
}
105103

106-
export type UnifiedSearchParams = TermsSearchOpts & {
107-
query: string
108-
terms?: string[]
109-
phrases?: string[]
110-
fromWhen?: number
111-
untilWhen?: number
112-
filterByDomains: string[]
113-
filterByListIds: number[]
114-
filterByPDFs?: boolean
115-
filterByVideos?: boolean
116-
filterByTweets?: boolean
117-
filterByEvents?: boolean
118-
omitPagesWithoutAnnotations?: boolean
119-
}
120-
121-
export interface TermsSearchOpts {
122-
/** Set to enable fuzzy startsWith terms matching, instead of exact match. */
123-
matchTermsFuzzyStartsWith?: boolean
124-
matchPageText?: boolean
125-
matchPageTitleUrl?: boolean
126-
matchHighlights?: boolean
127-
matchNotes?: boolean
128-
}
129-
130-
export interface UnifiedSearchPaginationParams {
131-
skip: number
132-
limit: number
133-
}
134-
135-
export type UnifiedTermsSearchParams = UnifiedSearchParams &
136-
UnifiedSearchPaginationParams & {
137-
queryPages: (
138-
terms: string[],
139-
phrases?: string[],
140-
) => Promise<Array<{ id: string; latestTimestamp: number }>>
141-
queryAnnotations: (
142-
terms: string[],
143-
phrases?: string[],
144-
) => Promise<_Annotation[]>
145-
}
146-
147104
/**
148105
* Note that, unlike terms search, blank search does not use the traditional pagination params.
149106
* Instead it expects the caller to keep a state of the oldest search result so far
@@ -164,29 +121,6 @@ export type UnifiedSearchResult = {
164121
oldestResultTimestamp: number
165122
}
166123

167-
export type IntermediarySearchResult = {
168-
resultsExhausted: boolean
169-
resultDataByPage: ResultDataByPage
170-
/** Always null for terms search. */
171-
oldestResultTimestamp: number | null
172-
}
173-
174-
export type ResultDataByPage = Map<string, UnifiedSearchPageResultData>
175-
176-
export type UnifiedSearchPageResultData = {
177-
annotations: Annotation[]
178-
/**
179-
* Contains the latest timestamp associated with the page bookmark or visits. Not annotation.
180-
* Used primarily for sorting and display in UI.
181-
*/
182-
latestPageTimestamp: number
183-
/**
184-
* Contains the oldest timestamp associated with the page, including bookmarks, visits, or annotations.
185-
* Used for paging back through blank search results (oldest timestamp of batch N is the upper bound for batch N+1)
186-
*/
187-
oldestTimestamp: number
188-
}
189-
190124
export type UnifiedSearchLookupData = {
191125
pages: Map<string, Omit<SearchResultPage, 'annotations' | 'hasBookmark'>>
192126
annotations: Map<string, SearchResultAnnotation>

src/search/background/unified-search.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import omit from 'lodash/omit'
22
import type Storex from '@worldbrain/storex'
33
import * as DATA from './unified-search.test.data'
44
import { setupBackgroundIntegrationTest } from 'src/tests/background-integration-tests'
5-
import { sortSearchResult, splitQueryIntoTerms } from './utils'
65
import type {
76
UnifiedSearchPaginationParams,
87
IntermediarySearchResult,
98
UnifiedSearchParams,
10-
} from './types'
9+
} from '@worldbrain/memex-common/lib/search/types'
1110
import type { BackgroundModules } from 'src/background-script/setup'
1211
import { AnnotationPrivacyLevels } from '@worldbrain/memex-common/lib/annotations/types'
12+
import { sortSearchResult } from '@worldbrain/memex-common/lib/search/utils'
13+
import { splitQueryIntoTerms } from '@worldbrain/memex-common/lib/search/terms-search'
1314

1415
async function insertTestData(storageManager: Storex) {
1516
for (const doc of Object.values(DATA.LISTS)) {

0 commit comments

Comments
 (0)