Skip to content

Commit

Permalink
Improve search result quality by doing distance verification of resul…
Browse files Browse the repository at this point in the history
…ts ✨#381
  • Loading branch information
Freymaurer committed Feb 21, 2024
1 parent 418fb2f commit 25184b2
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/Server/Database/Term.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ type Queries =

static member NameQueryFullText (nodeName: string, ?ontologyFilter: AnyOfOntology, ?limit: int) =
let sb = new StringBuilder()
let limit = defaultArg limit 10
sb.AppendLine $"""CALL db.index.fulltext.queryNodes("TermName",$Name, {{limit: $Limit}})
sb.AppendLine $"""CALL db.index.fulltext.queryNodes("TermName",$Name)
YIELD {nodeName}""" |> ignore
if ontologyFilter.IsSome then
sb.AppendLine(Queries.OntologyFilter(ontologyFilter.Value, nodeName)) |> ignore
sb.AppendLine(Queries.TermReturn nodeName) |> ignore
sb.AppendLine($"""ORDER BY apoc.text.distance(toLower({nodeName}.name), toLower($Name))""") |> ignore
if limit.IsSome then
sb.AppendLine(Queries.Limit(limit.Value)) |> ignore
sb.ToString()


Expand All @@ -74,19 +76,18 @@ type Term(?credentials:Neo4JCredentials, ?session:IAsyncSession) =

/// Searchtype defaults to "get term suggestions with auto complete".
member this.getByName(termName:string, ?searchType:FullTextSearch, ?sourceOntologyName:AnyOfOntology, ?limit: int) =
let limit = defaultArg limit 5
let nodeName = "node"
let fulltextSearchStr =
if searchType.IsSome then
searchType.Value.ofQueryString termName
else
FullTextSearch.PerformanceComplete.ofQueryString termName
let query = Queries.NameQueryFullText (nodeName, ?ontologyFilter=sourceOntologyName, limit=limit)
let query = Queries.NameQueryFullText (nodeName, ?ontologyFilter=sourceOntologyName, ?limit = limit)
let parameters =
Map [
"Name",fulltextSearchStr |> box
if sourceOntologyName.IsSome then sourceOntologyName.Value.toParamTuple
"Limit", box limit
if limit.IsSome then "Limit", box limit.Value
] |> Some
Neo4j.runQuery(query,parameters,(Term.asTerm(nodeName)),?session=session,?credentials=credentials)

Expand All @@ -95,10 +96,7 @@ type Term(?credentials:Neo4JCredentials, ?session:IAsyncSession) =
/// </summary>
member this.searchByParentStepwise(query: string, parentId: string, ?searchType:FullTextSearch, ?limit: int) =
let limit = defaultArg limit 5
let searchNameQuery =
"""CALL db.index.fulltext.queryNodes("TermName", $Search, {limit: $Limit})
YIELD node
RETURN node.accession"""
let searchNameQuery = Queries.NameQueryFullText ("node", limit=limit)
let searchTreeQuery =
"""MATCH (node:Term)
WHERE node.accession IN $AccessionList
Expand Down Expand Up @@ -127,7 +125,7 @@ type Term(?credentials:Neo4JCredentials, ?session:IAsyncSession) =
session.RunAsync(
searchNameQuery,
System.Collections.Generic.Dictionary<string,obj>([
KeyValuePair("Search", box fulltextSearchStr);
KeyValuePair("Name", box fulltextSearchStr);
// KeyValuePair("Accession", box parentId);
KeyValuePair("Limit", box limit)
]),
Expand Down

0 comments on commit 25184b2

Please sign in to comment.