@dhyasama/totem-models 10.13.0 → 10.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -804,6 +804,88 @@ module.exports = function(mongoose, config) {
804
804
 
805
805
  };
806
806
 
807
+ LimitedPartner.statics.search2 = function search2(value, options, cb) {
808
+
809
+ const self = this;
810
+
811
+ if (!cb) { throw new Error('cb is required'); }
812
+ if (!value) { return cb(new Error('value is required'), null); }
813
+ if (!options) { return cb(new Error('options is required'), null); }
814
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
815
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
816
+
817
+ const defaultOptions = {
818
+ limit: 10,
819
+ maxEdits: 1,
820
+ maxExpansions: 100
821
+ };
822
+
823
+ // combine provided and default options
824
+ options = _.defaults(options || {}, defaultOptions);
825
+
826
+ self.aggregate([
827
+ {
828
+ "$search": {
829
+ index: 'default',
830
+ compound: {
831
+ should: [
832
+ {
833
+ autocomplete: {
834
+ query: value,
835
+ path: 'name',
836
+ fuzzy: {
837
+ maxEdits: options.maxEdits,
838
+ maxExpansions: options.maxExpansions
839
+ }
840
+ }
841
+ },
842
+ {
843
+ text: {
844
+ query: value,
845
+ path: 'name',
846
+ fuzzy: {
847
+ maxEdits: options.maxEdits,
848
+ maxExpansions: options.maxExpansions
849
+ },
850
+ score: { boost: { value: 3 } }
851
+ }
852
+ }
853
+ ],
854
+ must: [
855
+ {
856
+ equals: {
857
+ path: 'customer',
858
+ value: mongoose.Types.ObjectId(options.CUSTOMER_ID)
859
+ }
860
+ }
861
+ ],
862
+ minimumShouldMatch: 1
863
+ }
864
+ }
865
+ },
866
+ {
867
+ $limit: options.limit,
868
+ },
869
+ {
870
+ $project: {
871
+ name: 1,
872
+ score: { $meta: "searchScore" }
873
+ }
874
+ }
875
+ ]).exec(function(err, orgs) {
876
+
877
+ if (err) { return cb(err, null); }
878
+
879
+ orgs = _.map(orgs, function(org) {
880
+ return helpers.cleanOrg(org, options.CUSTOMER_ID);
881
+ });
882
+
883
+ return cb(null, orgs);
884
+
885
+ });
886
+
887
+ };
888
+
807
889
  LimitedPartner.statics.upsert = function(lp, username, options, cb) {
808
890
 
809
891
  if (!cb) { throw new Error('cb is required'); }
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  const _ = require("underscore");
4
+ const utilities = require("@dhyasama/totem-utilities");
5
+ const helpers = require("../helpers");
4
6
  module.exports = function(mongoose, config) {
5
7
 
6
8
  let
@@ -1290,6 +1292,87 @@ module.exports = function(mongoose, config) {
1290
1292
  this.find({ 'slug': { $in : slugs } }).exec(cb);
1291
1293
  };
1292
1294
 
1295
+ Organization.statics.findBySocial2 = function findBySocial2(value, options, cb) {
1296
+
1297
+ // Extract stand-alone username and append it to our standardized domains
1298
+
1299
+ const self = this;
1300
+
1301
+ if (!cb) { throw new Error('cb is required'); }
1302
+ if (!value) { return cb(new Error('value is required'), null); }
1303
+ if (!options) { return cb(new Error('options is required'), null); }
1304
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
1305
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
1306
+
1307
+ const defaultMaxEdits = 1;
1308
+ const defaultMaxExpansions = 100;
1309
+ const username = utilities.getUsernameFromUrl(value);
1310
+
1311
+ if (!username) { return cb(null, []); }
1312
+
1313
+ self.aggregate([
1314
+ {
1315
+ "$search": {
1316
+ index: 'organizations_search_autocomplete',
1317
+ compound: {
1318
+ should: [
1319
+ {
1320
+ autocomplete: {
1321
+ query: username,
1322
+ path: 'social_handle.facebook',
1323
+ fuzzy: {
1324
+ maxEdits: defaultMaxEdits,
1325
+ maxExpansions: defaultMaxExpansions
1326
+ }
1327
+ }
1328
+ },
1329
+ {
1330
+ autocomplete: {
1331
+ query: username,
1332
+ path: 'social_handle.linkedin',
1333
+ fuzzy: {
1334
+ maxEdits: defaultMaxEdits,
1335
+ maxExpansions: defaultMaxExpansions
1336
+ }
1337
+ }
1338
+ },
1339
+ {
1340
+ autocomplete: {
1341
+ query: username,
1342
+ path: 'social_handle.twitter',
1343
+ fuzzy: {
1344
+ maxEdits: defaultMaxEdits,
1345
+ maxExpansions: defaultMaxExpansions
1346
+ }
1347
+ }
1348
+ }
1349
+ ],
1350
+ must: [
1351
+ {
1352
+ equals: {
1353
+ path: 'deleted',
1354
+ value: false
1355
+ }
1356
+ }
1357
+ ],
1358
+ minimumShouldMatch: 1
1359
+ }
1360
+ }
1361
+ }
1362
+ ]).exec(function(err, orgs) {
1363
+
1364
+ if (err) { return cb(err, null); }
1365
+
1366
+ orgs = _.map(orgs, function(org) {
1367
+ return helpers.cleanOrg(org, options.CUSTOMER_ID);
1368
+ });
1369
+
1370
+ return cb(null, orgs);
1371
+
1372
+ });
1373
+
1374
+ };
1375
+
1293
1376
  Organization.statics.findBySocial = function findBySocial(value, options, cb) {
1294
1377
 
1295
1378
  // Extract stand-alone username and append it to our standardized domains
@@ -1789,6 +1872,47 @@ module.exports = function(mongoose, config) {
1789
1872
 
1790
1873
  };
1791
1874
 
1875
+ // Organization.statics.atlasSearch = function (query, options, cb) {
1876
+ //
1877
+ // const self = this;
1878
+ //
1879
+ // const defaultOptions = {
1880
+ // limit: 100
1881
+ // };
1882
+ //
1883
+ // // combine provided and default options
1884
+ // options = _.defaults(options || {}, defaultOptions);
1885
+ //
1886
+ // self.aggregate([
1887
+ // {
1888
+ // '$search': {
1889
+ // 'index': 'default',
1890
+ // 'text': {
1891
+ // 'query': query,
1892
+ // 'path': {
1893
+ // 'wildcard': '*'
1894
+ // }
1895
+ // }
1896
+ // }
1897
+ // }, {
1898
+ // '$match': {
1899
+ // 'deleted': false
1900
+ // }
1901
+ // }, {
1902
+ // $limit: options.limit,
1903
+ // }, {
1904
+ // "$project": {
1905
+ // "_id": 1,
1906
+ // "fullName": 1,
1907
+ // "name": 1,
1908
+ // "avatarUrl": 1,
1909
+ // "score": { "$meta": "searchScore" }
1910
+ // }
1911
+ // }
1912
+ // ], cb);
1913
+ //
1914
+ // };
1915
+
1792
1916
  Organization.statics.search = function search(data, options, cb) {
1793
1917
 
1794
1918
  // search for orgs based on fields provided
@@ -1946,6 +2070,119 @@ module.exports = function(mongoose, config) {
1946
2070
 
1947
2071
  };
1948
2072
 
2073
+ Organization.statics.search2 = function search2(value, options, cb) {
2074
+
2075
+ const self = this;
2076
+
2077
+ if (!cb) { throw new Error('cb is required'); }
2078
+ if (!value) { return cb(new Error('value is required'), null); }
2079
+ if (!options) { return cb(new Error('options is required'), null); }
2080
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
2081
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
2082
+
2083
+ const defaultOptions = {
2084
+ limit: 10,
2085
+ maxEdits: 1,
2086
+ maxExpansions: 100
2087
+ };
2088
+
2089
+ // combine provided and default options
2090
+ options = _.defaults(options || {}, defaultOptions);
2091
+
2092
+ self.aggregate([
2093
+ {
2094
+ "$search": {
2095
+ index: 'default',
2096
+ compound: {
2097
+ should: [
2098
+ {
2099
+ autocomplete: {
2100
+ query: value,
2101
+ path: 'name',
2102
+ fuzzy: {
2103
+ maxEdits: options.maxEdits,
2104
+ maxExpansions: options.maxExpansions
2105
+ }
2106
+ }
2107
+ },
2108
+ {
2109
+ text: {
2110
+ query: value,
2111
+ path: 'name',
2112
+ fuzzy: {
2113
+ maxEdits: options.maxEdits,
2114
+ maxExpansions: options.maxExpansions
2115
+ },
2116
+ score: { boost: { value: 3 } }
2117
+ }
2118
+ },
2119
+ {
2120
+ autocomplete: {
2121
+ query: value,
2122
+ path: 'aliases',
2123
+ fuzzy: {
2124
+ maxEdits: options.maxEdits,
2125
+ maxExpansions: options.maxExpansions
2126
+ }
2127
+ }
2128
+ },
2129
+ {
2130
+ autocomplete: {
2131
+ query: value,
2132
+ path: 'website',
2133
+ fuzzy: {
2134
+ maxEdits: options.maxEdits,
2135
+ maxExpansions: options.maxExpansions
2136
+ }
2137
+ }
2138
+ },
2139
+ {
2140
+ autocomplete: {
2141
+ query: value,
2142
+ path: 'websiteAliases',
2143
+ fuzzy: {
2144
+ maxEdits: options.maxEdits,
2145
+ maxExpansions: options.maxExpansions
2146
+ }
2147
+ }
2148
+ }
2149
+ ],
2150
+ must: [
2151
+ {
2152
+ equals: {
2153
+ path: 'deleted',
2154
+ value: false
2155
+ }
2156
+ }
2157
+ ],
2158
+ minimumShouldMatch: 1
2159
+ }
2160
+ }
2161
+ },
2162
+ {
2163
+ $limit: options.limit,
2164
+ },
2165
+ {
2166
+ $project: {
2167
+ name: 1,
2168
+ logoUrl: 1,
2169
+ score: { $meta: "searchScore" }
2170
+ }
2171
+ }
2172
+ ]).exec(function(err, orgs) {
2173
+
2174
+ if (err) { return cb(err, null); }
2175
+
2176
+ orgs = _.map(orgs, function(org) {
2177
+ return helpers.cleanOrg(org, options.CUSTOMER_ID);
2178
+ });
2179
+
2180
+ return cb(null, orgs);
2181
+
2182
+ });
2183
+
2184
+ };
2185
+
1949
2186
  Organization.statics.upsert = function(org, username, cb) {
1950
2187
 
1951
2188
  if (!org) { return cb(new Error('Organization is required'), null); }
package/lib/Person.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const _ = require("underscore");
4
+
4
5
  module.exports = function(mongoose, config) {
5
6
 
6
7
  let
@@ -1041,6 +1042,124 @@ const _ = require("underscore");
1041
1042
 
1042
1043
  };
1043
1044
 
1045
+ Person.statics.search2 = function (query, options, cb) {
1046
+
1047
+ const self = this;
1048
+
1049
+ const defaultOptions = {
1050
+ limit: 10,
1051
+ maxEdits: 1,
1052
+ maxExpansions: 100
1053
+ };
1054
+
1055
+ // combine provided and default options
1056
+ options = _.defaults(options || {}, defaultOptions);
1057
+
1058
+ self.aggregate([
1059
+ {
1060
+ "$search": {
1061
+ index: 'default',
1062
+ compound: {
1063
+ should: [
1064
+ {
1065
+ autocomplete: {
1066
+ query: query,
1067
+ path: 'name.first',
1068
+ fuzzy: {
1069
+ maxEdits: options.maxEdits,
1070
+ maxExpansions: options.maxExpansions
1071
+ }
1072
+ }
1073
+ },
1074
+ {
1075
+ text: {
1076
+ query: query,
1077
+ path: 'name.first',
1078
+ fuzzy: {
1079
+ maxEdits: options.maxEdits,
1080
+ maxExpansions: options.maxExpansions
1081
+ }
1082
+ }
1083
+ },
1084
+ {
1085
+ autocomplete: {
1086
+ query: query,
1087
+ path: 'name.last',
1088
+ fuzzy: {
1089
+ maxEdits: options.maxEdits,
1090
+ maxExpansions: options.maxExpansions
1091
+ }
1092
+ }
1093
+ },
1094
+ {
1095
+ text: {
1096
+ query: query,
1097
+ path: 'name.last',
1098
+ fuzzy: {
1099
+ maxEdits: options.maxEdits,
1100
+ maxExpansions: options.maxExpansions
1101
+ }
1102
+ }
1103
+ },
1104
+ {
1105
+ autocomplete: {
1106
+ query: query,
1107
+ path: 'fullName',
1108
+ fuzzy: {
1109
+ maxEdits: options.maxEdits,
1110
+ maxExpansions: options.maxExpansions
1111
+ },
1112
+ }
1113
+ },
1114
+ {
1115
+ text: {
1116
+ query: query,
1117
+ path: 'fullName',
1118
+ fuzzy: {
1119
+ maxEdits: options.maxEdits,
1120
+ maxExpansions: options.maxExpansions
1121
+ },
1122
+ score: { boost: { value: 3 } }
1123
+ }
1124
+ },
1125
+ {
1126
+ autocomplete: {
1127
+ query: query,
1128
+ path: 'aliases',
1129
+ fuzzy: {
1130
+ maxEdits: options.maxEdits,
1131
+ maxExpansions: options.maxExpansions
1132
+ }
1133
+ }
1134
+ }
1135
+ ],
1136
+ must: [
1137
+ {
1138
+ equals: {
1139
+ path: 'deleted',
1140
+ value: false
1141
+ }
1142
+ }
1143
+ ],
1144
+ minimumShouldMatch: 1
1145
+ }
1146
+ }
1147
+ }, {
1148
+ $limit: options.limit,
1149
+ }, {
1150
+ "$project": {
1151
+ "_id": 1,
1152
+ "fullName": 1,
1153
+ "name": 1,
1154
+ "avatarUrl": 1,
1155
+ "sources": 1,
1156
+ "score": { "$meta": "searchScore" }
1157
+ }
1158
+ }
1159
+ ], cb);
1160
+
1161
+ };
1162
+
1044
1163
  Person.statics.searchByEmail = function(email, cb) {
1045
1164
 
1046
1165
  if (!cb) throw new Error('cb is required');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "10.13.0",
3
+ "version": "10.14.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",