[FIX] User search on directory not working correctly (#17299)

pull/17278/head^2
Rodrigo Nascimento 5 years ago committed by GitHub
parent ae903c23b0
commit 94e9fcc593
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/lib/server/startup/settings.js
  2. 11
      app/models/server/models/Users.js
  3. 13
      server/startup/migrations/v183.js

@ -97,9 +97,8 @@ settings.addGroup('Accounts', function() {
type: 'boolean',
public: true,
});
this.add('Accounts_SearchFields', '', {
this.add('Accounts_SearchFields', 'username, name, bio', {
type: 'string',
public: true,
});
this.add('Accounts_Directory_DefaultView', 'channels', {
type: 'select',

@ -30,7 +30,7 @@ export class Users extends Base {
this.tryEnsureIndex({ roles: 1 }, { sparse: 1 });
this.tryEnsureIndex({ name: 1 });
this.tryEnsureIndex({ name: 'text', username: 'text', bio: 'text' }, { default_language: 'none', language_override: 'documentLanguage' });
this.tryEnsureIndex({ bio: 1 });
this.tryEnsureIndex({ createdAt: 1 });
this.tryEnsureIndex({ lastLogin: 1 });
this.tryEnsureIndex({ status: 1 });
@ -641,10 +641,7 @@ export class Users extends Base {
const searchFields = forcedSearchFields || settings.get('Accounts_SearchFields').trim().split(',');
const orStmt = _.reduce(searchFields, function(acc, el) {
el = el.trim();
if (el && !['name', 'username', 'bio'].includes(el)) {
acc.push({ [el]: termRegex });
}
acc.push({ [el.trim()]: termRegex });
return acc;
}, []);
@ -652,10 +649,8 @@ export class Users extends Base {
$and: [
{
active: true,
$or: [{
$text: { $search: searchTerm },
}, ...orStmt],
username: { $exists: true, $nin: exceptions },
$or: orStmt,
},
...extraQuery,
],

@ -1,7 +1,7 @@
import { Random } from 'meteor/random';
import { Migrations } from '../../../app/migrations';
import { Rooms, Messages, Subscriptions, Uploads } from '../../../app/models/server';
import { Rooms, Messages, Subscriptions, Uploads, Settings, Users } from '../../../app/models/server';
const unifyRooms = (room) => {
// verify if other DM already exists
@ -85,10 +85,21 @@ const fixDiscussions = () => {
});
};
const fixUserSearch = () => {
const setting = Settings.findOneById('Accounts_SearchFields', { fields: { value: 1 } });
const value = setting?.value?.trim();
if (value === '' || value === 'username, name') {
Settings.updateValueById('Accounts_SearchFields', 'username, name, bio');
}
Users.tryDropIndex('name_text_username_text_bio_text');
};
Migrations.add({
version: 183,
up() {
fixDiscussions();
fixSelfDMs();
fixUserSearch();
},
});

Loading…
Cancel
Save