Skip to content
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

[Webcomponents] : Full text search #1122

Merged
merged 5 commits into from
Mar 2, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
body {
margin: 0;
overflow-y: scroll;
font-family: var(--font-family-main);
}
header {
height: 200px;
Expand Down Expand Up @@ -50,9 +51,9 @@
main-color="#555"
background-color="#fdfbff"
main-font="'Inter', sans-serif"
filter='{"OrgForResource": { "Géo2France": true } }'
title-font="'DM Serif Display', serif"
show-more="auto"
filter='{"OrgForResourceObject.default": { "Géo2France": true } }'
></gn-results-list>
</main>
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
<gn-ui-fuzzy-search #searchInput class="text-[18px]"></gn-ui-fuzzy-search>
<gn-ui-fuzzy-search
class="text-[18px] pointer-events-auto"
style="--gn-ui-text-input-padding: 1.1em; --gn-ui-text-input-border-size: 0px"
(itemSelected)="select($event)"
(inputSubmitted)="search($event)"
[autoFocus]="true"
></gn-ui-fuzzy-search>
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,25 @@ import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'
encapsulation: ViewEncapsulation.ShadowDom,
providers: [SearchFacade, SearchService],
})
export class GnSearchInputComponent
extends BaseComponent
implements AfterViewChecked
{
export class GnSearchInputComponent extends BaseComponent {
@Input() openOnSearch: string
@Input() openOnSelect: string
@ViewChild('searchInput') searchInput: FuzzySearchComponent

ngAfterViewChecked() {
search(any: string) {
if (this.openOnSearch) {
this.searchInput.inputSubmitted.subscribe(this.search.bind(this))
}
if (this.openOnSelect) {
this.searchInput.itemSelected.subscribe(this.select.bind(this))
const landingPage = this.openOnSearch.replace(/\$\{search}/, any)
window.open(landingPage, '_self').focus()
}
}

search(any: string) {
const landingPage = this.openOnSearch.replace(/\$\{search}/, any)
window.open(landingPage, '_self').focus()
}

select(record: CatalogRecord) {
const landingPage = this.openOnSelect.replace(
/\$\{uuid}/,
record.uniqueIdentifier
)
window.open(landingPage, '_self').focus()
if (this.openOnSelect) {
const landingPage = this.openOnSelect.replace(
/\$\{uuid}/,
record.uniqueIdentifier
)
window.open(landingPage, '_self').focus()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<style>
body {
margin: 0;
font-family: var(--font-family-main);
}
header {
height: 200px;
Expand Down
1 change: 0 additions & 1 deletion apps/webcomponents/src/app/webcomponents.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const CUSTOM_ELEMENTS: [new (...args) => BaseComponent, string][] = [
]

@NgModule({
exports: [],
declarations: [
AppComponent,
BaseComponent,
Expand Down
18 changes: 11 additions & 7 deletions apps/webcomponents/src/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '../../../tailwind.base.css';

@tailwind base;
@tailwind components;
@tailwind utilities;
Expand Down Expand Up @@ -89,13 +91,6 @@
display: none;
}

.mat-mdc-autocomplete-panel {
background: #fff;
box-shadow:
0 2px 4px -1px #0003,
0 4px 5px #00000024,
0 1px 10px #0000001f;
}
.mat-mdc-option.suggestion.mat-mdc-option-active {
background-color: var(--color-primary-lightest);
}
Expand All @@ -121,3 +116,12 @@
.mat-mdc-option.mat-selected:not(.mat-mdc-option-multiple) {
background: rgba(0, 0, 0, 0.12);
}
.mdc-menu-surface.mat-mdc-autocomplete-panel {
margin-top: 10px !important;
border-radius: 8px;
background: white;
box-shadow:
0 2px 4px -1px #0003,
0 4px 5px #00000024,
0 1px 10px #0000001f;
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,32 @@ describe('ElasticsearchService', () => {
})

describe('#getSearchRequestBody', () => {
describe('#track_total_hits', () => {
let payload
describe('request fields', () => {
it('includes the _source property if fields are specified', () => {
payload = service.getSearchRequestBody({}, 4, 0, null, ['uuid', 'tag'])
expect(payload).toEqual({
_source: ['uuid', 'tag'],
from: 0,
size: 4,
query: expect.any(Object),
aggregations: expect.any(Object),
track_total_hits: true,
})
})
it('does not include the _source property if no field specified', () => {
payload = service.getSearchRequestBody({}, 4, 0, null, null)
expect(payload).toEqual({
from: 0,
size: 4,
query: expect.any(Object),
aggregations: expect.any(Object),
track_total_hits: true,
})
})
})
describe('track_total_hits', () => {
let size = 0
let payload
describe('when size is 0', () => {
beforeEach(() => {
payload = service.getSearchRequestBody({}, size)
Expand Down Expand Up @@ -450,6 +473,37 @@ describe('ElasticsearchService', () => {
},
})
})
it('handle values expressed as reg exp', () => {
const query = service['buildPayloadQuery'](
{
Org: {
'/world.*/': true,
'/*country^[fr|en]/': false,
},
},
{},
[]
)
expect(query).toMatchObject({
bool: {
filter: [
{
terms: {
isTemplate: ['n'],
},
},
{
query_string: {
query: 'Org:(/world.*/ OR -/*country^[fr|en]/)',
},
},
{
ids: { values: [] },
},
],
},
})
})
describe('any has special characters', () => {
let query
beforeEach(() => {
Expand Down Expand Up @@ -554,7 +608,9 @@ describe('ElasticsearchService', () => {
})

describe('#injectLangInQueryStringFields - Search language', () => {
let queryStringFields = { 'resourceTitleObject.${searchLang}': 1 }
let queryStringFields: Record<string, number> = {
'resourceTitleObject.${searchLang}': 1,
}
describe('When no lang from config', () => {
beforeEach(() => {
service['metadataLang'] = undefined
Expand Down Expand Up @@ -895,14 +951,16 @@ describe('ElasticsearchService', () => {
).toStrictEqual({
myFilters: {
filters: {
filter1: {
query_string: { query: 'field1:(100)' },
},
filter2: {
query_string: { query: 'field2:("value1" OR "value3")' },
},
filter3: {
query_string: { query: 'my own query' },
filters: {
filter1: {
query_string: { query: 'field1:(100)' },
},
filter2: {
query_string: { query: 'field2:("value1" OR "value3")' },
},
filter3: {
query_string: { query: 'my own query' },
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ElasticsearchService {
size = 0,
from = 0,
sortBy: SortByField = null,
requestFields: RequestFields = [],
requestFields: RequestFields = null,
searchFilters: SearchFilters = {},
configFilters: SearchFilters = {},
uuids?: string[],
Expand All @@ -68,7 +68,7 @@ export class ElasticsearchService {
geometry
),
...(size > 0 ? { track_total_hits: true } : {}),
_source: requestFields,
...(requestFields && { _source: requestFields }),
}
this.processRuntimeFields(payload)
return payload
Expand Down Expand Up @@ -220,16 +220,17 @@ export class ElasticsearchService {
private filtersToQuery(
filters: FieldFilters | FiltersAggregationParams | string
): FilterQuery {
const addQuote = (key: string) => (/^\/.+\/$/.test(key) ? key : `"${key}"`)
const makeQuery = (filter: FieldFilter): string => {
if (typeof filter === 'string') {
return filter
}
return Object.keys(filter)
.map((key) => {
if (filter[key] === true) {
return `"${key}"`
return addQuote(key)
}
return `-"${key}"`
return `-${addQuote(key)}`
})
.join(' OR ')
}
Expand Down Expand Up @@ -518,13 +519,15 @@ export class ElasticsearchService {
switch (aggregation.type) {
case 'filters':
return {
filters: Object.keys(aggregation.filters).reduce((prev, curr) => {
const filter = aggregation.filters[curr]
return {
...prev,
[curr]: this.filtersToQuery(filter)[0],
}
}, {}),
filters: {
filters: Object.keys(aggregation.filters).reduce((prev, curr) => {
const filter = aggregation.filters[curr]
return {
...prev,
[curr]: this.filtersToQuery(filter)[0],
}
}, {}),
},
}
case 'terms':
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ describe.each(['4.2.2-00', '4.2.3-xx', '4.2.5-xx'])(
filter: [{ terms: { isTemplate: ['n'] } }],
},
},
_source: [],
})
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe('FieldsService', () => {
'publisherOrg',
'user',
'changeDate',
'availableServices',
])
})
})
Expand Down Expand Up @@ -188,6 +189,7 @@ describe('FieldsService', () => {
publisherOrg: [],
user: [],
changeDate: [],
availableServices: [],
})
})
})
Expand Down
2 changes: 2 additions & 0 deletions libs/feature/search/src/lib/utils/service/fields.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable, Injector } from '@angular/core'
import {
AbstractSearchField,
AvailableServicesField,
DateRangeSearchField,
FieldValue,
FullTextSearchField,
Expand Down Expand Up @@ -91,6 +92,7 @@ export class FieldsService {
),
user: new UserSearchField(this.injector),
changeDate: new DateRangeSearchField('changeDate', this.injector, 'desc'),
availableServices: new AvailableServicesField(this.injector),
} as Record<string, AbstractSearchField>

get supportedFields() {
Expand Down
Loading
Loading