Index.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {
  2. IndexCreateParam,
  3. IndexManageParam,
  4. IndexView,
  5. ParamPair,
  6. } from '../pages/schema/Types';
  7. import { ManageRequestMethods } from '../types/Common';
  8. import { IndexState } from '../types/Milvus';
  9. import BaseModel from './BaseModel';
  10. export class IndexHttp extends BaseModel implements IndexView {
  11. params!: ParamPair[];
  12. field_name!: string;
  13. constructor(props: {}) {
  14. super(props);
  15. Object.assign(this, props);
  16. }
  17. static BASE_URL = `/schema/index`;
  18. static async getIndexStatus(
  19. collectionName: string,
  20. fieldName: string
  21. ): Promise<IndexState> {
  22. const path = `${this.BASE_URL}/state`;
  23. return super.findAll({
  24. path,
  25. params: { collection_name: collectionName, field_name: fieldName },
  26. });
  27. }
  28. static async getIndexInfo(collectionName: string): Promise<IndexHttp[]> {
  29. const path = this.BASE_URL;
  30. const res = await super.findAll({
  31. path,
  32. params: { collection_name: collectionName },
  33. });
  34. return res.index_descriptions.map((index: any) => new this(index));
  35. }
  36. static async createIndex(param: IndexCreateParam) {
  37. const path = this.BASE_URL;
  38. const type: ManageRequestMethods = ManageRequestMethods.CREATE;
  39. return super.create({
  40. path,
  41. data: { ...param, type },
  42. });
  43. }
  44. static async deleteIndex(param: IndexManageParam) {
  45. const path = this.BASE_URL;
  46. const type: ManageRequestMethods = ManageRequestMethods.DELETE;
  47. return super.batchDelete({ path, data: { ...param, type } });
  48. }
  49. get _indexType() {
  50. return this.params.find(p => p.key === 'index_type')?.value || '';
  51. }
  52. get _indexParameterPairs() {
  53. return this.params.filter(p => p.key !== 'index_type');
  54. }
  55. get _fieldName() {
  56. return this.field_name;
  57. }
  58. get _metricType() {
  59. return this.params.find(p => p.key === 'metric_type')?.value || '';
  60. }
  61. }