Skip to content

Commit

Permalink
Added sorting to search results
Browse files Browse the repository at this point in the history
  • Loading branch information
warmans committed Oct 12, 2024
1 parent 7bc4afe commit 4565d12
Show file tree
Hide file tree
Showing 18 changed files with 342 additions and 243 deletions.
4 changes: 4 additions & 0 deletions gui/src/app/lib/api-client/guards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,8 @@ export function isRskSong(arg: any): arg is models.RskSong {
( typeof arg.spotifyUri === 'undefined' || typeof arg.spotifyUri === 'string' ) &&
// title?: string
( typeof arg.title === 'undefined' || typeof arg.title === 'string' ) &&
// transcribed?: string[]
( typeof arg.transcribed === 'undefined' || (Array.isArray(arg.transcribed) && arg.transcribed.every((item: unknown) => typeof item === 'string')) ) &&

true
);
Expand Down Expand Up @@ -1208,6 +1210,8 @@ export function isRskTranscriptDialog(arg: any): arg is models.RskTranscriptDial
typeof arg === 'object' &&
// dialog?: RskDialog[]
( typeof arg.dialog === 'undefined' || (Array.isArray(arg.dialog) && arg.dialog.every((item: unknown) => isRskDialog(item))) ) &&
// maxDialogPosition?: number
( typeof arg.maxDialogPosition === 'undefined' || typeof arg.maxDialogPosition === 'number' ) &&
// transcriptMeta?: RskShortTranscript
( typeof arg.transcriptMeta === 'undefined' || isRskShortTranscript(arg.transcriptMeta) ) &&

Expand Down
1 change: 1 addition & 0 deletions gui/src/app/lib/api-client/models/rsk-song.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export interface RskSong {
episodeIds?: string[];
spotifyUri?: string;
title?: string;
transcribed?: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import {

export interface RskTranscriptDialog {
dialog?: RskDialog[];
maxDialogPosition?: number;
transcriptMeta?: RskShortTranscript;
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export class GuardedSearchAPIClient extends SearchAPIClient {
args: {
query?: string,
page?: number,
sort?: string,
},
requestHttpOptions?: HttpOptions
): Observable<models.RskSearchResultList> {
Expand Down Expand Up @@ -439,6 +440,8 @@ export class GuardedSearchAPIClient extends SearchAPIClient {
epid: string,
pos: number,
numContextLines?: number,
rangeStart?: number,
rangeEnd?: number,
},
requestHttpOptions?: HttpOptions
): Observable<models.RskTranscriptDialog> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export interface SearchAPIClientInterface {
args: {
query?: string,
page?: number,
sort?: string,
},
requestHttpOptions?: HttpOptions
): Observable<models.RskSearchResultList>;
Expand Down Expand Up @@ -426,6 +427,8 @@ export interface SearchAPIClientInterface {
epid: string,
pos: number,
numContextLines?: number,
rangeStart?: number,
rangeEnd?: number,
},
requestHttpOptions?: HttpOptions
): Observable<models.RskTranscriptDialog>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ export class SearchAPIClient implements SearchAPIClientInterface {
args: {
query?: string,
page?: number,
sort?: string,
},
requestHttpOptions?: HttpOptions
): Observable<models.RskSearchResultList> {
Expand All @@ -429,6 +430,9 @@ export class SearchAPIClient implements SearchAPIClientInterface {
if ('page' in args) {
options.params = options.params.set('page', String(args.page));
}
if ('sort' in args) {
options.params = options.params.set('sort', String(args.sort));
}
return this.sendRequest<models.RskSearchResultList>('GET', path, options);
}

Expand Down Expand Up @@ -926,6 +930,8 @@ export class SearchAPIClient implements SearchAPIClientInterface {
epid: string,
pos: number,
numContextLines?: number,
rangeStart?: number,
rangeEnd?: number,
},
requestHttpOptions?: HttpOptions
): Observable<models.RskTranscriptDialog> {
Expand All @@ -938,6 +944,12 @@ export class SearchAPIClient implements SearchAPIClientInterface {
if ('numContextLines' in args) {
options.params = options.params.set('numContextLines', String(args.numContextLines));
}
if ('rangeStart' in args) {
options.params = options.params.set('range.start', String(args.rangeStart));
}
if ('rangeEnd' in args) {
options.params = options.params.set('range.end', String(args.rangeEnd));
}
return this.sendRequest<models.RskTranscriptDialog>('GET', path, options);
}

Expand Down
13 changes: 12 additions & 1 deletion gui/src/app/module/search/page/search/search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@
<app-search-stats [rawStats]="result?.stats"></app-search-stats>
</div>
</div>
<div class="row">
<div class="col text-right">
<label>
<select name="sort" class="form-control-sm" [formControl]="currentSorting" title="Result Sorting">
<option value="_score">Best match</option>
<option value="-date">Newest to oldest</option>
<option value="date">Oldest to newest</option>
</select>
</label>
</div>
</div>
<div class="row">
<div class="col">
<div *ngFor="let res of result?.results" class="result card mb-3 animate__animated animate__fadeIn animate__faster">
<div class="card-header font-weight-bold">
<div class="d-flex justify-content-between">
<div class="d-flex align-items-center">
<a [routerLink]="['/ep', res?.episode?.id]" [fragment]="res?.dialogs[0]?.transcript | matchedRowPos">
{{ res.episode?.id }}
{{ res.episode?.id }} <span class="text-muted text-sm ml-3">{{ res.episode?.releaseDate }}</span>
</a>
<span *ngIf="res.episode?.bestof" class="badge badge-secondary ml-2">Bestof</span>
</div>
Expand Down
32 changes: 25 additions & 7 deletions gui/src/app/module/search/page/search/search.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component, EventEmitter, OnDestroy, OnInit} from '@angular/core';
import {SearchAPIClient} from 'src/app/lib/api-client/services/search';
import {ActivatedRoute, ParamMap} from '@angular/router';
import {ActivatedRoute, ParamMap, Router} from '@angular/router';
import {takeUntil} from 'rxjs/operators';
import {Title} from '@angular/platform-browser';
import {
Expand All @@ -13,6 +13,7 @@ import {
} from 'src/app/lib/api-client/models';
import {AudioService} from '../../../core/service/audio/audio.service';
import {ClipboardService} from 'src/app/module/core/service/clipboard/clipboard.service';
import {FormControl} from "@angular/forms";

@Component({
selector: 'app-search',
Expand All @@ -27,6 +28,7 @@ export class SearchComponent implements OnInit, OnDestroy {
result: RskSearchResultList;
pages: number[] = [];
currentPage: number;
currentSorting = new FormControl<string>("_score");
morePages: boolean = false;
latestChangelog: RskChangelog;
contributionsNeeded: number;
Expand All @@ -40,16 +42,33 @@ export class SearchComponent implements OnInit, OnDestroy {
private route: ActivatedRoute,
private titleService: Title,
private audioService: AudioService,
private clipboardService: ClipboardService) {
private clipboardService: ClipboardService,
private router: Router) {

this.currentSorting.valueChanges.pipe(takeUntil(this.unsubscribe$)).subscribe((val) => {
console.log("VAL", val);
this.router.navigate([], {
queryParams: {
sort: val
},
queryParamsHandling: 'merge',
skipLocationChange: false,
});
});

route.queryParamMap.pipe(takeUntil(this.unsubscribe$)).subscribe((params: ParamMap) => {
this.currentPage = parseInt(params.get('page'), 10) || 0;
this.currentSorting.setValue((params.get('sort') || '').trim());
this.query = (params.get('q') || '').trim();
if (this.query === '') {
this.result = null;
return;
}
this.executeQuery(this.query, this.currentPage);
this.executeQuery(
this.query,
this.currentPage,
this.currentSorting.getRawValue() ?? '_score',
);
});
}

Expand All @@ -73,12 +92,13 @@ export class SearchComponent implements OnInit, OnDestroy {
this.unsubscribe$.complete();
}

executeQuery(value: string, page: number) {
executeQuery(value: string, page: number, sort: string) {
this.result = undefined;
this.loading.push(true);
this.apiClient.search({
query: value,
page: page
page: page,
sort: sort,
}).pipe(
takeUntil(this.unsubscribe$),
).subscribe((res: RskSearchResultList) => {
Expand All @@ -100,6 +120,4 @@ export class SearchComponent implements OnInit, OnDestroy {
copyLineToClipboard(line: RskDialog) {
this.clipboardService.copyTextToClipboard(line.content);
}

protected readonly RskMediaType = RskMediaType;
}
6 changes: 6 additions & 0 deletions gui/src/assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,12 @@
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "sort",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
Expand Down
4 changes: 2 additions & 2 deletions server/cmd/data/populate-bluge-index.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func getMappedField(fieldName string, t mapping.FieldType, d search.DialogDocume
if dateField == nil {
return nil, false
}
return bluge.NewDateTimeField(fieldName, *dateField).Aggregatable(), true
return bluge.NewDateTimeField(fieldName, *dateField).Aggregatable().Sortable(), true
case mapping.FieldTypeNumber:
return bluge.NewNumericField(fieldName, float64(d.GetNamedField(fieldName).(int64))), true
return bluge.NewNumericField(fieldName, float64(d.GetNamedField(fieldName).(int64))).Sortable(), true
case mapping.FieldTypeShingles:
shingleAnalyzer := &analysis.Analyzer{
Tokenizer: tokenizer.NewUnicodeTokenizer(),
Expand Down
6 changes: 6 additions & 0 deletions server/gen/api/open-api/search.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "sort",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
Expand Down
Loading

0 comments on commit 4565d12

Please sign in to comment.