Skip to content

Fix search #791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/templates/components/search-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
onfocus={{action 'onfocus'}}
onblur={{action 'onblur'}}
placeholder="Search"
data-test-search-input
>
{{!-- Search results dropdown --}}
<EmberTether @target="#search-input" @targetAttachment="bottom left" @attachment="top left" @constraints={{this._resultTetherConstraints}} @class="ds-dropdown-results">
Expand Down
6 changes: 3 additions & 3 deletions app/templates/components/search-input/dropdown-result.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
<div class="algolia-docsearch-suggestion--content">
{{#if this.result.static}}
<LinkTo @route="project-version.functions.function" @models={{array this.module this.version this.result.class this.result.name}}>
<LinkTo @route="project-version.functions.function" @models={{array this.module this.version this.result.class this.result.name}} data-test-search-result>
<div class="algolia-docsearch-suggestion--subcategory-inline">
{{!-- Sometimes hierarchy lvl1 is null, fall-back to lvl0 --}}
{{#if this.result._highlightResult.hierarchy.lvl1}}
Expand All @@ -28,7 +28,7 @@
</div>
</LinkTo>
{{else}}
<LinkTo @route="project-version.classes.class.methods.method" @models={{array this.module this.version}} @query={{hash anchor=this.result.name}}>
<LinkTo @route="project-version.classes.class.methods.method" @models={{array this.module this.version result.class result.name}} @query={{hash anchor=this.result.name}} data-test-search-result>
<div class="algolia-docsearch-suggestion--subcategory-inline">
{{!-- Sometimes hierarchy lvl1 is null, fall-back to lvl0 --}}
{{#if this.result._highlightResult.hierarchy.lvl1}}
Expand All @@ -54,4 +54,4 @@
</div>
</div>

{{yield}}
{{yield}}
28 changes: 28 additions & 0 deletions tests/acceptance/search-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { module, test } from 'qunit';
import { visit, currentURL, fillIn, click } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';

import searchResults from 'ember-api-docs/tests/fixtures/searchresult';

module('Acceptance | search', function (hooks) {
setupApplicationTest(hooks);

test('search for an EmberArray function and navigate properly', async function (assert) {
await visit('/');

const algoliaService = this.owner.lookup('service:algolia');

algoliaService.search = async () => {
return searchResults;
};

await fillIn('[data-test-search-input]', 'forEach');

await click('[data-test-search-result]');

assert.equal(
currentURL(),
'/ember/4.1/classes/EmberArray/methods/forEach?anchor=forEach'
);
});
});
178 changes: 178 additions & 0 deletions tests/fixtures/searchresult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
export default {
hits: [
{
file: 'packages/@ember/-internals/runtime/lib/mixins/array.js',
line: 473,
module: '@ember/array',
class: 'EmberArray',
name: 'forEach',
access: 'public',
_tags: ['module:@ember/array', 'version:4.1.0'],
hierarchy: {
lvl0: '@ember/array',
lvl1: 'EmberArray',
lvl2: 'forEach',
},
objectID: '7173445001',
_highlightResult: {
name: {
value: '<em>forEach</em>',
matchLevel: 'full',
fullyHighlighted: true,
matchedWords: ['foreach'],
},
hierarchy: {
lvl0: {
value: '@ember/array',
matchLevel: 'none',
matchedWords: [],
},
lvl1: {
value: 'EmberArray',
matchLevel: 'none',
matchedWords: [],
},
lvl2: {
value: '<em>forEach</em>',
matchLevel: 'full',
fullyHighlighted: true,
matchedWords: ['foreach'],
},
},
},
},
{
file: 'packages/@ember/-internals/runtime/lib/mixins/array.js',
line: 473,
module: '@ember/array',
class: 'MutableArray',
name: 'forEach',
access: 'public',
_tags: ['module:@ember/array', 'version:4.1.0'],
hierarchy: {
lvl0: '@ember/array',
lvl1: 'MutableArray',
lvl2: 'forEach',
},
objectID: '7173416001',
_highlightResult: {
name: {
value: '<em>forEach</em>',
matchLevel: 'full',
fullyHighlighted: true,
matchedWords: ['foreach'],
},
hierarchy: {
lvl0: {
value: '@ember/array',
matchLevel: 'none',
matchedWords: [],
},
lvl1: {
value: 'MutableArray',
matchLevel: 'none',
matchedWords: [],
},
lvl2: {
value: '<em>forEach</em>',
matchLevel: 'full',
fullyHighlighted: true,
matchedWords: ['foreach'],
},
},
},
},
{
file: 'packages/@ember/-internals/runtime/lib/mixins/array.js',
line: 473,
module: '@ember/array',
class: 'Ember.NativeArray',
name: 'forEach',
access: 'public',
_tags: ['module:@ember/array', 'version:4.1.0'],
hierarchy: {
lvl0: '@ember/array',
lvl1: 'Ember.NativeArray',
lvl2: 'forEach',
},
objectID: '7173371001',
_highlightResult: {
name: {
value: '<em>forEach</em>',
matchLevel: 'full',
fullyHighlighted: true,
matchedWords: ['foreach'],
},
hierarchy: {
lvl0: {
value: '@ember/array',
matchLevel: 'none',
matchedWords: [],
},
lvl1: {
value: 'Ember.NativeArray',
matchLevel: 'none',
matchedWords: [],
},
lvl2: {
value: '<em>forEach</em>',
matchLevel: 'full',
fullyHighlighted: true,
matchedWords: ['foreach'],
},
},
},
},
{
file: 'packages/@ember/-internals/runtime/lib/mixins/array.js',
line: 473,
module: '@ember/array',
class: 'ArrayProxy',
name: 'forEach',
access: 'public',
_tags: ['module:@ember/array', 'version:4.1.0'],
hierarchy: {
lvl0: '@ember/array',
lvl1: 'ArrayProxy',
lvl2: 'forEach',
},
objectID: '7173290001',
_highlightResult: {
name: {
value: '<em>forEach</em>',
matchLevel: 'full',
fullyHighlighted: true,
matchedWords: ['foreach'],
},
hierarchy: {
lvl0: {
value: '@ember/array',
matchLevel: 'none',
matchedWords: [],
},
lvl1: {
value: 'ArrayProxy',
matchLevel: 'none',
matchedWords: [],
},
lvl2: {
value: '<em>forEach</em>',
matchLevel: 'full',
fullyHighlighted: true,
matchedWords: ['foreach'],
},
},
},
},
],
nbHits: 4,
page: 0,
nbPages: 1,
hitsPerPage: 15,
exhaustiveNbHits: true,
exhaustiveTypo: true,
query: 'forEach',
params:
'query=forEach&hitsPerPage=15&restrictSearchableAttributes=%5B%22hierarchy.lvl0%22%2C%22hierarchy.lvl1%22%2C%22hierarchy.lvl2%22%5D&tagFilters=%5B%22version%3A4.1.0%22%5D&facetFilters=%5B%22access%3A-private%22%5D',
processingTimeMS: 1,
};