@@ -7,7 +7,7 @@ import { CallsService } from './calls.service';
77import { Store } from '@ngrx/store' ;
88import { CLOSEDOCUMENT , AppState } from './searchreducer' ;
99import { StrixEvent } from './strix-event.enum' ;
10- import { filter , switchMap } from 'rxjs/operators' ;
10+ import { filter , switchMap , tap } from 'rxjs/operators' ;
1111import * as _ from 'lodash' ;
1212
1313/**
@@ -37,10 +37,10 @@ export class QueryService {
3737 aggregationResult$ = this . aggregationResultSubject . asObservable ( ) ;
3838
3939 // Components should subscribe to the searchStatus$ stream
40- // to know the *status* of the search (for displaying such
40+ // to know the *status* of the search (for displaying such
4141 // things as progress bars):
4242 // REM: searchStatusSubject needs to be a BehaviorSubject
43- // so that any subscribing components can get the latest
43+ // so that any subscribing components can get the latest
4444 // state directly upon subscribing.
4545 private searchStatusSubject = new BehaviorSubject < StrixEvent > ( StrixEvent . INIT ) ;
4646 searchStatus$ = this . searchStatusSubject . asObservable ( ) ;
@@ -68,7 +68,7 @@ export class QueryService {
6868 //let keywordSearch = this.currentQuery.keyword_search || false;
6969 //return !keywordSearch;
7070 }
71-
71+
7272 public setSearchString ( searchString : string ) : void {
7373 this . currentQuery . queryString = searchString ;
7474 }
@@ -100,7 +100,7 @@ export class QueryService {
100100 // ... we'll see what the future brings
101101 }
102102 }
103-
103+
104104 private runAggregationQuery ( query : StrixQuery ) {
105105 if ( query . type === QueryType . Normal ) {
106106 console . log ( "adding an aggregation search to the stream of streams" ) ;
@@ -112,8 +112,18 @@ export class QueryService {
112112
113113 onInit ( ) {
114114
115+ /* switchMap makes sure only the most recently added query stream is listened to.
116+ All other streams are unsubscribed and the $http request should, as a
117+ consequence be cancelled. */
118+ this . streamOfStreams . pipe ( switchMap ( obj => obj ) ) . subscribe ( ( value : SearchResult ) => {
119+ this . signalEndedSearch ( ) ;
120+ this . searchResultSubject . next ( value ) ;
121+ } ) ;
122+ this . streamOfAggregationStreams . pipe ( switchMap ( obj => obj ) ) . subscribe ( ( value : AggregationsResult ) => {
123+ this . aggregationResultSubject . next ( value ) ;
124+ } ) ;
125+
115126 this . store . select ( 'query' ) . subscribe ( data => {
116- /* React upon the action SEARCH, most likely triggering a main query search. */
117127 const previousQuery = this . currentQuery ;
118128 this . currentQuery = new StrixQuery ( ) ;
119129 this . currentQuery . type = < QueryType > data . type ;
@@ -126,25 +136,13 @@ export class QueryService {
126136 this . currentQuery . keyword_search = data . keyword_search
127137 }
128138 if ( ! _ . isEqual ( this . currentQuery , previousQuery ) ) {
139+ console . log ( 'new query' ) ;
129140 this . runCurrentQuery ( ) ; // Perform the actual search
130141 }
131142 } ) ;
132143
133- /* Redo the last query when the user closes the open document */
134- this . store . select ( 'ui' ) . pipe ( filter ( ui => ui . latestAction === CLOSEDOCUMENT ) ) . subscribe ( ( ) => {
135- if ( this . currentQuery ) this . runCurrentQuery ( ) ; // REM: Don't know why it's sometimes null (and only in Firefox, it seems..)
136- } ) ;
137-
138- /* switchMap makes sure only the most recently added query stream is listened to.
139- All other streams are unsubscribed and the $http request should, as a
140- consequence be cancelled. */
141- this . streamOfStreams . pipe ( switchMap ( obj => obj ) ) . subscribe ( ( value : SearchResult ) => {
142- this . signalEndedSearch ( ) ;
143- this . searchResultSubject . next ( value ) ;
144- } ) ;
145- this . streamOfAggregationStreams . pipe ( switchMap ( obj => obj ) ) . subscribe ( ( value : AggregationsResult ) => {
146- this . aggregationResultSubject . next ( value ) ;
147- } ) ;
144+ // console.log('QueryService init run query');
145+ // this.runCurrentQuery();
148146 }
149147
150148}
0 commit comments