Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export class AzCognitiveSearch implements CognitiveSearchBase {
}

// check if index exists
async indexExists(indexName: string): Promise<boolean> {
return this.searchClients.has(indexName);
indexExists(indexName: string): boolean {
return this.getSearchClient(indexName) !== undefined;
}

async createIndexIfNotExists(indexDefinition: SearchIndex): Promise<void> {
Expand Down Expand Up @@ -100,9 +100,4 @@ export class AzCognitiveSearch implements CognitiveSearchBase {
throw new Error(`Failed to delete index ${indexName}: ${error.message}`);
}
}

// async updateIndex(indexName: string) {
// const index = await this.client.getIndex(indexName);
// this.client.createOrUpdateIndex(index);
// }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CognitiveSearchDomain } from "../../src/app/domain/infrastructure/cognitive-search/interfaces";
import { BaseDocumentType, SearchIndex } from "./interfaces";
import { CognitiveSearchDomain } from '../../src/app/domain/infrastructure/cognitive-search/interfaces';
import { BaseDocumentType, SearchIndex } from './interfaces';

export interface IMemoryCognitiveSearchCollection<DocumentType extends BaseDocumentType> {
indexDocument(document: DocumentType): Promise<void>;
Expand All @@ -11,17 +11,15 @@ export interface IMemoryCognitiveSearch {
deleteDocument(indexName: string, document: any): Promise<void>;
indexDocument(indexName: string, document: any): Promise<void>;
search(indexName: string, searchText: string, options?: any): Promise<any>;
indexExists(indexName: string): Promise<boolean>;
indexExists(indexName: string): boolean;
logSearchCollectionIndexMap(): void;

}


export class MemoryCognitiveSearchCollection<DocumentType extends BaseDocumentType> implements IMemoryCognitiveSearchCollection<DocumentType> {
private searchCollection: DocumentType[] = [];

constructor () {}
constructor() {}

async indexDocument(document: DocumentType): Promise<void> {
const existingDocument = this.searchCollection.find((i) => i.id === document.id);
if (existingDocument) {
Expand All @@ -36,22 +34,17 @@ export class MemoryCognitiveSearchCollection<DocumentType extends BaseDocumentTy
}
}


export class MemoryCognitiveSearch implements IMemoryCognitiveSearch, CognitiveSearchDomain {

private searchCollectionIndexMap: Map<string, MemoryCognitiveSearchCollection<any>>;
private searchCollectionIndexDefinitionMap: Map<string, SearchIndex>;

constructor() {
this.searchCollectionIndexMap = new Map<string, MemoryCognitiveSearchCollection<any>>();
this.searchCollectionIndexDefinitionMap = new Map<string, SearchIndex>();
}
initializeSearchClients(): Promise<void> {
throw new Error("Method not implemented.");
}


deleteIndex(indexName: string): Promise<void> {
throw new Error("Method not implemented.");
throw new Error('Method not implemented.');
}

async createIndexIfNotExists(indexDefinition: SearchIndex): Promise<void> {
Expand Down Expand Up @@ -90,9 +83,9 @@ export class MemoryCognitiveSearch implements IMemoryCognitiveSearch, CognitiveS
for (const [key, value] of this.searchCollectionIndexMap.entries()) {
console.log(`Index: ${key} | Documents: ${JSON.stringify(value)}`);
}
}
}

async indexExists(indexName: string): Promise<boolean> {
indexExists(indexName: string): boolean {
return this.searchCollectionIndexMap.has(indexName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export interface CognitiveSearchBase {
deleteDocument(indexName: string, document: any): Promise<void>;
indexDocument(indexName: string, document: any): Promise<void>;
deleteIndex(indexName: string): Promise<void>;
indexExists(indexName: string): Promise<boolean>;
indexExists(indexName: string): boolean;
}
Loading