{"id":20417029,"url":"https://github.com/smourier/futese","last_synced_at":"2025-10-27T19:46:46.809Z","repository":{"id":227133002,"uuid":"770430868","full_name":"smourier/Futese","owner":"smourier","description":"A simple in-memory persistable full text search engine in less than 1000 lines of C# code.","archived":false,"fork":false,"pushed_at":"2025-02-25T22:00:51.000Z","size":58,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T17:14:36.611Z","etag":null,"topics":["csharp","dotnet","fulltextsearch","search-engine"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smourier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-11T14:39:54.000Z","updated_at":"2025-02-25T22:00:55.000Z","dependencies_parsed_at":"2024-11-17T22:45:39.212Z","dependency_job_id":"4bf69ced-d9dc-461b-9e4b-c8da7fd9748e","html_url":"https://github.com/smourier/Futese","commit_stats":null,"previous_names":["smourier/futese"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smourier%2FFutese","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smourier%2FFutese/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smourier%2FFutese/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smourier%2FFutese/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smourier","download_url":"https://codeload.github.com/smourier/Futese/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248602313,"owners_count":21131616,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","fulltextsearch","search-engine"],"created_at":"2024-11-15T06:24:14.416Z","updated_at":"2025-10-27T19:46:41.772Z","avatar_url":"https://github.com/smourier.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Futese\n'Futese' stands for **FU**ll **TE**xt **SE**arch.\n\nIt's a simple in-memory persistable full text search engine in less than 1000 lines of C# code:\n\n* The index part tokenizes strings and adds corresponding keys to the index\n* The index tokenizer is customizable. By default it removes diacritics and stores lowercase-only\n* The query part can search for phrases. It supports AND (blah blih), OR (blah | blih) and NOT (blah - blih) with its own tokenizer\n* The index can be saved to a stream (or a file) and reloaded\n* A thread-safe vesion using locks  (`ThreadSafeIndex\u003cT\u003e`) and a concurrent versions using ConcurrentDictionary (`ConcurrentIndex\u003cT\u003e`) are provided. `ConcurrentIndex\u003cT\u003e` uses much more memory.\n* You can an index using a non thread-safe version, save it and load it with a thread-safe version\n* The whole code is also available as a single .cs file: [Futese.cs](Amalgamation/Futese.cs)\n\n```c#\n// create an index with string keys\nvar index = new Index\u003cstring\u003e();\n\n// add keys and phrases\nindex.Add(\"a\", \"This is a simple phrase\");\nindex.Add(\"b\", \"And this one is another phrase a bit longer\");\nindex.Add(\"c\", \"The last phrase (this one) contains french (with diacritics) like 'réveillez-vous à l'heure!'\");\n\n// search\nSimpleTest(index);\n\n// persist to a file\nvar fileName = \"test.fts\";\nindex.Save(fileName);\n\n// load from a file\nvar newIndex = new Index\u003cstring\u003e();  // or new ThreadSafe\u003cstring\u003e() for example\nnewIndex.Load(fileName);\n\n// search again\nSimpleTest(newIndex);\n\nnewIndex.KeysCount.Should().Be(index.KeysCount);\n```\n\n```c#\nstatic void SimpleTest(Index\u003cstring\u003e index)\n{\n    string[] result;\n    result = index.Search(\"this\").Distinct().ToArray();\n    result.Should().BeEquivalentTo([\"a\", \"b\", \"c\"]);\n\n    result = index.Search(\"this is\").Distinct().ToArray();\n    result.Should().BeEquivalentTo([\"a\", \"b\"]);\n\n    result = index.Search(\"simple | with\").Distinct().ToArray();\n    result.Should().BeEquivalentTo([\"a\", \"c\"]);\n\n    result = index.Search(\"that\").Distinct().ToArray();\n    result.Should().BeEquivalentTo([]);\n\n    result = index.Search(\"the\").Distinct().ToArray();\n    result.Should().BeEquivalentTo([\"c\"]);\n\n    result = index.Search(\"rev\").Distinct().ToArray();\n    result.Should().BeEquivalentTo([\"c\"]);\n\n    result = index.Search(\"-one\").Distinct().ToArray();\n    result.Should().BeEquivalentTo([\"a\"]);\n\n    result = index.Search(\"-this | last\").Distinct().ToArray();\n    result.Should().BeEquivalentTo([]);\n}\n```\nYou can also use complex keys, for example this `Customer` class can be used as a key, and its data will be persisted too:\n\n```c#\n// a key must be IParsable and should generally implement IEquatable\u003cT\u003e\nprivate sealed class Customer(int id, string firstName, string lastName, int age) :\n    IParsable\u003cCustomer\u003e, IEquatable\u003cCustomer\u003e\n{\n    public int Id =\u003e id;\n    public string FirstName =\u003e firstName;\n    public string LastName =\u003e lastName;\n    public int Age =\u003e age;\n\n    // used when saved to a stream.\n    // by default, the index will use object.ToString() to persist the key,\n    // but you can also implement IStringable.ToString()\n    public override string ToString() =\u003e id + \"\\t\" + firstName + \"\\t\" + lastName + \"\\t\" + age;\n\n    // use id as the real key\n    public override int GetHashCode() =\u003e id.GetHashCode();\n    public override bool Equals(object? obj) =\u003e Equals(obj as Customer);\n    public bool Equals(Customer? other) =\u003e other != null \u0026\u0026 other.Id == id;\n\n    // used when loading from a stream\n    public static Customer Parse(string s, IFormatProvider? provider)\n    {\n        var split = s.Split('\\t');\n        return new Customer(int.Parse(split[0]), split[1], split[2], int.Parse(split[3]));\n    }\n\n    // not called by futese which expects Parse to succeed\n    public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(false)] out Customer result) =\u003e throw new NotImplementedException();\n}\n```\nAnd this is how you'd use it:\n\n```c#\nvar index = new Index\u003cCustomer\u003e();\n\nindex.Add(new(0, \"alice\", \"hunting-bobby-crown\", 25));\nindex.Add(new(1, \"bob\", \"albert-down\", 32));\nindex.Add(new(2, \"carl\", \"ctrl-alt\", 15));\n\n// search\nTestWithObjects(index);\n\n// persist to a file\nvar fileName = \"customer.fts\";\nindex.Save(fileName);\n\n// load from a file\nvar newIndex = new Index\u003cCustomer\u003e();\nnewIndex.Load(fileName);\n\n// search again\nTestWithObjects(newIndex);\n```\n\n```c#\nstatic void TestWithObjects(Index\u003cCustomer\u003e index)\n{\n    Customer[] result;\n    result = index.Search(\"al\").Distinct().ToArray();\n    result.Should().OnlyContain(c =\u003e c.FirstName == \"alice\" || c.FirstName == \"bob\" || c.FirstName == \"carl\");\n\n    result = index.Search(\"b\").Distinct().ToArray();\n    result.Should().OnlyContain(c =\u003e c.FirstName == \"alice\" || c.FirstName == \"bob\");\n\n    result = index.Search(\"a -c\").Distinct().ToArray();\n    result.Should().OnlyContain(c =\u003e c.FirstName == \"bob\");\n\n    result = index.Search(\"a c\").Distinct().ToArray();\n    result.Should().OnlyContain(c =\u003e c.FirstName == \"alice\" || c.FirstName == \"carl\");\n\n    result = index.Search(\"a d\").Distinct().ToArray();\n    result.Should().OnlyContain(c =\u003e c.FirstName == \"bob\");\n\n    result = index.Search(\"hunting a\").Distinct().ToArray();\n    result.Should().OnlyContain(c =\u003e c.FirstName == \"alice\");\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmourier%2Ffutese","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmourier%2Ffutese","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmourier%2Ffutese/lists"}