@internetarchive/radio-player 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +26 -1
- package/package.json +1 -1
- package/lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-delegate.d.ts +0 -9
- package/lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-delegate.js +0 -1
- package/lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-delegate.js.map +0 -1
- package/lib/src/search-handler/search-index.d.ts +0 -53
- package/lib/src/search-handler/search-index.js +0 -118
- package/lib/src/search-handler/search-index.js.map +0 -1
package/index.d.ts
CHANGED
|
@@ -1,15 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TranscriptConfig,
|
|
3
|
+
TranscriptEntryConfig
|
|
4
|
+
} from '@internetarchive/transcript-view';
|
|
5
|
+
import { AudioSource } from '@internetarchive/audio-element';
|
|
6
|
+
|
|
1
7
|
import RadioPlayer from './lib/src/radio-player.d';
|
|
2
8
|
import SearchResultsSwitcher from './lib/src/search-results-switcher.d';
|
|
3
9
|
import MusicZone from './lib/src/models/music-zone.d';
|
|
4
10
|
import RadioPlayerConfig from './lib/src/models/radio-player-config.d';
|
|
11
|
+
import { SearchHandler } from './lib/src/search-handler/search-handler.d';
|
|
12
|
+
import { LocalSearchBackend } from './lib/src/search-handler/search-backends/local-search-backend/local-search-backend.d';
|
|
13
|
+
import { FullTextSearchBackend } from './lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-backend.d';
|
|
14
|
+
import { TranscriptIndex } from './lib/src/search-handler/transcript-index.d';
|
|
15
|
+
import {
|
|
16
|
+
FullTextSearchResponse,
|
|
17
|
+
FullTextSearchResponseDoc
|
|
18
|
+
} from './lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-response.d';
|
|
5
19
|
import { FullTextSearchServiceInterface } from './lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-service-interface.d';
|
|
6
20
|
import { SearchBackendInterface } from './lib/src/search-handler/search-backends/search-backend-interface.d';
|
|
21
|
+
import { SearchHandlerInterface } from './lib/src/search-handler/search-handler-interface.d';
|
|
7
22
|
|
|
8
23
|
export {
|
|
9
24
|
RadioPlayer,
|
|
10
25
|
SearchResultsSwitcher,
|
|
11
26
|
MusicZone,
|
|
12
27
|
RadioPlayerConfig,
|
|
28
|
+
TranscriptConfig,
|
|
29
|
+
TranscriptEntryConfig,
|
|
30
|
+
AudioSource,
|
|
31
|
+
SearchHandler,
|
|
32
|
+
LocalSearchBackend,
|
|
33
|
+
FullTextSearchBackend,
|
|
34
|
+
TranscriptIndex,
|
|
35
|
+
FullTextSearchResponse,
|
|
36
|
+
FullTextSearchResponseDoc,
|
|
13
37
|
FullTextSearchServiceInterface,
|
|
14
|
-
SearchBackendInterface
|
|
38
|
+
SearchBackendInterface,
|
|
39
|
+
SearchHandlerInterface
|
|
15
40
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { FullTextSearchResponse } from './full-text-search-response';
|
|
2
|
-
/**
|
|
3
|
-
* The `FullTextSearchDelegate` allows the `FullTextSearchBackend` to hand off
|
|
4
|
-
* the network request to the consumer. This allows alternatives to AJAX calls
|
|
5
|
-
* for other consumers like the DWeb project.
|
|
6
|
-
*/
|
|
7
|
-
export interface FullTextSearchDelegate {
|
|
8
|
-
searchRequested(query: string): Promise<FullTextSearchResponse>;
|
|
9
|
-
}
|
package/lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-delegate.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// # sourceMappingURL=full-text-search-delegate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"full-text-search-delegate.js","sourceRoot":"","sources":["../../../../../src/search-handler/search-backends/full-text-search-backend/full-text-search-delegate.ts"],"names":[],"mappings":""}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { TranscriptConfig } from '@internetarchive/transcript-view';
|
|
2
|
-
import { Range, TranscriptEntryRange } from './search-models';
|
|
3
|
-
export declare class SearchIndex {
|
|
4
|
-
/**
|
|
5
|
-
* Make these properties readonly. We don't want outside classes touching the private storage.
|
|
6
|
-
*
|
|
7
|
-
* @readonly
|
|
8
|
-
* @type {string}
|
|
9
|
-
* @memberof SearchIndex
|
|
10
|
-
*/
|
|
11
|
-
get mergedTranscript(): string;
|
|
12
|
-
get transcriptEntryRanges(): TranscriptEntryRange[];
|
|
13
|
-
/**
|
|
14
|
-
* This gets populated as part of the search index build. It merges all of the transcript
|
|
15
|
-
* entries together so we can search it as a single document instead of a bunch of
|
|
16
|
-
* individual entries. This allows searches to cross over transcript entries.
|
|
17
|
-
*
|
|
18
|
-
* It also indexes the entries so we can quickly look them up later.
|
|
19
|
-
*
|
|
20
|
-
* @private
|
|
21
|
-
* @memberof SearchIndex
|
|
22
|
-
*/
|
|
23
|
-
private searchIndexCache;
|
|
24
|
-
/**
|
|
25
|
-
* Find the closes TranscriptEntryRange to the given overallCharIndex
|
|
26
|
-
*
|
|
27
|
-
* @param overallCharIndex
|
|
28
|
-
* @returns {TranscriptEntryRange | undefined}
|
|
29
|
-
*/
|
|
30
|
-
getTranscriptEntryAt(overallCharIndex: number): TranscriptEntryRange | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Finds all of the ranges of all the search results across the entire transcript.
|
|
33
|
-
*
|
|
34
|
-
* @private
|
|
35
|
-
* @param {string} term
|
|
36
|
-
* @returns {Range[]}
|
|
37
|
-
* @memberof SearchIndex
|
|
38
|
-
*/
|
|
39
|
-
getSearchRanges(term: string): Range[];
|
|
40
|
-
constructor(transcriptConfig: TranscriptConfig);
|
|
41
|
-
/**
|
|
42
|
-
* Build the search index. This method does two things:
|
|
43
|
-
* 1. Builds the "merged transcript" with all of the text combined into one long transcript.
|
|
44
|
-
* This allows us to search the entire thing at once instead of entry by entry.
|
|
45
|
-
* 2. For each entry, get the start and end index of that particular entry within the overall
|
|
46
|
-
* transcript. This allows us to reconstruct the transcript later from the original transcript
|
|
47
|
-
* and the search results.
|
|
48
|
-
*
|
|
49
|
-
* @private
|
|
50
|
-
* @memberof SearchHandler
|
|
51
|
-
*/
|
|
52
|
-
private buildIndex;
|
|
53
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { Range, TranscriptEntryRange } from './search-models';
|
|
2
|
-
class SearchIndexCache {
|
|
3
|
-
constructor(mergedTranscript = '', transcriptEntryRanges = []) {
|
|
4
|
-
/**
|
|
5
|
-
* This gets populated as part of the search index build. It merges all of the transcript
|
|
6
|
-
* entries together so we can search it as a single document instead of a bunch of
|
|
7
|
-
* individual entries. This allows searches to cross over transcript entries.
|
|
8
|
-
*
|
|
9
|
-
* NOTE: When the mergedTranscript gets created, spaces are put between each transcript
|
|
10
|
-
* entry, otherwise the words would run into each other. We account for this in the
|
|
11
|
-
* indices above.
|
|
12
|
-
*
|
|
13
|
-
* @type {string}
|
|
14
|
-
* @memberof SearchIndexCache
|
|
15
|
-
*/
|
|
16
|
-
this.mergedTranscript = '';
|
|
17
|
-
this.mergedTranscriptLowercased = '';
|
|
18
|
-
/**
|
|
19
|
-
* This gets populated as part of the search index build. It maps the start and end indicies
|
|
20
|
-
* of all of the transcript entries so we can quickly look up where an entry is in the
|
|
21
|
-
* overall transcript.
|
|
22
|
-
*
|
|
23
|
-
* @type {TranscriptEntryRange[]}
|
|
24
|
-
* @memberof SearchIndexCache
|
|
25
|
-
*/
|
|
26
|
-
this.transcriptEntryRanges = [];
|
|
27
|
-
this.mergedTranscript = mergedTranscript;
|
|
28
|
-
this.transcriptEntryRanges = transcriptEntryRanges;
|
|
29
|
-
this.mergedTranscriptLowercased = mergedTranscript.toLowerCase();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export class SearchIndex {
|
|
33
|
-
constructor(transcriptConfig) {
|
|
34
|
-
/**
|
|
35
|
-
* This gets populated as part of the search index build. It merges all of the transcript
|
|
36
|
-
* entries together so we can search it as a single document instead of a bunch of
|
|
37
|
-
* individual entries. This allows searches to cross over transcript entries.
|
|
38
|
-
*
|
|
39
|
-
* It also indexes the entries so we can quickly look them up later.
|
|
40
|
-
*
|
|
41
|
-
* @private
|
|
42
|
-
* @memberof SearchIndex
|
|
43
|
-
*/
|
|
44
|
-
this.searchIndexCache = new SearchIndexCache();
|
|
45
|
-
this.buildIndex(transcriptConfig);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Make these properties readonly. We don't want outside classes touching the private storage.
|
|
49
|
-
*
|
|
50
|
-
* @readonly
|
|
51
|
-
* @type {string}
|
|
52
|
-
* @memberof SearchIndex
|
|
53
|
-
*/
|
|
54
|
-
get mergedTranscript() {
|
|
55
|
-
return this.searchIndexCache.mergedTranscript;
|
|
56
|
-
}
|
|
57
|
-
get transcriptEntryRanges() {
|
|
58
|
-
return this.searchIndexCache.transcriptEntryRanges;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Find the closes TranscriptEntryRange to the given overallCharIndex
|
|
62
|
-
*
|
|
63
|
-
* @param overallCharIndex
|
|
64
|
-
* @returns {TranscriptEntryRange | undefined}
|
|
65
|
-
*/
|
|
66
|
-
getTranscriptEntryAt(overallCharIndex) {
|
|
67
|
-
return this.searchIndexCache.transcriptEntryRanges.find(entry => {
|
|
68
|
-
const { range } = entry;
|
|
69
|
-
return range.endIndex > overallCharIndex && range.startIndex <= overallCharIndex;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Finds all of the ranges of all the search results across the entire transcript.
|
|
74
|
-
*
|
|
75
|
-
* @private
|
|
76
|
-
* @param {string} term
|
|
77
|
-
* @returns {Range[]}
|
|
78
|
-
* @memberof SearchIndex
|
|
79
|
-
*/
|
|
80
|
-
getSearchRanges(term) {
|
|
81
|
-
const ranges = [];
|
|
82
|
-
const termLowerCased = term.toLowerCase();
|
|
83
|
-
let index = -1;
|
|
84
|
-
/* eslint-disable-next-line no-cond-assign */
|
|
85
|
-
while ((index = this.searchIndexCache.mergedTranscriptLowercased.indexOf(termLowerCased, index + 1)) !== -1) {
|
|
86
|
-
const newRange = new Range(index, index + termLowerCased.length);
|
|
87
|
-
ranges.push(newRange);
|
|
88
|
-
}
|
|
89
|
-
return ranges;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Build the search index. This method does two things:
|
|
93
|
-
* 1. Builds the "merged transcript" with all of the text combined into one long transcript.
|
|
94
|
-
* This allows us to search the entire thing at once instead of entry by entry.
|
|
95
|
-
* 2. For each entry, get the start and end index of that particular entry within the overall
|
|
96
|
-
* transcript. This allows us to reconstruct the transcript later from the original transcript
|
|
97
|
-
* and the search results.
|
|
98
|
-
*
|
|
99
|
-
* @private
|
|
100
|
-
* @memberof SearchHandler
|
|
101
|
-
*/
|
|
102
|
-
buildIndex(transcriptConfig) {
|
|
103
|
-
let startIndex = 0;
|
|
104
|
-
const transcriptEntryRanges = [];
|
|
105
|
-
let mergedTranscript = '';
|
|
106
|
-
transcriptConfig.entries.forEach((entry) => {
|
|
107
|
-
const { displayText } = entry;
|
|
108
|
-
const indexMapRange = new Range(startIndex, startIndex + displayText.length);
|
|
109
|
-
const indexMap = new TranscriptEntryRange(entry, indexMapRange);
|
|
110
|
-
transcriptEntryRanges.push(indexMap);
|
|
111
|
-
mergedTranscript += `${entry.displayText} `;
|
|
112
|
-
startIndex = mergedTranscript.length;
|
|
113
|
-
});
|
|
114
|
-
mergedTranscript = mergedTranscript.trim();
|
|
115
|
-
this.searchIndexCache = new SearchIndexCache(mergedTranscript, transcriptEntryRanges);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
//# sourceMappingURL=search-index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search-index.js","sourceRoot":"","sources":["../../../src/search-handler/search-index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE9D,MAAM,gBAAg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