From de36e1ca5dfcb4845a0be202629b6dc4e630a812 Mon Sep 17 00:00:00 2001 From: Maxime Locqueville Date: Tue, 13 Dec 2016 11:39:27 +0100 Subject: [PATCH] display(highlighting): improve for camel_case --- src/lib/utils.js | 19 ++++++++++++++----- test/DocSearch-test.js | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/lib/utils.js b/src/lib/utils.js index ffbdcdbc..b2b8881c 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -195,12 +195,21 @@ let utils = { * @return {string} **/ getHighlightedValue(object, property) { - if (!object._highlightResult - || !object._highlightResult[property] - || !object._highlightResult[property].value) { - return object[property]; + if (object._highlightResult + && object._highlightResult.hierarchy_camel + && object._highlightResult.hierarchy_camel[property] + && object._highlightResult.hierarchy_camel[property].matchLevel + && object._highlightResult.hierarchy_camel[property].matchLevel !== 'none' + && object._highlightResult.hierarchy_camel[property].value) { + return object._highlightResult.hierarchy_camel[property].value; } - return object._highlightResult[property].value; + if (object._highlightResult + && object._highlightResult + && object._highlightResult[property] + && object._highlightResult[property].value) { + return object._highlightResult[property].value; + } + return object[property]; }, /* * Returns the snippeted value of the specified key in the specified object. diff --git a/test/DocSearch-test.js b/test/DocSearch-test.js index 9371b674..c6f51a41 100644 --- a/test/DocSearch-test.js +++ b/test/DocSearch-test.js @@ -622,6 +622,47 @@ describe('DocSearch', () => { expect(actual[0].category).toEqual('Ruby'); expect(actual[0].subcategory).toEqual('API'); }); + + it('should use highlighted camel if exists and matchLevel not none', () => { + // Given + let input = [{ + hierarchy: { + lvl0: 'Ruby', + lvl1: 'API', + lvl2: 'Foo', + lvl3: null, + lvl4: null, + lvl5: null + }, + _highlightResult: { + hierarchy_camel: { + lvl0: { + value: 'Python', + matchLevel: 'full' + }, + lvl1: { + value: 'API2', + matchLevel: 'full' + } + }, + hierarchy: { + lvl0: { + value: 'Ruby' + }, + lvl1: { + value: 'API' + } + } + } + }]; + + // When + let actual = DocSearch.formatHits(input); + + // Then + expect(actual[0].category).toEqual('Python'); + expect(actual[0].subcategory).toEqual('API2'); + }); it('should use lvl2 as title', () => { // Given let input = [{