From 7da5537f6a43c1b82afc5e0c8d18b8d847293fda Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 2 Aug 2021 22:27:28 +0900 Subject: indexing: use XML as input that is identical to indexing XML MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2242b4bd77220b55e67c2e0f0fe54f008759d282 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120194 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- desktop/qa/desktop_lib/test_desktop_lib.cxx | 7 +++-- sw/source/uibase/uno/unotxdoc.cxx | 49 ++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index f23f9709416e..dc8b4caf1de4 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -3117,13 +3117,16 @@ void DesktopLOKTest::testRenderSearchResult() Scheduler::ProcessEventsToIdle(); unsigned char* pBuffer = nullptr; - OString aJSON = "{ \"type\" : 1, \"node_index\" : 19 }"; + OString aPayload = + "" + "ABC" + ""; int nWidth = 0; int nHeight = 0; size_t nByteSize = 0; - bool bResult = pDocument->m_pDocumentClass->renderSearchResult(pDocument, aJSON.getStr(), &pBuffer, &nWidth, &nHeight, &nByteSize); + bool bResult = pDocument->m_pDocumentClass->renderSearchResult(pDocument, aPayload.getStr(), &pBuffer, &nWidth, &nHeight, &nByteSize); CPPUNIT_ASSERT(bResult); CPPUNIT_ASSERT(pBuffer); diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 2940c52b8256..51dfac84254c 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -122,7 +122,6 @@ #include #include - #include #include @@ -164,7 +163,7 @@ #include #include -#include +#include #define TWIPS_PER_PIXEL 15 @@ -3397,23 +3396,45 @@ SwXTextDocument::getSearchResultRectangles(const char* pPayload) { std::vector aRectangles; - boost::property_tree::ptree aTree; - std::stringstream aStream(pPayload); - boost::property_tree::read_json(aStream, aTree); + const OString aPayloadString(pPayload); - sw::search::SearchIndexData aData; + SvMemoryStream aStream(const_cast(aPayloadString.getStr()), aPayloadString.getLength(), StreamMode::READ); + tools::XmlWalker aWalker; + if (!aWalker.open(&aStream)) + return aRectangles; - int nType = aTree.get("type"); + if (aWalker.name() == "indexing") + { + SwDoc* pDoc = m_pDocShell->GetDoc(); - aData.nNodeIndex = sal_uInt32(aTree.get("node_index")); - aData.eType = sw::search::NodeType(nType); + sw::search::SearchIndexData aData; - SwDoc* pDoc = m_pDocShell->GetDoc(); + aWalker.children(); + while (aWalker.isValid()) + { + if (aWalker.name() == "paragraph") + { + OString sType = aWalker.attribute("type"); + OString sIndex = aWalker.attribute("index"); + + if (!sType.isEmpty() && !sIndex.isEmpty()) + { + aData.nNodeIndex = sIndex.toInt32(); + aData.eType = sw::search::NodeType(sType.toInt32()); - sw::search::SearchResultLocator aLocator(pDoc); - sw::search::LocationResult aResult = aLocator.find(aData); - if (aResult.mbFound) - aRectangles = aResult.maRectangles; + sw::search::SearchResultLocator aLocator(pDoc); + sw::search::LocationResult aResult = aLocator.find(aData); + if (aResult.mbFound) + { + for (auto const & rRect : aResult.maRectangles) + aRectangles.push_back(rRect); + } + } + } + aWalker.next(); + } + aWalker.parent(); + } return aRectangles; } -- cgit v1.2.3