Custom autocomplete using javascript to provide suggestions from existing library

176 views
Skip to first unread message

Luke Verburgt

unread,
Dec 29, 2024, 4:34:46 PM12/29/24
to mementodatabase
Hi all
I've been trying for days now to find a way to make this work and am stumped, hoping someone can assist. I am relatively capable of coding in javascript but am finding the architecture of Memento DB tricky to navigate. 

I currently have this setup:
  • The library I am actively using is called "Bird Observation DB". 
  • In this library is a text field called "Species". 
  • Users are required to type in the name of the bird that they have observed. 
  • To make it easier for them and to ensure accurate and standardized capture of the bird names, I have added an "Autofill" option that links to a second library called "Master bird species list". This is the reference library for all the bird names, which includes English common names and Scientific names for all the different bird species.
  • So the idea is that users can start typing any portion of either of those two species name identifiers and the entry suggestion facility must correctly find matching options.
  • Problem is, the built-in search function in Memento DB can't handle the following search requirement: Bird names are often two or more words like "Blue Woodpecker". Users often need to type in a portion of each of these words to improve searchability, for example "Bl Wo" because if they type in "Blue" it would return dozens of suggestions for all birds with "Blue" in the name and the one they need is too far down in the list so doesn't display - So users are required to spend too much time typing in a greater proportion of the full names and miss other bird observations in the process.  
If there is a way to alter the built-in search algorithm that would be awesome but I doubt it and so I therefore thought of writing my own auto-suggestion script using fuzzy logic as implemented in the Fuse.js library. Problems I'm having are these and I'd appreciate any help on each of these please:
  1. There doesn't seem to be a Trigger for changes made to a field DURING capture of an entry such as the "onchange" event typically used in scripting for fields on a website. Have I overlooked it and if not, is there a way to simulate this in Memento DB?
  2. Does Memento have a method similar to "ui.showSuggestions" to display potential selectable input options or must one create a custom dialog? If the latter, how does one go about this?
Appreciate any help on the above or alternative suggestions to achieving my intended objective. Thanks in advance. 

Mmm

unread,
Dec 29, 2024, 10:43:04 PM12/29/24
to mementodatabase
Вариант решения. 
Автозаполнение => источник данных => скрипт. 

//заменить пробелы в тексте запроса на звездочки
query = query.replace(/\s/g, '*');

var lbn = libByName("Master bird species list");
var entries = lbn.find(query + '*'); //звездочка в конце текста запроса 

//Массив объектов с нужными свойствами
var resultArray = entries.map(a => ({"name": a.field("Name"), "scientific_name": a.field("Scientific name")}));

result(resultArray);


Для поиска ввести в поле "Species":

Bl w    ( скрипт преобразует запрос в   Bl*w*   

Поиск не зависит от регистра запроса. 

понедельник, 30 декабря 2024 г. в 00:34:46 UTC+3, luke.v...@gmail.com:

Luke Verburgt

unread,
Jan 6, 2025, 7:51:07 AMJan 6
to mementodatabase
Thank you very much for trying to help. Unfortunately it seems you have provided only part of a potential solution, which is an approach to help search for a term. Thanks for this. But neither of my queries 1 or 2 were addressed. Is there a trigger option during editing of a field and how do you display the results of the search function as options the user can make a selection from? 

Mmm

unread,
Jan 6, 2025, 1:19:05 PMJan 6
to mementodatabase
В мобильной версии (Андроид) работает. 

Шаблон с примером:

Никаких триггеров нет. 
Связь между библиотеками не обязательна. Добавил, чтобы шаблоны загружались одновременно. 

Кроме того, библиотеки будут в общем доступе 3 дня. 
понедельник, 6 января 2025 г. в 15:51:07 UTC+3, luke.v...@gmail.com:
IC_06012025.jpg
Reply all
Reply to author
Forward
0 new messages