Created
November 8, 2017 13:23
-
-
Save jbin/130c8ff852268bd7ced119bd26891973 to your computer and use it in GitHub Desktop.
Angular-Solr Simple Search Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form (ngSubmit)="search()" #searchForm="ngForm"> | |
<input type="search" name="term" [(ngModel)]="term"> | |
<button type="submit">Suchen</button> | |
</form> | |
<ul> | |
<li *ngFor="let result of results "> | |
{{result.name}} | |
</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, ViewEncapsulation } from '@angular/core'; | |
import { HttpClient } from '@angular/common/http'; | |
import { Observable } from 'rxjs/Observable'; | |
@Component({ | |
selector: 'app-solr-search', | |
templateUrl: './solr-search.component.html', | |
styleUrls: ['./solr-search.component.css'], | |
encapsulation: ViewEncapsulation.None | |
}) | |
export class SolrSearchComponent implements OnInit { | |
readonly solrURL = 'http://192.168.99.100:8983/solr/demo/select'; | |
results: Array<any>; | |
term: string = ''; | |
constructor(private http: HttpClient) { } | |
ngOnInit() { | |
} | |
search() { | |
this.http.get<any>(this.solrURL + '?df=features&q=' + this.term).subscribe( | |
(data) => this.results = data.response.docs | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://jensbinfet.de/blog/tutorial-eine-einfache-angular-solr-komponente-entwickeln/