Skip to content

Commit

Permalink
fix: results
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed May 18, 2024
1 parent edce60c commit 9332991
Show file tree
Hide file tree
Showing 23 changed files with 374 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ImageDto importImage(ImageQueryDto imageDto, Image image) {
}

public List<ImageDto> queryImage(String imageQuery) {
var aiDocuments = this.documentVsRepository.retrieve(imageQuery, MetaData.DataType.IMAGE).stream()
var aiDocuments = this.documentVsRepository.retrieve(imageQuery, MetaData.DataType.IMAGE, this.resultSize.intValue()).stream()
.filter(myDoc -> myDoc.getMetadata().get(MetaData.DATATYPE).equals(DataType.IMAGE.toString()))
.sorted((myDocA, myDocB) -> ((Float) myDocA.getMetadata().get(MetaData.DISTANCE))
.compareTo(((Float) myDocB.getMetadata().get(MetaData.DISTANCE))))
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/angular/i18n/messages.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"cancel": "Cancel",
"upload": "Upload",
"doclistHeading": "Document List",
"imageQuery": "Image query",
"function": "Function",
"table": "Table",
"search": "Search",
Expand All @@ -28,7 +29,8 @@
"docSearchOtherDocuments": "Other Documents:",
"functionSearchHeading": "Function Search",
"imageQueryHeading": "Image Query",
"imagequeryQuery": "Image query",
"query": "Query",
"imageQueryPrompt": "Image prompt",
"tableSearchHeading": "Table Search",
"tableSearchDataImport": "A new DB instance needs a data import first.",
"tableSearchImportData": " Import Data "
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/angular/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ export const routes: Routes = [
loadChildren: () => import('./table-search').then((mod) => mod.TABLESEARCH),
},
{
path: 'functionsearch',
loadChildren: () => import('./function-search').then((mod) => mod.FUNCTIONSEARCH),
path: 'functionsearch',
loadChildren: () =>
import('./function-search').then((mod) => mod.FUNCTIONSEARCH),
},
{
path: 'imagequery',
loadChildren: () => import('./image-query').then((mod) => mod.IMAGEQUERY)
path: 'imagequery',
loadChildren: () => import('./image-query').then((mod) => mod.IMAGEQUERY),
},
{ path: '**', redirectTo: 'doclist' },
];
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Image query
</button>
</div>
<div>
<div>
<button
mat-flat-button
color="primary"
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/angular/src/app/doc-list/doc-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ export class DocListComponent implements OnInit {
}

protected imageQuery(): void {
this.router.navigate(['/imagequery']);
this.router.navigate(['/imagequery']);
}

protected tableSearch(): void {
this.router.navigate(['/tablesearch']);
}

protected functionSearch(): void {
this.router.navigate(['/functionsearch']);
this.router.navigate(['/functionsearch']);
}

protected showDocument(documentId: number): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<mat-toolbar color="primary" class="custom-toolbar">
<div class="toolbar-content">
<div i18n="@@functionSearchHeading">Function Search</div>
<div class="example-fill-remaining-space"></div>
<div class="example-fill-remaining-space"></div>
<div>
<button
mat-flat-button
Expand Down Expand Up @@ -53,27 +53,36 @@
</div>
</div>
} @else {
<mat-tree [dataSource]="dataSource" [treeControl]="treeControl" class="example-tree">
<mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle>
{{node.name}}
<mat-tree
[dataSource]="dataSource"
[treeControl]="treeControl"
class="example-tree"
>
<mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle>
{{ node.name }}
</mat-tree-node>
<!-- This is the tree node template for expandable nodes -->
<mat-nested-tree-node *matTreeNodeDef="let node; when: hasChild">
<div class="mat-tree-node">
<button mat-icon-button matTreeNodeToggle
[attr.aria-label]="'Toggle ' + node.name">
<mat-icon class="mat-icon-rtl-mirror">
{{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}}
</mat-icon>
</button>
{{node.name}}
</div>
<!-- There is inline padding applied to this div using styles.
<div class="mat-tree-node">
<button
mat-icon-button
matTreeNodeToggle
[attr.aria-label]="'Toggle ' + node.name"
>
<mat-icon class="mat-icon-rtl-mirror">
{{ treeControl.isExpanded(node) ? "expand_more" : "chevron_right" }}
</mat-icon>
</button>
{{ node.name }}
</div>
<!-- There is inline padding applied to this div using styles.
This padding value depends on the mat-icon-button width. -->
<div [class.example-tree-invisible]="!treeControl.isExpanded(node)"
role="group">
<ng-container matTreeNodeOutlet></ng-container>
<div
[class.example-tree-invisible]="!treeControl.isExpanded(node)"
role="group"
>
<ng-container matTreeNodeOutlet></ng-container>
</div>
</mat-nested-tree-node>
</mat-tree>
}
</mat-tree>
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
/*
* This padding sets alignment of the nested nodes.
*/
.example-tree .mat-nested-tree-node div[role=group] {
.example-tree .mat-nested-tree-node div[role="group"] {
padding-left: 40px;
}

Expand All @@ -78,7 +78,7 @@
* Leaf nodes need to have padding so as to align with other non-leaf nodes
* under the same parent.
*/
.example-tree div[role=group] > .mat-tree-node {
.example-tree div[role="group"] > .mat-tree-node {
padding-left: 40px;
}

Expand All @@ -91,4 +91,4 @@
justify-content: space-between;
width: 60%;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ describe('FunctionSearchComponent', () => {
expect(component).toBeTruthy();
});
});
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,26 @@
*/
import { Component, DestroyRef } from '@angular/core';
import { CommonModule } from '@angular/common';
import {MatTreeNestedDataSource, MatTreeModule} from '@angular/material/tree';
import { MatTreeNestedDataSource, MatTreeModule } from '@angular/material/tree';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatButtonModule } from '@angular/material/button';
import { Router } from '@angular/router';
import { MatInputModule } from '@angular/material/input';
import { MatTooltipModule } from '@angular/material/tooltip';
import { MatFormFieldModule } from '@angular/material/form-field';
import { FormControl, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
import {
FormControl,
FormsModule,
ReactiveFormsModule,
Validators,
} from '@angular/forms';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { Book, FunctionResponse, FunctionSearch } from '../model/functions';
import { FunctionSearchService } from '../service/function-search.service';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { Subscription, interval, map, tap } from 'rxjs';
import { NestedTreeControl } from '@angular/cdk/tree';
import {MatIconModule} from '@angular/material/icon';
import { MatIconModule } from '@angular/material/icon';

interface TreeNode {
name: string;
Expand All @@ -36,7 +41,8 @@ interface TreeNode {
@Component({
selector: 'app-function-search',
standalone: true,
imports: [CommonModule,
imports: [
CommonModule,
MatToolbarModule,
MatButtonModule,
MatInputModule,
Expand All @@ -46,34 +52,42 @@ interface TreeNode {
MatFormFieldModule,
FormsModule,
ReactiveFormsModule,
MatProgressSpinnerModule],
MatProgressSpinnerModule,
],
templateUrl: './function-search.component.html',
styleUrl: './function-search.component.scss'
styleUrl: './function-search.component.scss',
})
export class FunctionSearchComponent {
private repeatSub: Subscription | null = null;
protected searchValueControl = new FormControl('', [
protected searchValueControl = new FormControl('', [
Validators.required,
Validators.minLength(3),
]);
protected searching = false;
protected msWorking = 0;
protected treeControl = new NestedTreeControl<TreeNode>(node => node.children);
protected treeControl = new NestedTreeControl<TreeNode>(
(node) => node.children
);
protected dataSource = new MatTreeNestedDataSource<TreeNode>();

constructor(private router: Router,private destroyRef: DestroyRef, private functionSearchService: FunctionSearchService) { }

protected hasChild = (_: number, node: TreeNode) => !!node.children && node.children.length > 0;

protected showList(): void {
this.router.navigate(['/doclist']);
}

protected search(): void {
this.searching = true;
this.dataSource.data = [];
const startDate = new Date();
this.repeatSub?.unsubscribe();

constructor(
private router: Router,
private destroyRef: DestroyRef,
private functionSearchService: FunctionSearchService
) {}

protected hasChild = (_: number, node: TreeNode) =>
!!node.children && node.children.length > 0;

protected showList(): void {
this.router.navigate(['/doclist']);
}

protected search(): void {
this.searching = true;
this.dataSource.data = [];
const startDate = new Date();
this.repeatSub?.unsubscribe();
this.repeatSub = interval(100)
.pipe(
map(() => new Date()),
Expand All @@ -82,36 +96,71 @@ export class FunctionSearchComponent {
.subscribe(
(newDate) => (this.msWorking = newDate.getTime() - startDate.getTime())
);
this.functionSearchService.postLibraryFunction({question: this.searchValueControl.value, resultAmount: 10} as FunctionSearch)
.pipe(tap(() => this.repeatSub?.unsubscribe()),takeUntilDestroyed(this.destroyRef), tap(() => this.searching = false)).subscribe(value => this.dataSource.data = this.mapResult(value));
}
this.functionSearchService
.postLibraryFunction({
question: this.searchValueControl.value,
resultAmount: 10,
} as FunctionSearch)
.pipe(
tap(() => this.repeatSub?.unsubscribe()),
takeUntilDestroyed(this.destroyRef),
tap(() => (this.searching = false))
)
.subscribe((value) => (this.dataSource.data = this.mapResult(value)));
}

private mapResult(functionResponse: FunctionResponse): TreeNode[] {
return functionResponse.docs.map((myBook) => this.mapBook(myBook));
}

private mapBook(book: Book): TreeNode {
const rootNode = { name: book.title, children: [] } as TreeNode;
rootNode.children?.push({ name: 'Title: ' + book.title } as TreeNode);
rootNode.children?.push({ name: 'Type: ' + book.type } as TreeNode);
rootNode.children?.push({
name: 'Average Ratings: ' + book.ratings_average,
} as TreeNode);
rootNode.children?.push({
name: 'Authors',
children: this.mapArray(book.author_name),
} as TreeNode);
rootNode.children?.push({
name: 'Languages',
children: this.mapArray(book.language),
} as TreeNode);
rootNode.children?.push({
name: 'Persons',
children: this.mapArray(book.person),
} as TreeNode);
rootNode.children?.push({
name: 'Places',
children: this.mapArray(book.place),
} as TreeNode);
rootNode.children?.push({
name: 'Publishdates',
children: this.mapArray(book.publish_date),
} as TreeNode);
rootNode.children?.push({
name: 'Publishers',
children: this.mapArray(book.publisher),
} as TreeNode);
rootNode.children?.push({
name: 'Subjects',
children: this.mapArray(book.subject),
} as TreeNode);
rootNode.children?.push({
name: 'Times',
children: this.mapArray(book.time),
} as TreeNode);
console.log(rootNode);
return rootNode;
}

private mapArray(values: string[]): TreeNode[] {
return !!values ? values.map((myStr) => ({ name: myStr } as TreeNode)) : [];
}

private mapResult(functionResponse: FunctionResponse): TreeNode[] {
return functionResponse.docs.map(myBook => this.mapBook(myBook));
}

private mapBook(book: Book): TreeNode {
const rootNode = {name: book.title, children: [] } as TreeNode;
rootNode.children?.push({name: 'Title: '+book.title} as TreeNode);
rootNode.children?.push({name: 'Type: '+book.type} as TreeNode);
rootNode.children?.push({name: 'Average Ratings: '+book.ratings_average} as TreeNode);
rootNode.children?.push({name: 'Authors', children: this.mapArray(book.author_name)} as TreeNode);
rootNode.children?.push({name: 'Languages', children: this.mapArray(book.language)} as TreeNode);
rootNode.children?.push({name: 'Persons', children: this.mapArray(book.person)} as TreeNode);
rootNode.children?.push({name: 'Places', children: this.mapArray(book.place)} as TreeNode);
rootNode.children?.push({name: 'Publishdates', children: this.mapArray(book.publish_date)} as TreeNode);
rootNode.children?.push({name: 'Publishers', children: this.mapArray(book.publisher)} as TreeNode);
rootNode.children?.push({name: 'Subjects', children: this.mapArray(book.subject)} as TreeNode);
rootNode.children?.push({name: 'Times', children: this.mapArray(book.time)} as TreeNode);
console.log(rootNode);
return rootNode;
}

private mapArray(values: string[]): TreeNode[] {
return !!values ? values.map(myStr => ({name: myStr} as TreeNode)) : [];
}

protected logout(): void {
console.log('logout');
}
protected logout(): void {
console.log('logout');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import { Routes } from '@angular/router';
import { FunctionSearchComponent } from './function-search.component';


export const FUNCTIONSEARCH: Routes = [
{
path: '',
Expand Down
Loading

0 comments on commit 9332991

Please sign in to comment.