barisusakli / nodebb-plugin-dbsearch

A plugin that uses the database for search
16 stars 24 forks source link

Changing language is not saved #70

Open Dravere opened 3 months ago

Dravere commented 3 months ago

When I try to change the language in the admin plugin panel, the language is not saved. This seems to happen because an error occurs during reindexing at: https://github.com/barisusakli/nodebb-plugin-dbsearch/blob/53a18802615064bc4ca4f3b773c0e3c3cdadf8ed/lib/dbsearch.js#L619

It thus never reaches the second line and never saves the language. Though looking at the Mongo process it seems the indexing is continuing and thus working.

The error I get back: dbsearch-language-change-error

I'm trying to change the language from english to german.

barisusakli commented 3 months ago

When you restart nodebb it should call createIndices here https://github.com/barisusakli/nodebb-plugin-dbsearch/blob/master/lib/mongo.js#L7-L18, and create that index is that not happening?

Dravere commented 3 months ago

I think it creates the index, but not in de. It always uses en, since it is not stored in the database, which language should be used. The property indexLanguage in the plugin config is never set.

barisusakli commented 3 months ago

What do you get when you run db.searchchat.getIndexes() in mongodb ?

Dravere commented 3 months ago

Result: [ { v: 2, key: { _id: 1 }, name: '_id_' } ]

barisusakli commented 3 months ago

Yeah so it looks like the indexes are not created for that collection. This is what it looks like when it works.

> db.searchchat.getIndexes()
[
        {
                "v" : 2,
                "key" : {
                        "_id" : 1
                },
                "name" : "_id_"
        },
        {
                "v" : 2,
                "key" : {
                        "_fts" : "text",
                        "_ftsx" : 1,
                        "roomId" : 1,
                        "uid" : 1
                },
                "name" : "content_text_roomId_1_uid_1",
                "background" : true,
                "weights" : {
                        "content" : 1
                },
                "default_language" : "english",
                "language_override" : "language",
                "textIndexVersion" : 3
        }
]
barisusakli commented 3 months ago

You can try manually creating it with.

db.searchchat.createIndex({ content: 'text', roomId: 1, uid: 1 }, { background: true });

Once that's done try changing language in acp.

Dravere commented 3 months ago

Ok, that did work. But why did I need this manual step?

barisusakli commented 3 months ago

I am not sure, it should happen on nodebb start here check if that line is executed when you restart nodebb, it doesn't get executed if you have jobsDisabled in config for example.

Dravere commented 3 months ago

Well, I dropped the index via mongosh, restarted NodeBB and it created the index again as it should. But there is one difference now, the indexLanguage property in the plugin config is set.

So I tried it again, but unset the indexLanguage property in the plugin config before restarting NodeBB. This time there is an error during the startup:

error: [plugins] Error executing 'static:app.load' in plugin 'nodebb-plugin-dbsearch'
MongoServerError: An equivalent index already exists with the same name but different options. Requested index: { v: 2, key: { _fts: "text", _ftsx: 1, uid: 1, cid: 1 }, name: "content_text_uid_1_cid_1", background: true, weights: { content: 1 }, default_language: "english", language_override: "language", textIndexVersion: 3 }, existing index: { v: 2, key: { _fts: "text", _ftsx: 1, uid: 1, cid: 1 }, name: "content_text_uid_1_cid_1", background: true, default_language: "de", weights: { content: 1 }, language_override: "language", textIndexVersion: 3 }
    at Connection.sendCommand (/home/dravere/Projects/cppnet/nodebb/node_modules/mongodb/lib/cmap/connection.js:297:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Connection.command (/home/dravere/Projects/cppnet/nodebb/node_modules/mongodb/lib/cmap/connection.js:325:26)
    at async Server.command (/home/dravere/Projects/cppnet/nodebb/node_modules/mongodb/lib/sdam/server.js:166:24)
    at async CreateIndexesOperation.executeCommand (/home/dravere/Projects/cppnet/nodebb/node_modules/mongodb/lib/operations/command.js:74:16)
    at async CreateIndexesOperation.execute (/home/dravere/Projects/cppnet/nodebb/node_modules/mongodb/lib/operations/indexes.js:121:9)
    at async executeOperation (/home/dravere/Projects/cppnet/nodebb/node_modules/mongodb/lib/operations/execute_operation.js:112:20)
    at async Collection.createIndex (/home/dravere/Projects/cppnet/nodebb/node_modules/mongodb/lib/collection.js:327:25)
    at async exports.createIndices (/home/dravere/Projects/cppnet/nodebb/node_modules/nodebb-plugin-dbsearch/lib/mongo.js:14:3)
    at async search.init [as method] (/home/dravere/Projects/cppnet/nodebb/node_modules/nodebb-plugin-dbsearch/lib/dbsearch.js:71:2)

And the index is not created.