Closed philipmarnef closed 4 years ago
What provider are you using?
SQLite
I read Algolia uses the order of the searchableAttributes
to calculate rank, was wondering if something similar is possible with the sqlite provider.
I have to check again why I switched back from fts5 to fts4... but if that reason isn’t valid anymore and we could use fts5, there is a functionality for weights: https://android.jlelse.eu/offline-full-text-search-in-android-ios-b4dd5bed3acd
In the alpha.2 I'm testing you ARE using FTS5...
I just added
->andWhere('rank MATCH \'bm25(5.0, 4.0, 3.0, 2.0, 1.0, 0, 0)\'')
after ->where(...)
to the search()
method in the Sqlite Provider to test and it works.
I guess you could iterate over the search.fields
option and build the bm25 query accordingly. It would be even cooler if you could define custom weights in your settings like:
'search' => [
'fields' => [
'pages' => [
'title' => 10,
'intro' => 5,
'body' => 1
]
],
Oh my haha, I still had FTS4 in my head.
I can't implement it as suggested, since that way is already used to allow to run fields through field methods before adding to the index.
I will likely just add another option weights
where you can define that.
Actually not as easy as thought...
bm25
needs the wights in the exact order as columns were created. However, columns are currently created dynamically based on what the indexed content actually is.
In addition, if a page and a file have the same named field, the database table simply uses the same column. So weights could only be defined on basis of field names (No matter if page, file or user).
Added the most basic/simple implementation for now:
✅ in next alpha release (1.0.0-alpha.3)
I have the 'fields' option set but they are all treated equally in the ranking of the results. It would be very nice if the order of the fields influenced the ranking, so results with a match in the title field take precedence over matches in the body field.
Or is there another way to achieve this?