mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Added urls to search resources
refs https://github.com/TryGhost/Team/issues/1665 - We need a way to visit the resource found through search. It should not be included in searchable fields though
This commit is contained in:
parent
b0afdaba10
commit
8b59245893
2 changed files with 30 additions and 6 deletions
|
@ -50,7 +50,7 @@ export default class SearchIndex {
|
||||||
elasticlunr.clearStopWords();
|
elasticlunr.clearStopWords();
|
||||||
|
|
||||||
const postsAPIUrl = `${this.apiUrl}/posts/?key=${this.apiKey}&limit=all&fields=id,slug,title,excerpt,url,updated_at,visibility&order=updated_at%20desc&formats=plaintext`;
|
const postsAPIUrl = `${this.apiUrl}/posts/?key=${this.apiKey}&limit=all&fields=id,slug,title,excerpt,url,updated_at,visibility&order=updated_at%20desc&formats=plaintext`;
|
||||||
const authorsAPIUrl = `${this.apiUrl}/authors/?key=${this.apiKey}&limit=all&fields=id,slug,name,profile_image`;
|
const authorsAPIUrl = `${this.apiUrl}/authors/?key=${this.apiKey}&limit=all&fields=id,slug,name,url,profile_image`;
|
||||||
const tagsAPIUrl = `${this.apiUrl}/tags/?key=${this.apiKey}&limit=all&fields=id,slug,name,url`;
|
const tagsAPIUrl = `${this.apiUrl}/tags/?key=${this.apiKey}&limit=all&fields=id,slug,name,url`;
|
||||||
|
|
||||||
const indexDump = JSON.parse(this.storage.getItem('ease_search_index'));
|
const indexDump = JSON.parse(this.storage.getItem('ease_search_index'));
|
||||||
|
@ -65,6 +65,7 @@ export default class SearchIndex {
|
||||||
if (posts.posts.length > 0) {
|
if (posts.posts.length > 0) {
|
||||||
this.postsIndex = elasticlunr();
|
this.postsIndex = elasticlunr();
|
||||||
this.postsIndex.addField('title');
|
this.postsIndex.addField('title');
|
||||||
|
this.postsIndex.addField('url');
|
||||||
this.postsIndex.addField('excerpt');
|
this.postsIndex.addField('excerpt');
|
||||||
this.postsIndex.setRef('id');
|
this.postsIndex.setRef('id');
|
||||||
|
|
||||||
|
@ -77,6 +78,7 @@ export default class SearchIndex {
|
||||||
if (authors.authors.length > 0) {
|
if (authors.authors.length > 0) {
|
||||||
this.authorsIndex = elasticlunr();
|
this.authorsIndex = elasticlunr();
|
||||||
this.authorsIndex.addField('name');
|
this.authorsIndex.addField('name');
|
||||||
|
this.authorsIndex.addField('url');
|
||||||
this.authorsIndex.setRef('id');
|
this.authorsIndex.setRef('id');
|
||||||
|
|
||||||
this.#updateAuthorsIndex(authors);
|
this.#updateAuthorsIndex(authors);
|
||||||
|
@ -88,6 +90,7 @@ export default class SearchIndex {
|
||||||
if (tags.tags.length > 0) {
|
if (tags.tags.length > 0) {
|
||||||
this.tagsIndex = elasticlunr();
|
this.tagsIndex = elasticlunr();
|
||||||
this.tagsIndex.addField('name');
|
this.tagsIndex.addField('name');
|
||||||
|
this.tagsIndex.addField('url');
|
||||||
this.tagsIndex.setRef('id');
|
this.tagsIndex.setRef('id');
|
||||||
|
|
||||||
this.#updateTagsIndex(tags);
|
this.#updateTagsIndex(tags);
|
||||||
|
@ -107,9 +110,25 @@ export default class SearchIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
search(value) {
|
search(value) {
|
||||||
const posts = this.postsIndex.search(value, {expand: true});
|
const posts = this.postsIndex.search(value, {
|
||||||
const authors = this.authorsIndex.search(value, {expand: true});
|
fields: {
|
||||||
const tags = this.tagsIndex.search(value, {expand: true});
|
title: {boost: 1},
|
||||||
|
excerpt: {boost: 1}
|
||||||
|
},
|
||||||
|
expand: true
|
||||||
|
});
|
||||||
|
const authors = this.authorsIndex.search(value, {
|
||||||
|
fields: {
|
||||||
|
name: {boost: 1}
|
||||||
|
},
|
||||||
|
expand: true
|
||||||
|
});
|
||||||
|
const tags = this.tagsIndex.search(value, {
|
||||||
|
fields: {
|
||||||
|
name: {boost: 1}
|
||||||
|
},
|
||||||
|
expand: true
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
posts: posts.map((doc) => {
|
posts: posts.map((doc) => {
|
||||||
|
|
|
@ -16,7 +16,7 @@ describe('search index', function () {
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
posts: [{}]
|
posts: [{}]
|
||||||
})
|
})
|
||||||
.get('/authors/?key=secret_key&limit=all&fields=id,slug,name,profile_image')
|
.get('/authors/?key=secret_key&limit=all&fields=id,slug,name,url,profile_image')
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
authors: [{
|
authors: [{
|
||||||
id: 'different_uniq',
|
id: 'different_uniq',
|
||||||
|
@ -50,13 +50,18 @@ describe('search index', function () {
|
||||||
excerpt: 'We are sitting by the pool and smashing out search features'
|
excerpt: 'We are sitting by the pool and smashing out search features'
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
.get('/authors/?key=secret_key&limit=all&fields=id,slug,name,profile_image')
|
.get('/authors/?key=secret_key&limit=all&fields=id,slug,name,url,profile_image')
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
authors: [{
|
authors: [{
|
||||||
id: 'different_uniq',
|
id: 'different_uniq',
|
||||||
slug: 'barcelona-author',
|
slug: 'barcelona-author',
|
||||||
name: 'Barcelona Author',
|
name: 'Barcelona Author',
|
||||||
profile_image: 'https://url_to_avatar/barcelona.png'
|
profile_image: 'https://url_to_avatar/barcelona.png'
|
||||||
|
}, {
|
||||||
|
id: 'different_uniq_2',
|
||||||
|
slug: 'bob',
|
||||||
|
name: 'Bob',
|
||||||
|
profile_image: 'https://url_to_avatar/barcelona.png'
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
.get('/tags/?key=secret_key&&limit=all&fields=id,slug,name,url')
|
.get('/tags/?key=secret_key&&limit=all&fields=id,slug,name,url')
|
||||||
|
|
Loading…
Add table
Reference in a new issue