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

Request: Configurable search by relevance #39

Closed mardukbp closed 4 years ago

mardukbp commented 4 years ago

In my TW I have some tiddlers whose title begins with "Robot Framework" and other tiddlers that contain "Robot Framework" in the title. Since this plugin claims to sort search results by relevance I was expecting that if my query is "Robot F" then the list of results begins with all the tiddlers whose title begins with "Robot Framework".

However, the first result is a tiddler whose title contains "Robot Framework". It is followed by some tiddlers whose title begins with "Robot Framework" and then some tiddlers that do not contain "Robot Framework" in the title and then more tiddlers whose title begins with "Robot Framework".

I guess that lunr is assigning the scores based on the full content of the tiddlers, not only their title. However, I only care about the tiddler's title. It would be great to be able to configure the plugin to only search in the title.

If there is an easy way to achieve what I want using only built-in TW functions, please tell me.

hoelzro commented 4 years ago

Hi @mardukbp! I'm not really maintaining this plugin anymore, but you could probably achieve something like the desired effect by only doing FTS on tiddlers whose title matches "Robot Framework" - so something like this:

[!is[system]search:title{$(searchTiddler)}ftsearch{$(searchTiddler)}]

However, that wouldn't pick up tiddlers with "robot framework" in the name if you search for something like "robots framework". You could also try modifying the code that builds the index (index-worker and shared-index, I think?) to omit tiddler text fields from the search index.

mardukbp commented 4 years ago

@hoelzro Thank you for your prompt reply. In the end I found a simple solution.

  1. Created the tiddler $:/language/Search/Matches/TitleLiteralAnchored with the contents:
Title begins with:
  1. Added the following to $:/core/ui/DefaultSearchResultList
//<small>{{$:/language/Search/Matches/TitleLiteralAnchored}}</small>//

<$list filter="[!is[system]search:title:literal,anchored{$(searchTiddler)$}sort[title]limit[250]]" template="$:/core/ui/ListItemTemplate"/>

The literal flag means that the query must match exactly. The anchored flag means that the match must occur at the beginning of the string.