@internetarchive/radio-player 0.0.3 → 0.0.4-alpha.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/LICENSE +661 -661
- package/README.md +142 -142
- package/index.d.ts +15 -15
- package/index.js +28 -28
- package/lib/demo/full-text-search-service.d.ts +14 -14
- package/lib/demo/full-text-search-service.js +33 -33
- package/lib/demo/radio-player-controller.d.ts +41 -41
- package/lib/demo/radio-player-controller.js +199 -199
- package/lib/src/assets/img/left.d.ts +2 -2
- package/lib/src/assets/img/left.js +15 -15
- package/lib/src/assets/img/right.d.ts +2 -2
- package/lib/src/assets/img/right.js +15 -15
- package/lib/src/models/music-zone.d.ts +12 -12
- package/lib/src/models/music-zone.js +15 -15
- package/lib/src/models/radio-player-config.d.ts +26 -26
- package/lib/src/models/radio-player-config.js +27 -27
- package/lib/src/radio-player.d.ts +589 -589
- package/lib/src/radio-player.js +1338 -1338
- package/lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-backend.d.ts +82 -82
- package/lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-backend.js +107 -107
- package/lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-response.d.ts +48 -48
- package/lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-response.js +58 -58
- package/lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-service-interface.d.ts +16 -16
- package/lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-service-interface.js +1 -1
- package/lib/src/search-handler/search-backends/local-search-backend/local-search-backend.d.ts +27 -27
- package/lib/src/search-handler/search-backends/local-search-backend/local-search-backend.js +42 -42
- package/lib/src/search-handler/search-backends/search-backend-interface.d.ts +9 -9
- package/lib/src/search-handler/search-backends/search-backend-interface.js +1 -1
- package/lib/src/search-handler/search-handler-interface.d.ts +17 -17
- package/lib/src/search-handler/search-handler-interface.js +1 -1
- package/lib/src/search-handler/search-handler.d.ts +83 -83
- package/lib/src/search-handler/search-handler.js +177 -177
- package/lib/src/search-handler/search-helper.d.ts +12 -12
- package/lib/src/search-handler/search-helper.js +22 -22
- package/lib/src/search-handler/search-models.d.ts +45 -45
- package/lib/src/search-handler/search-models.js +49 -49
- package/lib/src/search-handler/transcript-index-interface.d.ts +38 -38
- package/lib/src/search-handler/transcript-index-interface.js +1 -1
- package/lib/src/search-handler/transcript-index.d.ts +53 -53
- package/lib/src/search-handler/transcript-index.js +80 -80
- package/lib/src/search-results-switcher.d.ts +58 -58
- package/lib/src/search-results-switcher.js +133 -133
- package/package.json +93 -93
- package/src/assets/img/left.ts +17 -17
- package/src/assets/img/right.ts +17 -17
- package/src/models/music-zone.ts +17 -17
- package/src/models/radio-player-config.ts +47 -47
- package/src/radio-player.ts +1402 -1402
- package/src/search-handler/search-backends/full-text-search-backend/full-text-search-backend.ts +140 -140
- package/src/search-handler/search-backends/full-text-search-backend/full-text-search-response.ts +110 -110
- package/src/search-handler/search-backends/full-text-search-backend/full-text-search-service-interface.ts +17 -17
- package/src/search-handler/search-backends/local-search-backend/local-search-backend.ts +50 -50
- package/src/search-handler/search-backends/search-backend-interface.ts +10 -10
- package/src/search-handler/search-handler-interface.ts +18 -18
- package/src/search-handler/search-handler.ts +217 -217
- package/src/search-handler/search-helper.ts +25 -25
- package/src/search-handler/search-models.ts +69 -69
- package/src/search-handler/transcript-index-interface.ts +42 -42
- package/src/search-handler/transcript-index.ts +93 -93
- package/src/search-results-switcher.ts +131 -131
- package/.eslintrc +0 -37
- package/.gitignore +0 -11
- package/.storybook/.babelrc +0 -15
- package/.storybook/addons.js +0 -7
- package/.storybook/config.js +0 -11
- package/.storybook/webpack.config.js +0 -5
- package/demo/full-text-search-service.ts +0 -32
- package/demo/index.html +0 -53
- package/demo/radio-player-controller.ts +0 -237
- package/karma.bs.config.js +0 -16
- package/karma.conf.js +0 -66
- package/package-lock.json +0 -51719
- package/stories/index.stories.js +0 -40
- package/stories/transcript.js +0 -683
- package/test/assets/arrow.mp3 +0 -0
- package/test/music-zone.test.js +0 -13
- package/test/promised-sleep.js +0 -3
- package/test/radio-player-config.test.js +0 -42
- package/test/radio-player.test.js +0 -1072
- package/test/sample_transcript.js +0 -1493
- package/test/search-handler/search-backends/full-text-sample-response-brackets.js +0 -60
- package/test/search-handler/search-backends/full-text-sample-response-em.js +0 -60
- package/test/search-handler/search-backends/full-text-search-backend.test.js +0 -74
- package/test/search-handler/search-backends/full-text-search-response.test.js +0 -14
- package/test/search-handler/search-backends/local-search-backend.test.js +0 -39
- package/test/search-handler/search-handler.test.js +0 -550
- package/test/search-handler/search-helper.test.js +0 -63
- package/test/search-handler/search-model.test.js +0 -56
- package/test/search-handler/transcript-index.test.js +0 -66
- package/test/search-results-switcher.test.js +0 -97
- package/tsconfig.build.json +0 -7
- package/tsconfig.json +0 -21
- package/yarn.lock +0 -14450
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
import { Range } from '../../search-models';
|
|
2
|
-
import { SearchBackendInterface } from '../search-backend-interface';
|
|
3
|
-
import { FullTextSearchServiceInterface } from './full-text-search-service-interface';
|
|
4
|
-
/**
|
|
5
|
-
* This class is responsible for taking the response from the full text search backend
|
|
6
|
-
* and converting the results into start and end indices for each of the matches.
|
|
7
|
-
*
|
|
8
|
-
* The start and end indices are then used by the SearchHandler to re-build the
|
|
9
|
-
* transcript, separated by search results in their original time codes.
|
|
10
|
-
*/
|
|
11
|
-
export declare class FullTextSearchBackend implements SearchBackendInterface {
|
|
12
|
-
/**
|
|
13
|
-
* A FullTextSearchService that provides the fetching layer for results. This
|
|
14
|
-
* object can make AJAX requests or any other backend call needed to return
|
|
15
|
-
* a response.
|
|
16
|
-
*
|
|
17
|
-
* @private
|
|
18
|
-
* @type {FullTextSearchServiceInterface}
|
|
19
|
-
* @memberof FullTextSearchBackend
|
|
20
|
-
*/
|
|
21
|
-
private service;
|
|
22
|
-
/**
|
|
23
|
-
* The start tag to match a search result, like `{{{` or `<em>`
|
|
24
|
-
*
|
|
25
|
-
* @private
|
|
26
|
-
* @type {string}
|
|
27
|
-
* @memberof FullTextSearchBackend
|
|
28
|
-
*/
|
|
29
|
-
private startTag;
|
|
30
|
-
/**
|
|
31
|
-
* The end tag to match a search result, like `}}}` or `</em>`
|
|
32
|
-
*
|
|
33
|
-
* @private
|
|
34
|
-
* @type {string}
|
|
35
|
-
* @memberof FullTextSearchBackend
|
|
36
|
-
*/
|
|
37
|
-
private endTag;
|
|
38
|
-
constructor(service: FullTextSearchServiceInterface, startTag?: string, endTag?: string);
|
|
39
|
-
/**
|
|
40
|
-
* Finds all of the ranges of all the search results across the entire transcript.
|
|
41
|
-
*
|
|
42
|
-
* @private
|
|
43
|
-
* @param {string} query
|
|
44
|
-
* @returns {Promise<Range[]>}
|
|
45
|
-
* @memberof SearchBackendInterface
|
|
46
|
-
*/
|
|
47
|
-
getSearchRanges(query: string): Promise<Range[]>;
|
|
48
|
-
/**
|
|
49
|
-
* Find the Range (start and end indices) of the results
|
|
50
|
-
* from the `highlight` in the `transcript`.
|
|
51
|
-
*
|
|
52
|
-
* Example:
|
|
53
|
-
* If `highlight` = `bar {{{baz}}} snip\n snap`
|
|
54
|
-
* and
|
|
55
|
-
* `transcript` = `beep boop\n foo bar baz snip\n snap`
|
|
56
|
-
*
|
|
57
|
-
* This will return [Range(20, 22)] because `baz` starts at index 20 and ends at 22
|
|
58
|
-
* in the transcript.
|
|
59
|
-
*
|
|
60
|
-
* @param {string} highlight
|
|
61
|
-
* @param {string} transcript
|
|
62
|
-
* @returns {Range[]}
|
|
63
|
-
*/
|
|
64
|
-
private rangesOfResultInTranscript;
|
|
65
|
-
/**
|
|
66
|
-
* This method finds the highlight's overall location within the transcript.
|
|
67
|
-
*
|
|
68
|
-
* To do this, it strips out the start and end tags to treat it as a raw string.
|
|
69
|
-
*
|
|
70
|
-
* Example:
|
|
71
|
-
* If `highlight` = `bar {{{baz}}} snip\n snap`
|
|
72
|
-
* and
|
|
73
|
-
* `transcript` = `beep boop\n foo bar baz snip\n snap`
|
|
74
|
-
*
|
|
75
|
-
* This will return 16 because `bar baz snip...` starts at index 16.
|
|
76
|
-
*
|
|
77
|
-
* @param {string} highlight The highlighted string to find
|
|
78
|
-
* @param {string} transcript The transcript in which to find the highlight
|
|
79
|
-
* @returns {number}
|
|
80
|
-
*/
|
|
81
|
-
private getStartIndexOfHighlight;
|
|
82
|
-
}
|
|
1
|
+
import { Range } from '../../search-models';
|
|
2
|
+
import { SearchBackendInterface } from '../search-backend-interface';
|
|
3
|
+
import { FullTextSearchServiceInterface } from './full-text-search-service-interface';
|
|
4
|
+
/**
|
|
5
|
+
* This class is responsible for taking the response from the full text search backend
|
|
6
|
+
* and converting the results into start and end indices for each of the matches.
|
|
7
|
+
*
|
|
8
|
+
* The start and end indices are then used by the SearchHandler to re-build the
|
|
9
|
+
* transcript, separated by search results in their original time codes.
|
|
10
|
+
*/
|
|
11
|
+
export declare class FullTextSearchBackend implements SearchBackendInterface {
|
|
12
|
+
/**
|
|
13
|
+
* A FullTextSearchService that provides the fetching layer for results. This
|
|
14
|
+
* object can make AJAX requests or any other backend call needed to return
|
|
15
|
+
* a response.
|
|
16
|
+
*
|
|
17
|
+
* @private
|
|
18
|
+
* @type {FullTextSearchServiceInterface}
|
|
19
|
+
* @memberof FullTextSearchBackend
|
|
20
|
+
*/
|
|
21
|
+
private service;
|
|
22
|
+
/**
|
|
23
|
+
* The start tag to match a search result, like `{{{` or `<em>`
|
|
24
|
+
*
|
|
25
|
+
* @private
|
|
26
|
+
* @type {string}
|
|
27
|
+
* @memberof FullTextSearchBackend
|
|
28
|
+
*/
|
|
29
|
+
private startTag;
|
|
30
|
+
/**
|
|
31
|
+
* The end tag to match a search result, like `}}}` or `</em>`
|
|
32
|
+
*
|
|
33
|
+
* @private
|
|
34
|
+
* @type {string}
|
|
35
|
+
* @memberof FullTextSearchBackend
|
|
36
|
+
*/
|
|
37
|
+
private endTag;
|
|
38
|
+
constructor(service: FullTextSearchServiceInterface, startTag?: string, endTag?: string);
|
|
39
|
+
/**
|
|
40
|
+
* Finds all of the ranges of all the search results across the entire transcript.
|
|
41
|
+
*
|
|
42
|
+
* @private
|
|
43
|
+
* @param {string} query
|
|
44
|
+
* @returns {Promise<Range[]>}
|
|
45
|
+
* @memberof SearchBackendInterface
|
|
46
|
+
*/
|
|
47
|
+
getSearchRanges(query: string): Promise<Range[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Find the Range (start and end indices) of the results
|
|
50
|
+
* from the `highlight` in the `transcript`.
|
|
51
|
+
*
|
|
52
|
+
* Example:
|
|
53
|
+
* If `highlight` = `bar {{{baz}}} snip\n snap`
|
|
54
|
+
* and
|
|
55
|
+
* `transcript` = `beep boop\n foo bar baz snip\n snap`
|
|
56
|
+
*
|
|
57
|
+
* This will return [Range(20, 22)] because `baz` starts at index 20 and ends at 22
|
|
58
|
+
* in the transcript.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} highlight
|
|
61
|
+
* @param {string} transcript
|
|
62
|
+
* @returns {Range[]}
|
|
63
|
+
*/
|
|
64
|
+
private rangesOfResultInTranscript;
|
|
65
|
+
/**
|
|
66
|
+
* This method finds the highlight's overall location within the transcript.
|
|
67
|
+
*
|
|
68
|
+
* To do this, it strips out the start and end tags to treat it as a raw string.
|
|
69
|
+
*
|
|
70
|
+
* Example:
|
|
71
|
+
* If `highlight` = `bar {{{baz}}} snip\n snap`
|
|
72
|
+
* and
|
|
73
|
+
* `transcript` = `beep boop\n foo bar baz snip\n snap`
|
|
74
|
+
*
|
|
75
|
+
* This will return 16 because `bar baz snip...` starts at index 16.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} highlight The highlighted string to find
|
|
78
|
+
* @param {string} transcript The transcript in which to find the highlight
|
|
79
|
+
* @returns {number}
|
|
80
|
+
*/
|
|
81
|
+
private getStartIndexOfHighlight;
|
|
82
|
+
}
|
package/lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-backend.js
CHANGED
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { Range } from '../../search-models';
|
|
11
|
-
/**
|
|
12
|
-
* This class is responsible for taking the response from the full text search backend
|
|
13
|
-
* and converting the results into start and end indices for each of the matches.
|
|
14
|
-
*
|
|
15
|
-
* The start and end indices are then used by the SearchHandler to re-build the
|
|
16
|
-
* transcript, separated by search results in their original time codes.
|
|
17
|
-
*/
|
|
18
|
-
export class FullTextSearchBackend {
|
|
19
|
-
constructor(service, startTag = '{{{', endTag = '}}}') {
|
|
20
|
-
this.service = service;
|
|
21
|
-
this.startTag = startTag;
|
|
22
|
-
this.endTag = endTag;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Finds all of the ranges of all the search results across the entire transcript.
|
|
26
|
-
*
|
|
27
|
-
* @private
|
|
28
|
-
* @param {string} query
|
|
29
|
-
* @returns {Promise<Range[]>}
|
|
30
|
-
* @memberof SearchBackendInterface
|
|
31
|
-
*/
|
|
32
|
-
getSearchRanges(query) {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
let ranges = [];
|
|
35
|
-
const results = yield this.service.searchRequested(query);
|
|
36
|
-
results.value.docs.forEach((result) => {
|
|
37
|
-
const transcript = result.text;
|
|
38
|
-
result.highlight.cc.forEach((highlight) => {
|
|
39
|
-
const newRanges = this.rangesOfResultInTranscript(highlight, transcript);
|
|
40
|
-
ranges = ranges.concat(newRanges);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
return new Promise((resolve) => {
|
|
44
|
-
resolve(ranges);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Find the Range (start and end indices) of the results
|
|
50
|
-
* from the `highlight` in the `transcript`.
|
|
51
|
-
*
|
|
52
|
-
* Example:
|
|
53
|
-
* If `highlight` = `bar {{{baz}}} snip\n snap`
|
|
54
|
-
* and
|
|
55
|
-
* `transcript` = `beep boop\n foo bar baz snip\n snap`
|
|
56
|
-
*
|
|
57
|
-
* This will return [Range(20, 22)] because `baz` starts at index 20 and ends at 22
|
|
58
|
-
* in the transcript.
|
|
59
|
-
*
|
|
60
|
-
* @param {string} highlight
|
|
61
|
-
* @param {string} transcript
|
|
62
|
-
* @returns {Range[]}
|
|
63
|
-
*/
|
|
64
|
-
rangesOfResultInTranscript(highlight, transcript) {
|
|
65
|
-
const regex = new RegExp(`${this.startTag}(.*?)${this.endTag}`, 'gm');
|
|
66
|
-
const startIndexOfHighlight = this.getStartIndexOfHighlight(highlight, transcript);
|
|
67
|
-
const totalTagLength = this.startTag.length + this.endTag.length;
|
|
68
|
-
const ranges = [];
|
|
69
|
-
let matchIndex = 0;
|
|
70
|
-
let match;
|
|
71
|
-
// eslint-disable-next-line no-cond-assign
|
|
72
|
-
while ((match = regex.exec(highlight)) !== null) {
|
|
73
|
-
const startIndex = match.index;
|
|
74
|
-
const matchLength = match[1].length;
|
|
75
|
-
const adjustedMatchStart = startIndex - matchIndex * totalTagLength;
|
|
76
|
-
const overallMatchStart = startIndexOfHighlight + adjustedMatchStart;
|
|
77
|
-
const matchEnd = overallMatchStart + matchLength;
|
|
78
|
-
const range = new Range(overallMatchStart, matchEnd);
|
|
79
|
-
ranges.push(range);
|
|
80
|
-
matchIndex += 1;
|
|
81
|
-
}
|
|
82
|
-
return ranges;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* This method finds the highlight's overall location within the transcript.
|
|
86
|
-
*
|
|
87
|
-
* To do this, it strips out the start and end tags to treat it as a raw string.
|
|
88
|
-
*
|
|
89
|
-
* Example:
|
|
90
|
-
* If `highlight` = `bar {{{baz}}} snip\n snap`
|
|
91
|
-
* and
|
|
92
|
-
* `transcript` = `beep boop\n foo bar baz snip\n snap`
|
|
93
|
-
*
|
|
94
|
-
* This will return 16 because `bar baz snip...` starts at index 16.
|
|
95
|
-
*
|
|
96
|
-
* @param {string} highlight The highlighted string to find
|
|
97
|
-
* @param {string} transcript The transcript in which to find the highlight
|
|
98
|
-
* @returns {number}
|
|
99
|
-
*/
|
|
100
|
-
getStartIndexOfHighlight(highlight, transcript) {
|
|
101
|
-
const startTagRegex = new RegExp(this.startTag, 'gm');
|
|
102
|
-
const endTagRegex = new RegExp(this.endTag, 'gm');
|
|
103
|
-
const untokenizedHighlight = highlight.replace(startTagRegex, '').replace(endTagRegex, '');
|
|
104
|
-
const startIndexOfHighlight = transcript.indexOf(untokenizedHighlight);
|
|
105
|
-
return startIndexOfHighlight;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Range } from '../../search-models';
|
|
11
|
+
/**
|
|
12
|
+
* This class is responsible for taking the response from the full text search backend
|
|
13
|
+
* and converting the results into start and end indices for each of the matches.
|
|
14
|
+
*
|
|
15
|
+
* The start and end indices are then used by the SearchHandler to re-build the
|
|
16
|
+
* transcript, separated by search results in their original time codes.
|
|
17
|
+
*/
|
|
18
|
+
export class FullTextSearchBackend {
|
|
19
|
+
constructor(service, startTag = '{{{', endTag = '}}}') {
|
|
20
|
+
this.service = service;
|
|
21
|
+
this.startTag = startTag;
|
|
22
|
+
this.endTag = endTag;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Finds all of the ranges of all the search results across the entire transcript.
|
|
26
|
+
*
|
|
27
|
+
* @private
|
|
28
|
+
* @param {string} query
|
|
29
|
+
* @returns {Promise<Range[]>}
|
|
30
|
+
* @memberof SearchBackendInterface
|
|
31
|
+
*/
|
|
32
|
+
getSearchRanges(query) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
let ranges = [];
|
|
35
|
+
const results = yield this.service.searchRequested(query);
|
|
36
|
+
results.value.docs.forEach((result) => {
|
|
37
|
+
const transcript = result.text;
|
|
38
|
+
result.highlight.cc.forEach((highlight) => {
|
|
39
|
+
const newRanges = this.rangesOfResultInTranscript(highlight, transcript);
|
|
40
|
+
ranges = ranges.concat(newRanges);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
resolve(ranges);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Find the Range (start and end indices) of the results
|
|
50
|
+
* from the `highlight` in the `transcript`.
|
|
51
|
+
*
|
|
52
|
+
* Example:
|
|
53
|
+
* If `highlight` = `bar {{{baz}}} snip\n snap`
|
|
54
|
+
* and
|
|
55
|
+
* `transcript` = `beep boop\n foo bar baz snip\n snap`
|
|
56
|
+
*
|
|
57
|
+
* This will return [Range(20, 22)] because `baz` starts at index 20 and ends at 22
|
|
58
|
+
* in the transcript.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} highlight
|
|
61
|
+
* @param {string} transcript
|
|
62
|
+
* @returns {Range[]}
|
|
63
|
+
*/
|
|
64
|
+
rangesOfResultInTranscript(highlight, transcript) {
|
|
65
|
+
const regex = new RegExp(`${this.startTag}(.*?)${this.endTag}`, 'gm');
|
|
66
|
+
const startIndexOfHighlight = this.getStartIndexOfHighlight(highlight, transcript);
|
|
67
|
+
const totalTagLength = this.startTag.length + this.endTag.length;
|
|
68
|
+
const ranges = [];
|
|
69
|
+
let matchIndex = 0;
|
|
70
|
+
let match;
|
|
71
|
+
// eslint-disable-next-line no-cond-assign
|
|
72
|
+
while ((match = regex.exec(highlight)) !== null) {
|
|
73
|
+
const startIndex = match.index;
|
|
74
|
+
const matchLength = match[1].length;
|
|
75
|
+
const adjustedMatchStart = startIndex - matchIndex * totalTagLength;
|
|
76
|
+
const overallMatchStart = startIndexOfHighlight + adjustedMatchStart;
|
|
77
|
+
const matchEnd = overallMatchStart + matchLength;
|
|
78
|
+
const range = new Range(overallMatchStart, matchEnd);
|
|
79
|
+
ranges.push(range);
|
|
80
|
+
matchIndex += 1;
|
|
81
|
+
}
|
|
82
|
+
return ranges;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* This method finds the highlight's overall location within the transcript.
|
|
86
|
+
*
|
|
87
|
+
* To do this, it strips out the start and end tags to treat it as a raw string.
|
|
88
|
+
*
|
|
89
|
+
* Example:
|
|
90
|
+
* If `highlight` = `bar {{{baz}}} snip\n snap`
|
|
91
|
+
* and
|
|
92
|
+
* `transcript` = `beep boop\n foo bar baz snip\n snap`
|
|
93
|
+
*
|
|
94
|
+
* This will return 16 because `bar baz snip...` starts at index 16.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} highlight The highlighted string to find
|
|
97
|
+
* @param {string} transcript The transcript in which to find the highlight
|
|
98
|
+
* @returns {number}
|
|
99
|
+
*/
|
|
100
|
+
getStartIndexOfHighlight(highlight, transcript) {
|
|
101
|
+
const startTagRegex = new RegExp(this.startTag, 'gm');
|
|
102
|
+
const endTagRegex = new RegExp(this.endTag, 'gm');
|
|
103
|
+
const untokenizedHighlight = highlight.replace(startTagRegex, '').replace(endTagRegex, '');
|
|
104
|
+
const startIndexOfHighlight = transcript.indexOf(untokenizedHighlight);
|
|
105
|
+
return startIndexOfHighlight;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
108
|
//# sourceMappingURL=full-text-search-backend.js.map
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the response models for the full text search backend.
|
|
3
|
-
*
|
|
4
|
-
* On receiving the response, we deserialize the raw JSON into `FullTextSearchResponse`,
|
|
5
|
-
* which cascades down into all of the child models.
|
|
6
|
-
*/
|
|
7
|
-
export declare class FullTextSearchResponseValueHighlighting {
|
|
8
|
-
text: string[];
|
|
9
|
-
constructor(payload: any);
|
|
10
|
-
}
|
|
11
|
-
export declare class FullTextSearchResponseValueFacetCounts {
|
|
12
|
-
facetFields: object;
|
|
13
|
-
facetDates: object;
|
|
14
|
-
constructor(payload: any);
|
|
15
|
-
}
|
|
16
|
-
export declare class FullTextSearchResponseDocHighlight {
|
|
17
|
-
cc: string[];
|
|
18
|
-
constructor(payload: any);
|
|
19
|
-
}
|
|
20
|
-
export declare class FullTextSearchResponseDoc {
|
|
21
|
-
identifier: string;
|
|
22
|
-
title: string;
|
|
23
|
-
text: string;
|
|
24
|
-
times: string;
|
|
25
|
-
downloads: number;
|
|
26
|
-
collection: string;
|
|
27
|
-
highlight: FullTextSearchResponseDocHighlight;
|
|
28
|
-
description: string;
|
|
29
|
-
mediatype: string;
|
|
30
|
-
__href__: string;
|
|
31
|
-
'SE-BYPASS': number;
|
|
32
|
-
constructor(payload: any);
|
|
33
|
-
}
|
|
34
|
-
export declare class FullTextSearchResponseValue {
|
|
35
|
-
numFound: number;
|
|
36
|
-
start: number;
|
|
37
|
-
docs: FullTextSearchResponseDoc[];
|
|
38
|
-
highlighting: {
|
|
39
|
-
[key: string]: FullTextSearchResponseValueHighlighting;
|
|
40
|
-
};
|
|
41
|
-
facetCounts: FullTextSearchResponseValueFacetCounts;
|
|
42
|
-
constructor(payload: any);
|
|
43
|
-
}
|
|
44
|
-
export declare class FullTextSearchResponse {
|
|
45
|
-
success: boolean;
|
|
46
|
-
value: FullTextSearchResponseValue;
|
|
47
|
-
constructor(payload: any);
|
|
48
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the response models for the full text search backend.
|
|
3
|
+
*
|
|
4
|
+
* On receiving the response, we deserialize the raw JSON into `FullTextSearchResponse`,
|
|
5
|
+
* which cascades down into all of the child models.
|
|
6
|
+
*/
|
|
7
|
+
export declare class FullTextSearchResponseValueHighlighting {
|
|
8
|
+
text: string[];
|
|
9
|
+
constructor(payload: any);
|
|
10
|
+
}
|
|
11
|
+
export declare class FullTextSearchResponseValueFacetCounts {
|
|
12
|
+
facetFields: object;
|
|
13
|
+
facetDates: object;
|
|
14
|
+
constructor(payload: any);
|
|
15
|
+
}
|
|
16
|
+
export declare class FullTextSearchResponseDocHighlight {
|
|
17
|
+
cc: string[];
|
|
18
|
+
constructor(payload: any);
|
|
19
|
+
}
|
|
20
|
+
export declare class FullTextSearchResponseDoc {
|
|
21
|
+
identifier: string;
|
|
22
|
+
title: string;
|
|
23
|
+
text: string;
|
|
24
|
+
times: string;
|
|
25
|
+
downloads: number;
|
|
26
|
+
collection: string;
|
|
27
|
+
highlight: FullTextSearchResponseDocHighlight;
|
|
28
|
+
description: string;
|
|
29
|
+
mediatype: string;
|
|
30
|
+
__href__: string;
|
|
31
|
+
'SE-BYPASS': number;
|
|
32
|
+
constructor(payload: any);
|
|
33
|
+
}
|
|
34
|
+
export declare class FullTextSearchResponseValue {
|
|
35
|
+
numFound: number;
|
|
36
|
+
start: number;
|
|
37
|
+
docs: FullTextSearchResponseDoc[];
|
|
38
|
+
highlighting: {
|
|
39
|
+
[key: string]: FullTextSearchResponseValueHighlighting;
|
|
40
|
+
};
|
|
41
|
+
facetCounts: FullTextSearchResponseValueFacetCounts;
|
|
42
|
+
constructor(payload: any);
|
|
43
|
+
}
|
|
44
|
+
export declare class FullTextSearchResponse {
|
|
45
|
+
success: boolean;
|
|
46
|
+
value: FullTextSearchResponseValue;
|
|
47
|
+
constructor(payload: any);
|
|
48
|
+
}
|
package/lib/src/search-handler/search-backends/full-text-search-backend/full-text-search-response.js
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/**
|
|
3
|
-
* This file contains the response models for the full text search backend.
|
|
4
|
-
*
|
|
5
|
-
* On receiving the response, we deserialize the raw JSON into `FullTextSearchResponse`,
|
|
6
|
-
* which cascades down into all of the child models.
|
|
7
|
-
*/
|
|
8
|
-
export class FullTextSearchResponseValueHighlighting {
|
|
9
|
-
constructor(payload) {
|
|
10
|
-
this.text = payload.text;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export class FullTextSearchResponseValueFacetCounts {
|
|
14
|
-
constructor(payload) {
|
|
15
|
-
this.facetDates = payload.facet_dates;
|
|
16
|
-
this.facetFields = payload.facet_fields;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export class FullTextSearchResponseDocHighlight {
|
|
20
|
-
constructor(payload) {
|
|
21
|
-
this.cc = payload.cc;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export class FullTextSearchResponseDoc {
|
|
25
|
-
constructor(payload) {
|
|
26
|
-
this.identifier = payload.identifier;
|
|
27
|
-
this.title = payload.title;
|
|
28
|
-
this.text = payload.text;
|
|
29
|
-
this.times = payload.times;
|
|
30
|
-
this.downloads = payload.downloads;
|
|
31
|
-
this.collection = payload.collection;
|
|
32
|
-
this.highlight = new FullTextSearchResponseDocHighlight(payload.highlight);
|
|
33
|
-
this.description = payload.description;
|
|
34
|
-
this.mediatype = payload.mediatype;
|
|
35
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
36
|
-
this.__href__ = payload.__href__;
|
|
37
|
-
this['SE-BYPASS'] = payload['SE-BYPASS'];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export class FullTextSearchResponseValue {
|
|
41
|
-
constructor(payload) {
|
|
42
|
-
this.highlighting = {};
|
|
43
|
-
this.numFound = payload.numFound;
|
|
44
|
-
this.start = payload.start;
|
|
45
|
-
this.docs = payload.docs.map((doc) => new FullTextSearchResponseDoc(doc));
|
|
46
|
-
Object.keys(payload.highlighting).forEach((key) => {
|
|
47
|
-
const highlighting = payload.highlighting[key];
|
|
48
|
-
this.highlighting[key] = new FullTextSearchResponseValueHighlighting(highlighting);
|
|
49
|
-
});
|
|
50
|
-
this.facetCounts = new FullTextSearchResponseValueFacetCounts(payload.facet_counts);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export class FullTextSearchResponse {
|
|
54
|
-
constructor(payload) {
|
|
55
|
-
this.success = payload.success;
|
|
56
|
-
this.value = new FullTextSearchResponseValue(payload.value);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/**
|
|
3
|
+
* This file contains the response models for the full text search backend.
|
|
4
|
+
*
|
|
5
|
+
* On receiving the response, we deserialize the raw JSON into `FullTextSearchResponse`,
|
|
6
|
+
* which cascades down into all of the child models.
|
|
7
|
+
*/
|
|
8
|
+
export class FullTextSearchResponseValueHighlighting {
|
|
9
|
+
constructor(payload) {
|
|
10
|
+
this.text = payload.text;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class FullTextSearchResponseValueFacetCounts {
|
|
14
|
+
constructor(payload) {
|
|
15
|
+
this.facetDates = payload.facet_dates;
|
|
16
|
+
this.facetFields = payload.facet_fields;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class FullTextSearchResponseDocHighlight {
|
|
20
|
+
constructor(payload) {
|
|
21
|
+
this.cc = payload.cc;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class FullTextSearchResponseDoc {
|
|
25
|
+
constructor(payload) {
|
|
26
|
+
this.identifier = payload.identifier;
|
|
27
|
+
this.title = payload.title;
|
|
28
|
+
this.text = payload.text;
|
|
29
|
+
this.times = payload.times;
|
|
30
|
+
this.downloads = payload.downloads;
|
|
31
|
+
this.collection = payload.collection;
|
|
32
|
+
this.highlight = new FullTextSearchResponseDocHighlight(payload.highlight);
|
|
33
|
+
this.description = payload.description;
|
|
34
|
+
this.mediatype = payload.mediatype;
|
|
35
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
36
|
+
this.__href__ = payload.__href__;
|
|
37
|
+
this['SE-BYPASS'] = payload['SE-BYPASS'];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export class FullTextSearchResponseValue {
|
|
41
|
+
constructor(payload) {
|
|
42
|
+
this.highlighting = {};
|
|
43
|
+
this.numFound = payload.numFound;
|
|
44
|
+
this.start = payload.start;
|
|
45
|
+
this.docs = payload.docs.map((doc) => new FullTextSearchResponseDoc(doc));
|
|
46
|
+
Object.keys(payload.highlighting).forEach((key) => {
|
|
47
|
+
const highlighting = payload.highlighting[key];
|
|
48
|
+
this.highlighting[key] = new FullTextSearchResponseValueHighlighting(highlighting);
|
|
49
|
+
});
|
|
50
|
+
this.facetCounts = new FullTextSearchResponseValueFacetCounts(payload.facet_counts);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export class FullTextSearchResponse {
|
|
54
|
+
constructor(payload) {
|
|
55
|
+
this.success = payload.success;
|
|
56
|
+
this.value = new FullTextSearchResponseValue(payload.value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
59
|
//# sourceMappingURL=full-text-search-response.js.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { FullTextSearchResponse } from './full-text-search-response';
|
|
2
|
-
/**
|
|
3
|
-
* The `FullTextSearchServiceInterface` 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 FullTextSearchServiceInterface {
|
|
8
|
-
/**
|
|
9
|
-
* Execute the search and return a Promise with a FullTextSearchResponse.
|
|
10
|
-
*
|
|
11
|
-
* @param {string} query
|
|
12
|
-
* @returns {Promise<FullTextSearchResponse>}
|
|
13
|
-
* @memberof FullTextSearchServiceInterface
|
|
14
|
-
*/
|
|
15
|
-
searchRequested(query: string): Promise<FullTextSearchResponse>;
|
|
16
|
-
}
|
|
1
|
+
import { FullTextSearchResponse } from './full-text-search-response';
|
|
2
|
+
/**
|
|
3
|
+
* The `FullTextSearchServiceInterface` 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 FullTextSearchServiceInterface {
|
|
8
|
+
/**
|
|
9
|
+
* Execute the search and return a Promise with a FullTextSearchResponse.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} query
|
|
12
|
+
* @returns {Promise<FullTextSearchResponse>}
|
|
13
|
+
* @memberof FullTextSearchServiceInterface
|
|
14
|
+
*/
|
|
15
|
+
searchRequested(query: string): Promise<FullTextSearchResponse>;
|
|
16
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=full-text-search-service-interface.js.map
|