Skip to content

Instantly share code, notes, and snippets.

@jbin
Created November 8, 2017 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbin/130c8ff852268bd7ced119bd26891973 to your computer and use it in GitHub Desktop.
Save jbin/130c8ff852268bd7ced119bd26891973 to your computer and use it in GitHub Desktop.
Angular-Solr Simple Search Method
<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>
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