提交 edcb27d7 编写于 作者: J Joao Moreno

parse category: and tag: in marketplace queries

fixes #27605
上级 54b8d4d9
......@@ -297,7 +297,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
}
const type = options.names ? 'ids' : (options.text ? 'text' : 'all');
const text = options.text || '';
let text = options.text || '';
const pageSize = getOrDefault(options, o => o.pageSize, 50);
this.telemetryService.publicLog('galleryService:query', { type, text });
......@@ -310,7 +310,25 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
.withAssetTypes(AssetType.Icon, AssetType.License, AssetType.Details, AssetType.Manifest, AssetType.VSIX, AssetType.Changelog);
if (text) {
query = query.withFilter(FilterType.SearchText, text).withSortBy(SortBy.NoneOrRelevance);
// Use category filter instead of "category:themes"
text = text.replace(/\bcategory:("([^"]*)"|([^"]\S*))(\s+|\b|$)/g, (_, quotedCategory, category) => {
query = query.withFilter(FilterType.Category, category || quotedCategory);
return '';
});
// Use tag filter instead of "tag:debuggers"
text = text.replace(/\btag:("([^"]*)"|([^"]\S*))(\s+|\b|$)/g, (_, quotedTag, tag) => {
query = query.withFilter(FilterType.Tag, tag || quotedTag);
return '';
});
text = text.trim();
if (text) {
query = query.withFilter(FilterType.SearchText, text);
}
query = query.withSortBy(SortBy.NoneOrRelevance);
} else if (options.ids) {
query = query.withFilter(FilterType.ExtensionId, ...options.ids);
} else if (options.names) {
......@@ -327,6 +345,8 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
query = query.withSortOrder(options.sortOrder);
}
console.log(query.raw);
return this.queryGallery(query).then(({ galleryExtensions, total }) => {
const extensions = galleryExtensions.map(e => toExtension(e, this.extensionsGalleryUrl));
const pageSize = query.pageSize;
......@@ -337,34 +357,34 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
});
}
private queryGallery(query: Query): TPromise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> {
return this.commonHTTPHeaders
.then(headers => {
const data = JSON.stringify(query.raw);
private async queryGallery(query: Query): TPromise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> {
const commonHeaders = await this.commonHTTPHeaders;
const data = JSON.stringify(query.raw);
const headers = assign({}, commonHeaders, {
'Content-Type': 'application/json',
'Accept': 'application/json;api-version=3.0-preview.1',
'Accept-Encoding': 'gzip',
'Content-Length': data.length
});
headers = assign({}, headers, {
'Content-Type': 'application/json',
'Accept': 'application/json;api-version=3.0-preview.1',
'Accept-Encoding': 'gzip',
'Content-Length': data.length
});
const context = await this.requestService.request({
type: 'POST',
url: this.api('/extensionquery'),
data,
headers
});
return this.requestService.request({
type: 'POST',
url: this.api('/extensionquery'),
data,
headers
});
})
.then(context => asJson<IRawGalleryQueryResult>(context))
.then(result => {
const r = result.results[0];
const galleryExtensions = r.extensions;
const resultCount = r.resultMetadata && r.resultMetadata.filter(m => m.metadataType === 'ResultCount')[0];
const total = resultCount && resultCount.metadataItems.filter(i => i.name === 'TotalCount')[0].count || 0;
return { galleryExtensions, total };
});
if (context.res.statusCode >= 400 && context.res.statusCode < 500) {
return { galleryExtensions: [], total: 0 };
}
const result = await asJson<IRawGalleryQueryResult>(context);
const r = result.results[0];
const galleryExtensions = r.extensions;
const resultCount = r.resultMetadata && r.resultMetadata.filter(m => m.metadataType === 'ResultCount')[0];
const total = resultCount && resultCount.metadataItems.filter(i => i.name === 'TotalCount')[0].count || 0;
return { galleryExtensions, total };
}
download(extension: IGalleryExtension): TPromise<string> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册