hoelzro / tw-full-text-search

Full text search plugin for TiddlyWiki powered by lunr.js
https://hoelz.ro/files/fts.html
Other
25 stars 4 forks source link

Renaming image error? #1

Closed diego898 closed 6 years ago

diego898 commented 6 years ago

I have a node installation of tw5 on my machine, and I was using your excellent plugin when I discovered the following possible bug. This is replicated on a fresh node version of tw5 with your plugin:

This produces the following error popup:

error

And in the javascript console, I see:

(index):28821 Uncaught RangeError: Maximum call stack size exceeded
$tw.utils.error @ (index):28821
window.onerror @ (index):28848

$:/plugins/hoelzro/full-text-search/lunr.min.js:7 Uncaught RangeError: Maximum call stack size exceeded
    at t.TokenStore.add ($:/plugins/hoelzro/full-text-search/lunr.min.js:7:14130)
    at t.TokenStore.add ($:/plugins/hoelzro/full-text-search/lunr.min.js:7:14204)
    at t.TokenStore.add ($:/plugins/hoelzro/full-text-search/lunr.min.js:7:14204)

...***this line is repeated about 7,000 times***....

 at t.Index.add ($:/plugins/hoelzro/full-text-search/lunr.min.js:7:7852)
    at t.Index.update ($:/plugins/hoelzro/full-text-search/lunr.min.js:7:8266)
    at eval ($:/plugins/hoelzro/full-text-search/hooks.js:13:20)
    at Object.$tw.hooks.invokeHook (http://localhost:8080/:30853:43)
    at NavigatorWidget.handleSaveTiddlerEvent ($:/core/modules/widgets/navigator.js:363:28)
    at eventListeners.(anonymous function) ($:/core/modules/widgets/widget.js:370:25)
    at NavigatorWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:387:7)
    at DropZoneWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at ListWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at ListItemWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at TranscludeWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at ElementWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at ListWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at ListItemWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at TranscludeWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at SetWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at SetWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at ElementWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at FieldManglerWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at SetWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at KeyboardWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at KeyboardWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at ListWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at ListItemWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at SetWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at TranscludeWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at SetWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at ElementWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at ElementWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at ListWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at ListItemWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at RevealWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at TranscludeWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at FieldManglerWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at ButtonWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at SendMessageWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:393:28)
    at SendMessageWidget.invokeAction ($:/core/modules/widgets/action-sendmessage.js:77:7)
    at ButtonWidget.Widget.invokeActions ($:/core/modules/widgets/widget.js:501:13)
    at HTMLButtonElement.eval ($:/core/modules/widgets/button.js:71:11)

After disabling your plugin, I can then rename the tiddler as usual.

hoelzro commented 6 years ago

Hi @diego898, and thanks for reporting this! I actually just discovered this bug myself last week while working on a new version - it's because while the initial index ignores non-text tiddlers, the change detection hook does not. A fix is coming in 0.0.5, which should be out this week - in the meantime, you can hotfix this by overwriting $:/plugins/hoelzro/full-text-search/hooks.js with the following code:

"use strict";
/*\
title: $:/plugins/hoelzro/full-text-search/hooks.js
type: text/vnd.tiddlywiki
module-type: startup

\*/
var SaveTiddlerHook;
(function (SaveTiddlerHook) {
    var getIndex = require('$:/plugins/hoelzro/full-text-search/shared-index.js').getIndex;
    $tw.hooks.addHook('th-saving-tiddler', function (tiddler) {
        var type = tiddler.fields.type || 'text/vnd.tiddlywiki';
        if(type.startsWith('text/')) {
          getIndex().update(tiddler.fields);
        }
        return tiddler;
    });
    $tw.hooks.addHook('th-deleting-tiddler', function (tiddler) {
        getIndex().remove({ title: tiddler.fields.title });
    });
})(SaveTiddlerHook || (SaveTiddlerHook = {}));
// vim:sts=4:sw=4
hoelzro commented 6 years ago

Hi again @diego898 - I'm happy to report that I've released the latest version of this plugin - you can get the latest version at https://hoelz.ro/files/fts.html

diego898 commented 6 years ago

Hey @hoelzro thanks very much! I can confirm this is now fixed for me so I will close this issue.

A side question: Where can I see/edit the list of ignored words?

Thanks!

hoelzro commented 6 years ago

@diego898 Currently, the plugin ignores system tiddlers and those with a type not beginning with "text/" (treating tiddlers without a type as "text/vnd.tiddlywiki"). I was thinking about adding a new feature to allow a custom filter on top of this

diego898 commented 6 years ago

Hey @hoelzro, I saw on google groups you mentioned that certain "stop words" like the, and etc are ignored. I was just wondering if those stop words are listed in a tiddler somewhere?

hoelzro commented 6 years ago

Ah, gotcha! So the stop words are currently hardcoded into lunr.js, which is the search library I use. I've been thinking about adding support for non-English languages; is this what you would use it for, or do you just want to add custom stop words?

diego898 commented 6 years ago

I just wanted to know all the stop words, and perhaps some of my own, but all in english

hoelzro commented 6 years ago

So all of the stop words currently in use are here: https://github.com/olivernn/lunr.js/blob/f4f25aecbf95ddba2106fc2d3317a46a318a55f9/lib/stop_word_filter.js#L41

I hadn't thought to make custom stop words a feature - I'll add it to the list =)