Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Search API Error

Anyone having any issues with the Search API? I've been using version 0.1.1  from the Mod Library for awhile and now I'm getting the error shown below. Started noticing the error this week.... For reference, the error message generated was: TypeError: (text || "").toLowerCase is not a function TypeError: (text || "").toLowerCase is not a function     at tokenizer (apiscript.js:38402:29)     at addDocument (apiscript.js:38427:25)     at apiscript.js:38942:9 Picture of the error below:
1679446260
timmaugh
Forum Champion
API Scripter
If you aren't sure what line that is in the script (or what script), you can install ScriptInfo and run the line number through it. Your text copy/paste of the error has a different line number from the image, but using the image line number, the command would be: !scriptinfo 11685 If it were me, I would install ScriptInfo and then regenerate the error to make sure the line number doesn't change. Once you have the line, share it here and maybe we can spot what is going wrong.
Hi Timmaugh. I loaded the scriptinfo API. it runs fine when Search API is disabled. But once I load the Search API, the sandbox crashes again and none of the API's work, including Scriptinfo.  When I type !scriptinfo in the chat box, nothing happens. It only works when I disable the Search API
My game has developed the same problem. Disabling the Search mod allows the API to run normally, and reinstating it causes a crash. The error message is the same as Pak's but with different numbers in the parentheses. timmaugh, I can't run the API with Search enabled. Will ScriptInfo tell me anything useful if Search is disabled?
1679461243
timmaugh
Forum Champion
API Scripter
It won't give an accurate reading if the script isn't enabled because then the line numbers will be off. However, there is only one occurrence of the (text || '') text in the script, so it was easy to spot. The script is one of Aaron's, so I don't want to push a change, but from my poking around, I think the function (at the referenced line) is getting an argument of a different type from what it is expecting. I haven't tested it to see if the script works, but I can change the line to coerce whatever it receives to be a string, then the error goes away and the script indexes the source docs in your game, just fine. So if you want to give it a try until Aaron gets time to look at it himself, you'll need to uninstall the script (if you have it from the 1-click), then choose it again but this time choose Import. Then you'll want to alter line 90 to read this: return _.chain((`${text}` || '').toLowerCase().replace(/<[^>]*>|\d+|&[a-zA-Z0-9#]*;/g,' ').trim().split(/[\W\s]+/)) Like I said, that gets rid of the error, and it might make the script usable again... as I haven't used the script, I would rely on one of you to report if it works. For now, I'll flag Aaron and see if he can take a look.
1679491351
The Aaron
Roll20 Production Team
API Scripter
Hmm, interesting, I'll have to figure out what they changed. Tim's change will work, but will likely result in a bunch is '[Object object]' entries in the corpus, and possibly miss some information of interest. I'll take a quick look this morning. 
Thanks Tim! Your line tweak did resolve the crash on my end! But it looks like Aaron has some other concerns.  I'll run with the line tweak for now until The Aaron completes his assessment.
1679501251
The Aaron
Roll20 Production Team
API Scripter
Ok, I've pushed an updated version.&nbsp; You can get it now here:&nbsp; <a href="https://github.com/shdwjk/Roll20API/blob/master/Search/Search.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/Search/Search.js</a> Or grab it from the 1-click when it gets updated.&nbsp; I did a bit of tidying up as well (quite an old script and the world keeps turning... =D).&nbsp; My change is a little more conservative than Tim's, but should give the same results.&nbsp; Let me know if you run into any more issues.&nbsp; I'll probably do a bit more clean up on it soon, but wanted to get a fixed version out there soon.
Hi Aaron. When I use your new code, the sandbox seems to hang on the 2nd line shown, t hen after a few minutes or so, I get an infinite loop error "-=&gt; Search v0.1.2 &lt;=-&nbsp; [Wed Mar 22 2023 15:49:45 GMT+0000 (Coordinated Universal Time)]" "Load Corpus: 0/167819..." When I use Tim's suggestion, the sandbox shows Search doing the Load Corpus indexing: "Load Corpus: 1000/167838... (3.50 seconds)" "Load Corpus: 2000/167838... (5.61 seconds)" "Load Corpus: 3000/167838... (6.97 seconds)" "Load Corpus: 4000/167838... (8.39 seconds)" "Load Corpus: 5000/167838... (10.07 seconds)" "Load Corpus: 6000/167838... (11.59 seconds)" "Load Corpus: 7000/167838... (13.86 seconds)" "Load Corpus: 8000/167838... (15.29 seconds)" "Load Corpus: 9000/167838... (16.68 seconds)" "Load Corpus: 10000/167838... (18.07 seconds)" etc...
1679509429
The Aaron
Roll20 Production Team
API Scripter
Hmm.&nbsp; Possible I've introduced a bug then.
1679512926
The Aaron
Roll20 Production Team
API Scripter
Ok, looks like some code I introduced for tokenizing documents was really sub-optimal... (like x1000 slower...).&nbsp; I've reverted that part and updated:&nbsp; <a href="https://github.com/shdwjk/Roll20API/blob/master/Search/Search.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/Search/Search.js</a> I'll come back to it and do some better testing later. =D
Thanks Aaron. V.0.1.3 seems to run without crashing at the beginning, but it doesn't complete the "load corpus" indexing (not sure if indexing is the proper term to use). This time around, it did 4 different rounds of corpus loading. The first round made it about 43% of the way before resetting. "Load Corpus: 72000/167819... (115.12 seconds)" The 2nd round it made it about 4% then reset "Load Corpus: 7000/167819... (14.32 seconds)" 3rd round it got to 46% then reset. "Load Corpus: 78000/167819... (111.26 seconds)" on 4th round it never made it past 0/167819 before it hit the infinite loop error "Load Corpus: 0/167819..." Then ending in infinite loop error.
1679546259
The Aaron
Roll20 Production Team
API Scripter
Hmm. Would you mind inviting me to your game (or a copy of it) and GMing me?
Hi Aaron, I PM'd you a link to the campaign.
1679584718
The Aaron
Roll20 Production Team
API Scripter
Thx, I responded. =D
Hi all, did you manage to solve the problem? I'm very interested too, because I had the same issue. BTW thank you so much to the Aaron for your incredible work here on roll20!!! I'm using a lot of your stuff.
1679590782
The Aaron
Roll20 Production Team
API Scripter
Tim's fix above works if you need a short term.&nbsp; I have some other refactors and modernizations in mine, but apparently I broke something, but I can't reproduce it so I'm going to try in Pak's game and get things sorted out, then get the update into the 1-click.
Thanks to Pak for bringing this up, and to Aaron for a mod I rely on in every game! I look forward to seeing the repaired version.
1679887588

Edited 1679887634
Is there a fix for the Search mod yet? Re-enabling the version I have just keeps crashing the API. I wish I had some coding ability, but my forays are very slow and uncertain.
1679950508
The Aaron
Roll20 Production Team
API Scripter
I pushed an updated version here:&nbsp; <a href="https://github.com/shdwjk/Roll20API/blob/master/Search/Search.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/Search/Search.js</a> It's working for me, but there seems to be an issue with the sandbox right now tied to time of day load.&nbsp; YMMV.&nbsp; I'm still digging into it, and so are the devs now, so I'm hoping for a resolution.
Thanks Aaron. I loaded latest version on 1-click (ver. 0.1.3) and it completed all of the load corpus indexing. So far, no errors!! Thanks so much for jumping on this!!!!
Thanks, Aaron. I deleted and reloaded from one click and it's working now. I rely on this script to keep all the NPCs straight and remember campaign history, and I really appreciate the vision as well as all the work that went into it!
Oops, I spoke too soon. I looked away for 5 minutes, and it crashed with a "possible infinite loop" error. I notice that's happening to others too, so it may not be related to the Search mod.
The infinite loop error currently seems to be a widespread Mod/sandbox issue, separate from any specific scripts.&nbsp;
1679977468
The Aaron
Roll20 Production Team
API Scripter
Valerie M. said: Oops, I spoke too soon. I looked away for 5 minutes, and it crashed with a "possible infinite loop" error. I notice that's happening to others too, so it may not be related to the Search mod. 1-click is still version 0.1.1 I think. The link above is to version 0.1.3. That should get in the 1-click soon though.&nbsp;