Skip to content

Commit

Permalink
ids query implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan687 committed Jul 28, 2016
1 parent 7681ec5 commit c0bc208
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 5 deletions.
97 changes: 97 additions & 0 deletions app/build/singlequery/queries/ids.query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { Component, OnInit, OnChanges, Input, Output, EventEmitter } from "@angular/core";

@Component({
selector: 'ids-query',
template: `<span class="col-xs-6 pd-0">
<div class="form-group form-element">
<input type="text" class="form-control col-xs-12"
[(ngModel)]="inputs.input.value"
placeholder="{{inputs.input.placeholder}}"
(keyup)="getFormat();" />
</div>
</span>`,
inputs: ['appliedQuery', 'queryList', 'selectedQuery', 'selectedField','getQueryFormat', 'selectedTypes']
})

export class IdsQuery implements OnInit, OnChanges {
@Input() queryList: any;
@Input() selectedField: any;
@Input() appliedQuery: any;
@Input() selectedQuery: any;
@Input() selectedTypes: any;
@Output() getQueryFormat = new EventEmitter<any>();
public queryName = '*';
public fieldName = '*';
public information: any = {
title: 'Ids query',
content: `<span class="description"> Ids query content </span>
<a class="link" href="https://www.elastic.co/guide/en/elasticsearch/reference/2.3/query-dsl-terms-query.html">Documentation</a>`
};

public inputs: any = {
input: {
placeholder: 'Input',
value: ''
}
};
public queryFormat: any = {};

ngOnInit() {
try {
if(this.appliedQuery['ids']) {
try {
this.inputs.input.value = this.appliedQuery['ids'].values.join(' ');
} catch(e) {
this.inputs.input.value = this.appliedQuery['ids'].values;
}
}
} catch(e) {}
this.getFormat();
}
ngOnChanges() {
if(this.selectedField != '') {
if(this.selectedField !== this.fieldName) {
this.fieldName = this.selectedField;
this.getFormat();
}
}
if(this.selectedQuery != '') {
if(this.selectedQuery !== this.queryName) {
this.queryName = this.selectedQuery;
this.getFormat();
}
}
}

// QUERY FORMAT
/*
Query Format for this query is
@queryName: {
@fieldName: {
type: @type,
values: @value
}
}
*/

getFormat() {
if (this.queryName === 'ids') {
this.queryFormat = this.setFormat();
this.getQueryFormat.emit(this.queryFormat);
}
}
setFormat() {
var queryFormat = {};
queryFormat[this.queryName] = {
values: [],
type: this.selectedTypes
};
try {
queryFormat[this.queryName].values = this.inputs.input.value.split(' ');
} catch(e) {
queryFormat[this.queryName].values = [];
}
return queryFormat;
}

}
15 changes: 14 additions & 1 deletion app/build/singlequery/singlequery.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,20 @@
</fuzzy-query>
</div>
<!-- regexp query end -->


<!-- ids query start -->
<div [hidden]="query.selectedQuery != 'ids'" class="row">
<ids-query
[appliedQuery]="query.appliedQuery"
[queryList]="queryList"
[selectedQuery]="query.selectedQuery"
[selectedField]="query.selectedField"
[selectedTypes]="selectedTypes"
(getQueryFormat)="getQueryFormat($event);"
>
</ids-query>
</div>
<!-- ids query end -->

<!-- load the slector for selected query -->
</div>
8 changes: 6 additions & 2 deletions app/build/singlequery/singlequery.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { MissingQuery } from './queries/missing.query';
import { WildcardQuery } from './queries/wildcard.query';
import { RegexpQuery } from './queries/regexp.query';
import { FuzzyQuery } from './queries/fuzzy.query';
import { IdsQuery } from './queries/ids.query';

@Component({
selector: 'single-query',
Expand All @@ -43,7 +44,8 @@ import { FuzzyQuery } from './queries/fuzzy.query';
PrefixQuery,
WildcardQuery,
RegexpQuery,
FuzzyQuery
FuzzyQuery,
IdsQuery
]
})

Expand Down Expand Up @@ -83,6 +85,7 @@ export class SinglequeryComponent implements OnInit, OnChanges, AfterViewInit {
@ViewChild(WildcardQuery) private wildcardQuery: WildcardQuery;
@ViewChild(RegexpQuery) private regexpQuery: RegexpQuery;
@ViewChild(FuzzyQuery) private fuzzyQuery: FuzzyQuery;
@ViewChild(IdsQuery) private idsQuery: IdsQuery;

public informationList: any = {};
@Input() query: any;
Expand Down Expand Up @@ -121,7 +124,8 @@ export class SinglequeryComponent implements OnInit, OnChanges, AfterViewInit {
'prefix': this.prefixQuery.information,
'wildcard': this.wildcardQuery.information,
'regexp': this.regexpQuery.information,
'fuzzy': this.fuzzyQuery.information
'fuzzy': this.fuzzyQuery.information,
'ids': this.idsQuery.information
};
}

Expand Down
6 changes: 4 additions & 2 deletions app/shared/queryList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ export var queryList = {
'regexp',
'fuzzy',
'simple_query_string',
'match-phase-prefix'
'match-phase-prefix',
'ids'
],
numeric: [
'match',
'range',
'gt',
'lt',
'exists',
'missing'
'missing',
'ids'
]
},
not_analyzed: {
Expand Down

0 comments on commit c0bc208

Please sign in to comment.