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

feat(integration): Make the save search result option configurable #1206

Merged
merged 5 commits into from
Mar 27, 2023
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
34 changes: 18 additions & 16 deletions packages/geo/src/lib/feature/shared/strategies/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,24 @@ export class FeatureStoreSearchIndexStrategy extends EntityStoreStrategy {
return Object.assign({}, {field: sf2.name, tokenize: "full"}, sf2.searchIndex);
});
} else {
// THIS METHOD COMPUTE COLUMN DISTINCT VALUE TO FILTER WHICH COLUMN TO INDEX BASED ON A RATIO or discard float columns
const columns = Object.keys(featuresProperties[0]);
const columnsToIndex = [];
columnsToNotIndex = columns.map((column) => {
const distinctValues = [...new Set(featuresProperties.map(item => item[column]))];
// identify column to not index based on a ratio distinctValues/nb of features OR discart exclusive float column (ex: lat, long)
if (
(distinctValues.length / featuresProperties.length) * 100 <= ratio ||
distinctValues.every(n => Number(n) === n && n % 1 !== 0)) {
columnsToNotIndex.push(column);
} else {
columnsToIndex.push(column);
}
}).filter(f => f);
const keysToIndex = columnsToIndex.filter(f => f!== 'igoSearchID');
contentToIndex = keysToIndex.map(key => {return {field: key,tokenize: "full"};});
if (featuresProperties.length) {
// THIS METHOD COMPUTE COLUMN DISTINCT VALUE TO FILTER WHICH COLUMN TO INDEX BASED ON A RATIO or discard float columns
const columns = Object.keys(featuresProperties[0]);
const columnsToIndex = [];
columnsToNotIndex = columns.map((column) => {
const distinctValues = [...new Set(featuresProperties.map(item => item[column]))];
// identify column to not index based on a ratio distinctValues/nb of features OR discart exclusive float column (ex: lat, long)
if (
(distinctValues.length / featuresProperties.length) * 100 <= ratio ||
distinctValues.every(n => Number(n) === n && n % 1 !== 0)) {
columnsToNotIndex.push(column);
} else {
columnsToIndex.push(column);
}
}).filter(f => f);
const keysToIndex = columnsToIndex.filter(f => f !== 'igoSearchID');
contentToIndex = keysToIndex.map(key => { return { field: key, tokenize: "full" }; });
}
}
store.index.forEach((value, key) => {
const propertiesToIndex = JSON.parse(JSON.stringify(value.properties));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h1 mat-dialog-title class="mat-typography">{{'igo.geo.layer.saveFeatureInLayer'
[matAutocomplete]="auto"
formControlName="layerName">
<mat-autocomplete [displayWith]="displayFn" #auto="matAutocomplete">
<mat-option *ngFor="let layer of filteredLayers | async" [value]="layer">
<mat-option *ngFor="let layer of filteredLayers$ | async" [value]="layer">
<p mat-line>{{layer.title}}</p>
</mat-option>
</mat-autocomplete>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class SaveFeatureDialogComponent implements OnInit {
public form: UntypedFormGroup;
feature: SearchResult;
layers: Layer[] = [];
filteredLayers: Observable<Layer[]>;
filteredLayers$: Observable<Layer[]>;

constructor(
private formBuilder: UntypedFormBuilder,
Expand All @@ -35,7 +35,7 @@ export class SaveFeatureDialogComponent implements OnInit {
ngOnInit() {
this.feature = this.data.feature;
this.layers = this.data.layers;
this.filteredLayers = this.form.controls['layerName'].valueChanges.pipe(
this.filteredLayers$ = this.form.controls['layerName'].valueChanges.pipe(
startWith(''),
map(val => this.filter(val))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import OlOverlay from 'ol/Overlay';
import { VectorSourceEvent as OlVectorSourceEvent } from 'ol/source/Vector';
import { default as OlGeometry } from 'ol/geom/Geometry';
import { QueryableDataSourceOptions } from '../../query';
import { createOverlayDefaultStyle } from '../../style/shared/overlay/overlay-style.utils';


@Component({
Expand Down Expand Up @@ -334,12 +333,18 @@ export class SearchResultAddButtonComponent implements OnInit, OnDestroy{
id: 'igo-search-layer' + ++layerCounterID,
title: layerTitle,
source: dataSource,
style: createOverlayDefaultStyle({
text: '',
strokeWidth: 1,
fillColor: 'rgba(255,255,255,0.4)',
strokeColor: 'rgba(143,7,7,1)'
}),
igoStyle: {
editable: false,
igoStyleObject: {
fill: { color: 'rgba(255,255,255,0.4)' },
stroke: { color: 'rgba(143,7,7,1)', width: 1 },
circle: {
fill: { color: 'rgba(255,255,255,0.4)', },
stroke: { color: 'rgba(143,7,7,1)', width: 1 },
radius: 5,
}
}
},
showInLayerList: true,
exportable: true,
workspace: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h4><strong>{{ 'igo.integration.searchResultsTool.noResults' | translate }}</str
(resultMouseleave)="onResultUnfocus($event)"
(moreResults)="onSearch($event)"
[map]="map">
<ng-template #igoSearchItemToolbar let-result="result">
<ng-template #igoSearchItemToolbar let-result="result" *ngIf="saveSearchResultInLayer">
<igo-search-add-button
[map]="map"
[store]="store"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class SearchResultsToolComponent implements OnInit, OnDestroy {
@Input() topPanelStateDefault: string = 'expanded';

private hasFeatureEmphasisOnSelection: boolean = false;
public saveSearchResultInLayer: boolean = false;

private showResultsGeometries$$: Subscription;
private getRoute$$: Subscription;
Expand Down Expand Up @@ -167,6 +168,9 @@ export class SearchResultsToolComponent implements OnInit, OnDestroy {
this.hasFeatureEmphasisOnSelection = configService.getConfig(
'hasFeatureEmphasisOnSelection'
);
this.saveSearchResultInLayer = configService.getConfig(
'saveSearchResultInLayer'
);
}

ngOnInit() {
Expand Down