mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-03 12:08:31 +00:00
refactor for searchQuery
This commit is contained in:
parent
4ff856d164
commit
638e1daa8e
@ -483,6 +483,13 @@ export const AuthProvider = ({
|
||||
// Escape special characters for exact matching
|
||||
const domainStatement = escapeESReservedCharacters(activeDomain);
|
||||
|
||||
// Create domain filter using term query for exact matching
|
||||
const domainFilter = {
|
||||
term: {
|
||||
'domains.fullyQualifiedName': domainStatement,
|
||||
},
|
||||
};
|
||||
|
||||
// Move domain filter to proper queryFilter structure
|
||||
if (queryParams.query_filter) {
|
||||
// Merge with existing query_filter
|
||||
@ -490,32 +497,18 @@ export const AuthProvider = ({
|
||||
queryParams.query_filter = JSON.stringify({
|
||||
query: {
|
||||
bool: {
|
||||
must: [
|
||||
existingFilter.query || existingFilter,
|
||||
{
|
||||
match: {
|
||||
'domains.fullyQualifiedName': domainStatement,
|
||||
},
|
||||
},
|
||||
],
|
||||
must: [existingFilter.query || existingFilter, domainFilter],
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// Create new query_filter with proper structure
|
||||
queryParams.query_filter = JSON.stringify({
|
||||
query: {
|
||||
match: {
|
||||
'domains.fullyQualifiedName': domainStatement,
|
||||
},
|
||||
},
|
||||
query: domainFilter,
|
||||
});
|
||||
}
|
||||
|
||||
// Clear the q parameter if it exists since we're using query_filter
|
||||
if (queryParams.q === '') {
|
||||
delete queryParams.q;
|
||||
}
|
||||
// Don't clear the q parameter - let it contain search text only
|
||||
|
||||
// Update the URL with the modified query parameter
|
||||
config.url = `${config.url.split('?')[0]}?${Qs.stringify(queryParams)}`;
|
||||
|
||||
@ -65,7 +65,6 @@ import { useCustomPages } from '../../../hooks/useCustomPages';
|
||||
import { useFqn } from '../../../hooks/useFqn';
|
||||
import { addDataProducts } from '../../../rest/dataProductAPI';
|
||||
import { addDomains } from '../../../rest/domainAPI';
|
||||
import { searchData } from '../../../rest/miscAPI';
|
||||
import { searchQuery } from '../../../rest/searchAPI';
|
||||
import { getIsErrorMatch } from '../../../utils/CommonUtils';
|
||||
import {
|
||||
@ -241,19 +240,22 @@ const DomainDetailsPage = ({
|
||||
const fetchSubDomainsCount = useCallback(async () => {
|
||||
if (!isVersionsView) {
|
||||
try {
|
||||
const res = await searchData(
|
||||
'',
|
||||
0,
|
||||
0,
|
||||
`(parent.fullyQualifiedName:"${encodedFqn}")`,
|
||||
'',
|
||||
'',
|
||||
SearchIndex.DOMAIN,
|
||||
false,
|
||||
true
|
||||
);
|
||||
const res = await searchQuery({
|
||||
query: '',
|
||||
pageNumber: 1,
|
||||
pageSize: 0,
|
||||
queryFilter: {
|
||||
query: {
|
||||
term: {
|
||||
'parent.fullyQualifiedName.keyword': encodedFqn,
|
||||
},
|
||||
},
|
||||
},
|
||||
searchIndex: SearchIndex.DOMAIN,
|
||||
trackTotalHits: true,
|
||||
});
|
||||
|
||||
const totalCount = res.data.hits.total.value ?? 0;
|
||||
const totalCount = res.hits.total.value ?? 0;
|
||||
setSubDomainsCount(totalCount);
|
||||
} catch (error) {
|
||||
setSubDomainsCount(0);
|
||||
@ -347,17 +349,21 @@ const DomainDetailsPage = ({
|
||||
const fetchDataProducts = async () => {
|
||||
if (!isVersionsView) {
|
||||
try {
|
||||
const res = await searchData(
|
||||
'',
|
||||
1,
|
||||
0,
|
||||
`(domains.fullyQualifiedName:"${encodedFqn}")`,
|
||||
'',
|
||||
'',
|
||||
SearchIndex.DATA_PRODUCT
|
||||
);
|
||||
const res = await searchQuery({
|
||||
query: '',
|
||||
pageNumber: 1,
|
||||
pageSize: 0,
|
||||
queryFilter: {
|
||||
query: {
|
||||
term: {
|
||||
'domains.fullyQualifiedName': encodedFqn,
|
||||
},
|
||||
},
|
||||
},
|
||||
searchIndex: SearchIndex.DATA_PRODUCT,
|
||||
});
|
||||
|
||||
setDataProductsCount(res.data.hits.total.value ?? 0);
|
||||
setDataProductsCount(res.hits.total.value ?? 0);
|
||||
} catch (error) {
|
||||
setDataProductsCount(0);
|
||||
showErrorToast(
|
||||
|
||||
@ -29,7 +29,7 @@ import { EntityType } from '../../../../enums/entity.enum';
|
||||
import { SearchIndex } from '../../../../enums/search.enum';
|
||||
import { DataProduct } from '../../../../generated/entity/domains/dataProduct';
|
||||
import { useFqn } from '../../../../hooks/useFqn';
|
||||
import { searchData } from '../../../../rest/miscAPI';
|
||||
import { searchQuery } from '../../../../rest/searchAPI';
|
||||
import { formatDataProductResponse } from '../../../../utils/APIUtils';
|
||||
import {
|
||||
escapeESReservedCharacters,
|
||||
@ -62,20 +62,24 @@ const DataProductsTab = forwardRef(
|
||||
try {
|
||||
setLoading(true);
|
||||
const encodedFqn = getEncodedFqn(escapeESReservedCharacters(domainFqn));
|
||||
const res = await searchData(
|
||||
'',
|
||||
1,
|
||||
PAGE_SIZE_LARGE,
|
||||
`(domains.fullyQualifiedName:"${encodedFqn}")`,
|
||||
'',
|
||||
'',
|
||||
SearchIndex.DATA_PRODUCT
|
||||
);
|
||||
const res = await searchQuery({
|
||||
query: '',
|
||||
pageNumber: 1,
|
||||
pageSize: PAGE_SIZE_LARGE,
|
||||
queryFilter: {
|
||||
query: {
|
||||
term: {
|
||||
'domains.fullyQualifiedName': encodedFqn,
|
||||
},
|
||||
},
|
||||
},
|
||||
searchIndex: SearchIndex.DATA_PRODUCT,
|
||||
});
|
||||
|
||||
const data = formatDataProductResponse(res.data.hits.hits);
|
||||
const data = formatDataProductResponse(res.hits.hits);
|
||||
setDataProducts({
|
||||
data: data,
|
||||
paging: { total: res.data.hits.total.value ?? 0 },
|
||||
paging: { total: res.hits.total.value ?? 0 },
|
||||
});
|
||||
if (data.length > 0) {
|
||||
setSelectedCard(data[0]);
|
||||
|
||||
@ -21,7 +21,7 @@ import { ERROR_PLACEHOLDER_TYPE } from '../../../enums/common.enum';
|
||||
import { SearchIndex } from '../../../enums/search.enum';
|
||||
import { Domain } from '../../../generated/entity/domains/domain';
|
||||
import { usePaging } from '../../../hooks/paging/usePaging';
|
||||
import { searchData } from '../../../rest/miscAPI';
|
||||
import { searchQuery } from '../../../rest/searchAPI';
|
||||
import { formatDomainsResponse } from '../../../utils/APIUtils';
|
||||
import { getEntityName } from '../../../utils/EntityUtils';
|
||||
import { getDomainDetailsPath } from '../../../utils/RouterUtils';
|
||||
@ -60,20 +60,23 @@ const SubDomainsTable = ({
|
||||
try {
|
||||
setIsLoading(true);
|
||||
|
||||
const res = await searchData(
|
||||
'',
|
||||
currentPage,
|
||||
const res = await searchQuery({
|
||||
query: '',
|
||||
pageNumber: currentPage,
|
||||
pageSize,
|
||||
`(parent.fullyQualifiedName:"${encodedFqn}")`,
|
||||
'',
|
||||
'',
|
||||
SearchIndex.DOMAIN,
|
||||
false,
|
||||
true
|
||||
);
|
||||
queryFilter: {
|
||||
query: {
|
||||
term: {
|
||||
'parent.fullyQualifiedName.keyword': encodedFqn,
|
||||
},
|
||||
},
|
||||
},
|
||||
searchIndex: SearchIndex.DOMAIN,
|
||||
includeDeleted: false,
|
||||
});
|
||||
|
||||
const data = formatDomainsResponse(res.data.hits.hits);
|
||||
const totalCount = res.data.hits.total.value ?? 0;
|
||||
const data = formatDomainsResponse(res.hits.hits);
|
||||
const totalCount = res.hits.total.value ?? 0;
|
||||
setSubDomains(data);
|
||||
|
||||
handlePagingChange({
|
||||
|
||||
@ -101,11 +101,18 @@ const Services = ({ serviceName }: ServicesProps) => {
|
||||
const [deleted, setDeleted] = useState<boolean>(false);
|
||||
const { permissions } = usePermissionProvider();
|
||||
|
||||
const filterString = useMemo(() => {
|
||||
const serviceTypeQueryFilter = useMemo(() => {
|
||||
return serviceTypeFilter?.length
|
||||
? `(${serviceTypeFilter
|
||||
.map((type) => `serviceType:${type}`)
|
||||
.join(' OR ')})`
|
||||
? {
|
||||
query: {
|
||||
bool: {
|
||||
should: serviceTypeFilter.map((type) => ({
|
||||
term: { 'serviceType.keyword': type },
|
||||
})),
|
||||
minimum_should_match: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
}, [serviceTypeFilter]);
|
||||
|
||||
@ -143,19 +150,19 @@ const Services = ({ serviceName }: ServicesProps) => {
|
||||
currentPage,
|
||||
after,
|
||||
before,
|
||||
filters,
|
||||
queryFilter,
|
||||
}: {
|
||||
search?: string;
|
||||
limit?: number;
|
||||
currentPage?: number;
|
||||
after?: string;
|
||||
before?: string;
|
||||
filters?: string;
|
||||
queryFilter?: Record<string, unknown>;
|
||||
}) => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
let services = [];
|
||||
if (search || !isEmpty(filters)) {
|
||||
if (search || queryFilter) {
|
||||
const {
|
||||
hits: { hits, total },
|
||||
} = await searchService({
|
||||
@ -163,7 +170,7 @@ const Services = ({ serviceName }: ServicesProps) => {
|
||||
searchIndex,
|
||||
limit: pageSize,
|
||||
currentPage,
|
||||
filters,
|
||||
queryFilter,
|
||||
deleted,
|
||||
});
|
||||
|
||||
@ -207,23 +214,23 @@ const Services = ({ serviceName }: ServicesProps) => {
|
||||
|
||||
const handleServicePageChange = useCallback(
|
||||
({ cursorType, currentPage }: PagingHandlerParams) => {
|
||||
if (searchTerm || filterString) {
|
||||
if (searchTerm || serviceTypeQueryFilter) {
|
||||
handlePageChange(currentPage);
|
||||
getServiceDetails({
|
||||
currentPage,
|
||||
search: searchTerm,
|
||||
limit: pageSize,
|
||||
filters: filterString,
|
||||
queryFilter: serviceTypeQueryFilter,
|
||||
});
|
||||
} else if (cursorType) {
|
||||
handlePageChange(currentPage);
|
||||
getServiceDetails({
|
||||
[cursorType]: paging[cursorType],
|
||||
filters: filterString,
|
||||
queryFilter: serviceTypeQueryFilter,
|
||||
});
|
||||
}
|
||||
},
|
||||
[getServiceDetails, searchTerm, filterString, paging, pageSize]
|
||||
[getServiceDetails, searchTerm, serviceTypeQueryFilter, paging, pageSize]
|
||||
);
|
||||
|
||||
const addServicePermission = useMemo(
|
||||
@ -270,7 +277,11 @@ const Services = ({ serviceName }: ServicesProps) => {
|
||||
}, [serviceName]);
|
||||
|
||||
const noDataPlaceholder = useMemo(() => {
|
||||
if (addServicePermission && isEmpty(searchTerm) && !filterString) {
|
||||
if (
|
||||
addServicePermission &&
|
||||
isEmpty(searchTerm) &&
|
||||
!serviceTypeQueryFilter
|
||||
) {
|
||||
return (
|
||||
<ErrorPlaceHolder
|
||||
className="p-lg border-none"
|
||||
@ -297,7 +308,7 @@ const Services = ({ serviceName }: ServicesProps) => {
|
||||
servicesDisplayName,
|
||||
serviceName,
|
||||
searchTerm,
|
||||
filterString,
|
||||
serviceTypeQueryFilter,
|
||||
addServicePermission,
|
||||
handleAddServiceClick,
|
||||
]);
|
||||
@ -462,9 +473,16 @@ const Services = ({ serviceName }: ServicesProps) => {
|
||||
getServiceDetails({
|
||||
search: searchTerm,
|
||||
limit: pageSize,
|
||||
filters: filterString,
|
||||
queryFilter: serviceTypeQueryFilter,
|
||||
});
|
||||
}, [searchIndex, pageSize, serviceName, searchTerm, filterString, deleted]);
|
||||
}, [
|
||||
searchIndex,
|
||||
pageSize,
|
||||
serviceName,
|
||||
searchTerm,
|
||||
serviceTypeQueryFilter,
|
||||
deleted,
|
||||
]);
|
||||
|
||||
const handleTableChange: TableProps<ServicesType>['onChange'] = (
|
||||
_pagination,
|
||||
|
||||
@ -31,7 +31,7 @@ import {
|
||||
} from '../interface/service.interface';
|
||||
import { getEncodedFqn } from '../utils/StringsUtils';
|
||||
import APIClient from './index';
|
||||
import { searchData } from './miscAPI';
|
||||
import { searchQuery } from './searchAPI';
|
||||
|
||||
interface ServiceRequestParams {
|
||||
limit?: number;
|
||||
@ -183,28 +183,26 @@ export const searchService = async ({
|
||||
searchIndex,
|
||||
currentPage = 1,
|
||||
limit = PAGE_SIZE,
|
||||
filters,
|
||||
queryFilter,
|
||||
deleted = false,
|
||||
}: {
|
||||
search?: string;
|
||||
searchIndex: SearchIndex | SearchIndex[];
|
||||
limit?: number;
|
||||
currentPage?: number;
|
||||
filters?: string;
|
||||
queryFilter?: Record<string, unknown>;
|
||||
deleted?: boolean;
|
||||
}) => {
|
||||
const response = await searchData(
|
||||
search ?? WILD_CARD_CHAR,
|
||||
currentPage,
|
||||
limit,
|
||||
filters ?? '',
|
||||
'',
|
||||
'',
|
||||
const response = await searchQuery({
|
||||
query: search ?? WILD_CARD_CHAR,
|
||||
pageNumber: currentPage,
|
||||
pageSize: limit,
|
||||
queryFilter,
|
||||
searchIndex,
|
||||
deleted
|
||||
);
|
||||
includeDeleted: deleted,
|
||||
});
|
||||
|
||||
return response.data;
|
||||
return response;
|
||||
};
|
||||
|
||||
export const restoreService = async (serviceCategory: string, id: string) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user