Improves ordering of search results
Modifies documents.search to return a context snippet and search ranking Displays context snipped on search results screen
This commit is contained in:
@@ -226,13 +226,16 @@ router.post('documents.search', auth(), pagination(), async ctx => {
|
||||
ctx.assertPresent(query, 'query is required');
|
||||
|
||||
const user = ctx.state.user;
|
||||
const documents = await Document.searchForUser(user, query, {
|
||||
const results = await Document.searchForUser(user, query, {
|
||||
offset,
|
||||
limit,
|
||||
});
|
||||
|
||||
const data = await Promise.all(
|
||||
documents.map(async document => await presentDocument(ctx, document))
|
||||
results.map(async result => {
|
||||
const document = await presentDocument(ctx, result.document);
|
||||
return { ...result, document };
|
||||
})
|
||||
);
|
||||
|
||||
ctx.body = {
|
||||
|
||||
@@ -228,7 +228,7 @@ describe('#documents.search', async () => {
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.length).toEqual(1);
|
||||
expect(body.data[0].text).toEqual('# Much guidance');
|
||||
expect(body.data[0].document.text).toEqual('# Much guidance');
|
||||
});
|
||||
|
||||
it('should require authentication', async () => {
|
||||
|
||||
@@ -64,14 +64,14 @@ router.post('hooks.slack', async ctx => {
|
||||
|
||||
if (!user) throw new InvalidRequestError('Invalid user');
|
||||
|
||||
const documents = await Document.searchForUser(user, text, {
|
||||
const results = await Document.searchForUser(user, text, {
|
||||
limit: 5,
|
||||
});
|
||||
|
||||
if (documents.length) {
|
||||
if (results.length) {
|
||||
const attachments = [];
|
||||
for (const document of documents) {
|
||||
attachments.push(presentSlackAttachment(document));
|
||||
for (const result of results) {
|
||||
attachments.push(presentSlackAttachment(result.document));
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
|
||||
Reference in New Issue
Block a user