desktop/qa/desktop_lib/test_desktop_lib.cxx | 7 ++ sw/qa/extras/indexing/SearchResultLocatorTest.cxx | 15 ++---- sw/source/core/inc/SearchResultLocator.hxx | 19 ++++++- sw/source/core/model/SearchResultLocator.cxx | 31 +++++++----- sw/source/uibase/uno/unotxdoc.cxx | 55 ++++++++++++++++------ 5 files changed, 87 insertions(+), 40 deletions(-)
New commits: commit c354786e79b13f0188f5a9626de7b896374e81f5 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Thu Aug 12 22:48:31 2021 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Thu Sep 2 11:21:45 2021 +0200 indexing: allow for multiple entries in search indexing data Change-Id: Idb9bbbaa940b7cd48423c6cc65b9c7d0b94f57dc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120396 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit adf65471e889676a600a9c6d0454c75cbd549ad3) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121114 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx index 0b452a6d564e..a1f13ebc32c5 100644 --- a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx +++ b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx @@ -53,11 +53,10 @@ void SearchResultLocatorTest::testSearchResultLocator() CPPUNIT_ASSERT(pDoc); sw::search::SearchResultLocator aLocator(pDoc); - sw::search::SearchIndexData aData; - aData.eType = sw::search::NodeType::WriterNode; - aData.nNodeIndex = 14; + std::vector<sw::search::SearchIndexData> aDataVector; + aDataVector.emplace_back(sw::search::NodeType::WriterNode, 14); - sw::search::LocationResult aResult = aLocator.find(aData); + sw::search::LocationResult aResult = aLocator.find(aDataVector); CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size()); // skip asserting exact values for macOS and Windows because of @@ -78,12 +77,10 @@ void SearchResultLocatorTest::testSearchResultLocatorForSdrObjects() CPPUNIT_ASSERT(pDoc); sw::search::SearchResultLocator aLocator(pDoc); - sw::search::SearchIndexData aData; - aData.eType = sw::search::NodeType::SdrObject; - aData.aObjectName = u"Circle"; - aData.nNodeIndex = 1; + std::vector<sw::search::SearchIndexData> aDataVector; + aDataVector.emplace_back(sw::search::NodeType::SdrObject, 1, u"Circle"); - sw::search::LocationResult aResult = aLocator.find(aData); + sw::search::LocationResult aResult = aLocator.find(aDataVector); CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size()); // skip asserting exact values for macOS and Windows because of diff --git a/sw/source/core/inc/SearchResultLocator.hxx b/sw/source/core/inc/SearchResultLocator.hxx index 5621a397b85c..cd1b2e4bb5e5 100644 --- a/sw/source/core/inc/SearchResultLocator.hxx +++ b/sw/source/core/inc/SearchResultLocator.hxx @@ -25,9 +25,18 @@ enum class NodeType struct SearchIndexData { - NodeType eType = NodeType::Undefined; - OUString aObjectName; - sal_uInt32 nNodeIndex = 0; + NodeType meType = NodeType::Undefined; + sal_uInt32 mnNodeIndex = 0; + OUString maObjectName; + + SearchIndexData() {} + + SearchIndexData(NodeType eType, sal_uInt32 nNodeIndex, OUString const& aObjectName = OUString()) + : meType(eType) + , mnNodeIndex(nNodeIndex) + , maObjectName(aObjectName) + { + } }; struct LocationResult @@ -40,13 +49,15 @@ class SW_DLLPUBLIC SearchResultLocator { SwDoc* mpDocument; + void findOne(LocationResult& rResult, SearchIndexData const& rSearchIndexData); + public: SearchResultLocator(SwDoc* pDoc) : mpDocument(pDoc) { } - LocationResult find(SearchIndexData const& rSearchIndexData); + LocationResult find(std::vector<SearchIndexData> const& rSearchIndexDataVector); }; } // end sw namespace diff --git a/sw/source/core/model/SearchResultLocator.cxx b/sw/source/core/model/SearchResultLocator.cxx index d86d518f082a..e98db11befec 100644 --- a/sw/source/core/model/SearchResultLocator.cxx +++ b/sw/source/core/model/SearchResultLocator.cxx @@ -23,15 +23,14 @@ namespace sw::search { -LocationResult SearchResultLocator::find(SearchIndexData const& rSearchIndexData) +void SearchResultLocator::findOne(LocationResult& rResult, SearchIndexData const& rSearchIndexData) { - LocationResult aResult; - if (rSearchIndexData.eType == NodeType::WriterNode) + if (rSearchIndexData.meType == NodeType::WriterNode) { SwNodes const& rNodes = mpDocument->GetNodes(); - if (rSearchIndexData.nNodeIndex >= rNodes.Count()) - return aResult; - SwNode* pNode = rNodes[rSearchIndexData.nNodeIndex]; + if (rSearchIndexData.mnNodeIndex >= rNodes.Count()) + return; + SwNode* pNode = rNodes[rSearchIndexData.mnNodeIndex]; auto* pContentNode = pNode->GetContentNode(); auto* pShell = mpDocument->getIDocumentLayoutAccess().GetCurrentViewShell(); @@ -42,13 +41,13 @@ LocationResult SearchResultLocator::find(SearchIndexData const& rSearchIndexData = pContentNode->getLayoutFrame(pShell->GetLayout(), nullptr, nullptr); SwRect const& rArea = pFrame->getFrameArea(); - aResult.mbFound = true; - aResult.maRectangles.emplace_back(rArea.Left(), rArea.Top(), + rResult.mbFound = true; + rResult.maRectangles.emplace_back(rArea.Left(), rArea.Top(), rArea.Left() + rArea.Width(), rArea.Top() + rArea.Height()); } } - else if (rSearchIndexData.eType == NodeType::SdrObject) + else if (rSearchIndexData.meType == NodeType::SdrObject) { IDocumentDrawModelAccess& rDrawModelAccess = mpDocument->getIDocumentDrawModelAccess(); auto* pModel = rDrawModelAccess.GetDrawModel(); @@ -60,22 +59,30 @@ LocationResult SearchResultLocator::find(SearchIndexData const& rSearchIndexData SdrObject* pObject = pPage->GetObj(nObject); if (pObject) { - if (pObject->GetName() == rSearchIndexData.aObjectName) + if (pObject->GetName() == rSearchIndexData.maObjectName) { + auto aLogicRect = pObject->GetLogicRect(); auto nLeft = convertMm100ToTwip(aLogicRect.Left()); auto nTop = convertMm100ToTwip(aLogicRect.Top()); auto nWidth = convertMm100ToTwip(aLogicRect.GetWidth()); auto nHeight = convertMm100ToTwip(aLogicRect.GetHeight()); - aResult.mbFound = true; - aResult.maRectangles.emplace_back(nLeft, nTop, nLeft + nWidth, + rResult.mbFound = true; + rResult.maRectangles.emplace_back(nLeft, nTop, nLeft + nWidth, nTop + nHeight); } } } } } +} + +LocationResult SearchResultLocator::find(std::vector<SearchIndexData> const& rSearchIndexDataVector) +{ + LocationResult aResult; + for (auto const& rSearchIndexData : rSearchIndexDataVector) + findOne(aResult, rSearchIndexData); return aResult; } diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 3f029d1b53e6..fa3019a2ebf3 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3425,8 +3425,7 @@ SwXTextDocument::getSearchResultRectangles(const char* pPayload) { SwDoc* pDoc = m_pDocShell->GetDoc(); - sw::search::SearchIndexData aData; - + std::vector<sw::search::SearchIndexData> aDataVector; aWalker.children(); while (aWalker.isValid()) { @@ -3437,21 +3436,28 @@ SwXTextDocument::getSearchResultRectangles(const char* pPayload) if (!sType.isEmpty() && !sIndex.isEmpty()) { - aData.nNodeIndex = sIndex.toInt32(); - aData.eType = sw::search::NodeType(sType.toInt32()); + sw::search::SearchIndexData aData; + aData.mnNodeIndex = sIndex.toInt32(); + aData.meType = sw::search::NodeType(sType.toInt32()); - 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); - } + aDataVector.push_back(aData); } } aWalker.next(); } aWalker.parent(); + + + if (!aDataVector.empty()) + { + sw::search::SearchResultLocator aLocator(pDoc); + sw::search::LocationResult aResult = aLocator.find(aDataVector); + if (aResult.mbFound) + { + for (auto const & rRect : aResult.maRectangles) + aRectangles.push_back(rRect); + } + } } return aRectangles; commit 43d30b5031396d8842b0a70cad7d095ee4be1fdd Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Aug 2 22:27:28 2021 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Thu Sep 2 11:21:31 2021 +0200 indexing: use XML as input that is identical to indexing XML Change-Id: I2242b4bd77220b55e67c2e0f0fe54f008759d282 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120194 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 7da5537f6a43c1b82afc5e0c8d18b8d847293fda) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121113 Tested-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index ba631b855226..be5276c3344b 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -3092,13 +3092,16 @@ void DesktopLOKTest::testRenderSearchResult() Scheduler::ProcessEventsToIdle(); unsigned char* pBuffer = nullptr; - OString aJSON = "{ \"type\" : 1, \"node_index\" : 19 }"; + OString aPayload = + "<indexing>" + "<paragraph type=\"1\" index=\"19\">ABC</paragraph>" + "</indexing>"; 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 6f4a24402ca5..3f029d1b53e6 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -124,7 +124,6 @@ #include <swruler.hxx> #include <docufld.hxx> - #include <EnhancedPDFExportHelper.hxx> #include <numrule.hxx> @@ -164,6 +163,8 @@ #include <SearchResultLocator.hxx> #include <boost/property_tree/json_parser.hpp> +#include <tools/XmlWalker.hxx> + #define TWIPS_PER_PIXEL 15 using namespace ::com::sun::star; @@ -3413,23 +3414,45 @@ SwXTextDocument::getSearchResultRectangles(const char* pPayload) { std::vector<basegfx::B2DRange> 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<char *>(aPayloadString.getStr()), aPayloadString.getLength(), StreamMode::READ); + tools::XmlWalker aWalker; + if (!aWalker.open(&aStream)) + return aRectangles; - int nType = aTree.get<int>("type"); + if (aWalker.name() == "indexing") + { + SwDoc* pDoc = m_pDocShell->GetDoc(); - aData.nNodeIndex = sal_uInt32(aTree.get<int>("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; }