thekid / dialog

Dialog photoblog
2 stars 1 forks source link

Implement search function using Atlas Search #20

Closed thekid closed 1 year ago

thekid commented 1 year ago

See https://dialog.sloppy.zone/search?q=Yosemite:

Search screenshot

Suggestions

Suggestions screenshot

Based on titles

Ranking

From highest to lowest:

Additional boost factors:

Facetted search

We could include the year as facette

Keywords & synonyms

Atlas configuration

A search index needs to be created in MongoDB Atlas!

{
  "mappings": {
    "dynamic": true,
    "fields": {
      "title": [
        {
          "dynamic": true,
          "type": "document"
        },
        {
          "type": "autocomplete"
        }
      ]
    }
  }
}

Implementation

thekid commented 1 year ago

We should remove HTML before searching, the highlighting function produces these kinds of fragments every now and then:

HTML fragments

thekid commented 1 year ago

We should remove HTML before searching, the highlighting function produces these kinds of fragments every now and then: [...]

Implemented in thekid/dialog@a589a03. Existing data can be migrated as follows:

use com\mongodb\MongoConnection;
use util\cmd\Console;

$c= new MongoConnection($argv[1]);
$entries= $c->database($argv[2])->collection('entries');
foreach ($entries->find() as $document) {
  Console::writeLine('> ', $document['title'], ' ', $document['is']);
  $entries->update($document->id(), ['$set' => [
    '_searchable' => [
      'content' => strip_tags(strtr($document['content'], ['<br>' => "\n", '</p><p>' => "\n"])),
      'boost'   => isset($document['is']['journey']) ? 2 : 1,
    ]
  ]]);
}

Now looks like this: https://dialog.sloppy.zone/search?q=Video

thekid commented 1 year ago

We need to be able to distinguish journeys and content in this case:

Journey and content with same title

thekid commented 1 year ago

Boosting results by date so that newer entries take precedenc over older ones is not as easy as I thought it would be. It will probably require a gauss function score, see https://www.mongodb.com/docs/atlas/atlas-search/scoring/#function and https://www.elastic.co/de/blog/0-90-4-released/

thekid commented 1 year ago

Released in https://github.com/thekid/dialog/releases/tag/v1.3.0