nextcloud / fulltextsearch_elasticsearch

🔍 Use Elasticsearch to index the content of your Nextcloud
GNU Affero General Public License v3.0
80 stars 29 forks source link

Fulltext search does not work for users with special characters in the username #300

Closed vbier closed 11 months ago

vbier commented 11 months ago

As soon as a username has some special character, no documents are found in the fulltext search. This effectively breaks fulltext search for all AD/LDAP users, which makes nextcloud unsuitable for use in corporate environments.

This is caused by the filter restricting documents by user permissions in https://github.com/nextcloud/fulltextsearch_elasticsearch/blob/91f9440cc6d9fa050446d97c8efb12c417085453/lib/Service/SearchMappingService.php#L307 The term query on users or owner does not find usernames that do not only consist of characters and digits because the type of the users and owner fields are text:

        "users" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }

When using the term query on text fields, the searched term is analyzed (see the big fat warning here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html) and does not match. Either fix the filter to use the subfield users.keyword and owner.keyword:

                $query[] = ['term' => ['owner.keyword' => $access->getViewerId()]];
                $query[] = ['term' => ['users.keyword' => $access->getViewerId()]];

or change the field type to keyword.

vbier commented 11 months ago

Fixing this issue also fixes: https://github.com/nextcloud/fulltextsearch/issues/751 https://github.com/nextcloud/fulltextsearch/issues/768

And most likely also: https://github.com/nextcloud/files_fulltextsearch/issues/222 https://github.com/nextcloud/files_fulltextsearch/issues/224 https://github.com/nextcloud/fulltextsearch_elasticsearch/issues/260

vbier commented 11 months ago

Has been fixed with https://github.com/nextcloud/fulltextsearch_elasticsearch/pull/237. I have just validated that searching now works with version 27.0.3.