3 var troupeService
= require('gitter-web-rooms/lib/troupe-service');
4 var oneToOneTypeahead
= require('./user-typeahead-one-to-one');
5 var elasticTypeahead
= require('./user-typeahead-elastic');
6 var userSearchService
= require('../user-search-service');
7 var env
= require('gitter-web-env');
8 var errorReporter
= env
.errorReporter
;
9 var logger
= env
.logger
;
11 module
.exports
.query = function(text
, options
) {
12 var roomId
= (options
|| {}).roomId
;
15 return troupeService
.findById(roomId
).then(function(room
) {
17 return oneToOneTypeahead
.query(text
, room
);
19 // elastic typeahead doesnt know about oneToOnes
20 return alphaFallbackTypeahead(text
, { roomId
: roomId
});
24 return alphaFallbackTypeahead(text
);
28 // while we are using elasticsearch 5 alphas, we better have a fallback
29 function alphaFallbackTypeahead(text
, options
) {
30 return elasticTypeahead
.query(text
, options
).catch(function(err
) {
31 logger
.error('typeahead alpha experienced an error, falling back to old typeahead', {
34 errorReporter(err
, { text
: text
, options
: options
}, { module
: 'user-typeahead' });
36 return oldTypeahead(text
, options
);
40 function oldTypeahead(text
, options
) {
41 var roomId
= (options
|| {}).roomId
|| '*';
44 return userSearchService
.searchForUsersInRoom(text
, roomId
).then(function(res
) {
48 return userSearchService
.globalUserSearch(text
).then(function(res
) {