From ee0347e904af6f20e8d01ac87794c83a1543fe52 Mon Sep 17 00:00:00 2001 From: kostyaeremin Date: Mon, 2 Oct 2017 12:18:28 +1000 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D1=81=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B2=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B5=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=B0=20=D0=B1=D0=B5=D0=B7=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BE=D0=BC=D0=B5=D0=BD=D0=B0,=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D1=8F=20%iFind?= =?UTF-8?q?.FindEntities?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cls/iKnowDoc/Search/Domain.cls | 39 ++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/cls/iKnowDoc/Search/Domain.cls b/src/cls/iKnowDoc/Search/Domain.cls index a2dbfa3..b293745 100644 --- a/src/cls/iKnowDoc/Search/Domain.cls +++ b/src/cls/iKnowDoc/Search/Domain.cls @@ -4,7 +4,8 @@ Class iKnowDoc.Search.Domain Extends %Persistent { /// Similar entity search method. Returns JSON-object containing 10 entities similar to input string. -ClassMethod GetSimilar(SearchString) As %Status +// Old version +/*ClassMethod GetSimilar(SearchString) As %Status { try { if ($length(SearchString)>1) { @@ -19,7 +20,7 @@ ClassMethod GetSimilar(SearchString) As %Status set Result(12) = $lb(999999," ",0,0) for i=1:1:10 { set оrd = $order(Result(i),1,Data) - if $li(Result(i),4)>2 { + if $li(Result(i),2)>2 { if ($FIND($li(Data,2),"--")'=0) { set string =" " } elseif ($FIND($li(Data,2),"|")'=0) { @@ -46,6 +47,40 @@ ClassMethod GetSimilar(SearchString) As %Status write ResultJSON.%ToJSON() } quit $$$OK +}*/ + +ClassMethod GetSimilar(SearchString) As %Status +{ + try { + if ($length(SearchString)>1) { + // Forming a dynamic object + set ResultJSON = { "entities": [] } + // Getting data from Result array and pushing to the dynamic object + //set myquery = "SELECT TOP 10 e.Word as Word, s.Spread FROM %iFind.FindWords('"_SearchString_"*') e JOIN User_DocBook.DocBook_contentInd_WordSpread s ON e.WordId= s.WordId ORDER BY Spread DESC" + set myquery = "SELECT TOP 10 e.Entity as Word, s.Spread FROM %iFind.FindEntities('"_SearchString_"*') e JOIN User_DocBook.DocBook_contentInd_EntSpread s ON e.EntityId = s.EntityId where s.Spread > 2 ORDER BY Spread DESC" + set tStatement = ##class(%SQL.Statement).%New() + set qStatus = tStatement.%Prepare(.myquery) + IF qStatus'=1 {WRITE "%Prepare failed:" DO $System.Status.DisplayError(qStatus) QUIT} + set rset = tStatement.%Execute() + //w 1 + //zw rset + while rset.%Next() { + set word=rset.Word + //w rset.Word + /*set string = ##class(iKnowDoc.Search.Parser).ParseHints(word) + set tJSON = { "value":($ZCONVERT(string,"I","HTML")) }*/ + //set tJSON = { "value":($ZCONVERT(rset.Word,"I","HTML")) } + set tJSON = { "value":(rset.Word) } + do ResultJSON.entities.%Push(tJSON) + } + } + // Converting dynamic object into JSON + write ResultJSON.%ToJSON() + } catch ex { + set ResultJSON = { "entities": [] } + write ResultJSON.%ToJSON() + } + quit $$$OK } /// Getting iKnow domain Id method