Skip to content

Commit

Permalink
Fix duplicate results and further improve search performance (Issue #230
Browse files Browse the repository at this point in the history
, #228) 🐛🐎
  • Loading branch information
Freymaurer committed Oct 10, 2022
1 parent 4c9a625 commit 2a910e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/Server/Database/Helper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ with
let s = queryString.Split(" ", StringSplitOptions.RemoveEmptyEntries)
s
// add "+" to every word so the fulltext search must include the previous word, this highly improves search performance
|> Array.mapi (fun i str -> if i <> s.Length-1 then "+" + str else str + "*")
// Searchquality is further improved by $"({str}^4 OR {str}*)". So it will value perfect hits higher then autocomplete hits.
|> Array.mapi (fun i str -> if i <> s.Length-1 then "+" + str else $"({str}^4 OR {str}*)")
|> String.concat " "
| Fuzzy -> queryString.Replace(" ","~ ") + "~"

Expand Down
43 changes: 22 additions & 21 deletions src/Server/Database/Term.fs
Original file line number Diff line number Diff line change
Expand Up @@ -187,33 +187,39 @@ type Term(?credentials:Neo4JCredentials, ?session:IAsyncSession) =
credentials.Value
)

static member private byParentQuery_Accession =
/// 1. Search for fitting terms first (db.index.fulltext.queryNodes, TermName)
/// 2. Limit search results by 50. If there are too many results it will reduce kill searchspeed when checking for relationship per searchresult (example: "growth", parent: "NFDI4PSO:1000161")
/// 2.5 It is possible to do (:Term {accession: $Accession})<-[*1..]-(node) but this will die whenever there are too many relationships (example: "arabidopsis", parent: "OBI:0100026")
/// Therefore i follow the assumption to limit n of searchresult, as they are sorted by best fit already, so whenever the user is close to the result he will get the desired search results.
"""CALL db.index.fulltext.queryNodes("TermName", $Search)
YIELD node
WITH node LIMIT 50
WHERE EXISTS ( (node)-[*1..]->(:Term {accession: $Accession}) )
RETURN node.accession, node.name, node.definition, node.is_obsolete"""

/// Searchtype defaults to "get child term suggestions with auto complete"
member this.getByNameAndParent(termName:string,parentAccession:string,?searchType:FullTextSearch) =
let fulltextSearchStr =
if searchType.IsSome then
searchType.Value.ofQueryString termName
else
FullTextSearch.Complete.ofQueryString termName
let query =
"""CALL db.index.fulltext.queryNodes("TermName", $Search)
YIELD node
WHERE EXISTS ( (:Term {accession: $Accession})<-[*1..]-(node) )
RETURN node.accession, node.name, node.definition, node.is_obsolete"""
let param =
Map [
"Accession", parentAccession;
"Search", fulltextSearchStr
] |> Some
if session.IsSome then
Neo4j.runQuery(
query,
Term.byParentQuery_Accession,
param,
(Term.asTerm("node")),
session = session.Value
)
else
Neo4j.runQuery(
query,
Term.byParentQuery_Accession,
param,
(Term.asTerm("node")),
credentials.Value
Expand All @@ -226,58 +232,50 @@ type Term(?credentials:Neo4JCredentials, ?session:IAsyncSession) =
searchType.Value.ofQueryString term.Name
else
FullTextSearch.Complete.ofQueryString term.Name
let query =
"""CALL db.index.fulltext.queryNodes("TermName", $Search)
YIELD node
WHERE EXISTS ( (:Term {accession: $Accession})<-[*1..]-(node) )
RETURN node.accession, node.name, node.definition, node.is_obsolete"""
let param =
Map [
"Accession", parent.TermAccession;
"Search", fulltextSearchStr
] |> Some
if session.IsSome then
Neo4j.runQuery(
query,
Term.byParentQuery_Accession,
param,
(Term.asTerm("node")),
session = session.Value
)
else
Neo4j.runQuery(
query,
Term.byParentQuery_Accession,
param,
(Term.asTerm("node")),
credentials.Value
)

// Searchtype defaults to "get child term suggestions with auto complete"
member this.getByNameAndParent(termName:string,parentAccession:TermMinimal,?searchType:FullTextSearch) =
printfn "hit"
let fulltextSearchStr =
if searchType.IsSome then
searchType.Value.ofQueryString termName
else
FullTextSearch.Complete.ofQueryString termName
let query =
"""CALL db.index.fulltext.queryNodes("TermName", $Search)
YIELD node
WHERE EXISTS ( (:Term {accession: $Accession})<-[*1..]-(node) )
RETURN node.accession, node.name, node.definition, node.is_obsolete"""
let param =
Map [
"Accession", parentAccession.TermAccession;
"Search", fulltextSearchStr
] |> Some
printfn "%A" param
if session.IsSome then
Neo4j.runQuery(
query,
Term.byParentQuery_Accession,
param,
(Term.asTerm("node")),
session = session.Value
)
else
Neo4j.runQuery(
query,
Term.byParentQuery_Accession,
param,
(Term.asTerm("node")),
credentials.Value
Expand All @@ -292,6 +290,7 @@ type Term(?credentials:Neo4JCredentials, ?session:IAsyncSession) =
let query =
"""CALL db.index.fulltext.queryNodes("TermName", $Search)
YIELD node
WITH node LIMIT 50
WHERE EXISTS ( (:Term {name: $Name})<-[*1..]-(node) )
RETURN node.accession, node.name, node.definition, node.is_obsolete"""
let param =
Expand Down Expand Up @@ -347,6 +346,7 @@ type Term(?credentials:Neo4JCredentials, ?session:IAsyncSession) =
let query =
"""CALL db.index.fulltext.queryNodes("TermName", $Search)
YIELD node
WITH node LIMIT 50
WHERE EXISTS ( (:Term {accession: $Accession})-[*1..]->(node) )
RETURN node.accession, node.name, node.definition, node.is_obsolete"""
let param =
Expand Down Expand Up @@ -379,6 +379,7 @@ type Term(?credentials:Neo4JCredentials, ?session:IAsyncSession) =
let query =
"""CALL db.index.fulltext.queryNodes("TermName", $Search)
YIELD node
WITH node LIMIT 50
WHERE EXISTS ( (:Term {name: $Name})-[*1..]->(node) )
RETURN node.accession, node.name, node.definition, node.is_obsolete"""
let param =
Expand Down

0 comments on commit 2a910e1

Please sign in to comment.