summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-08-12 22:48:31 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-09-02 11:21:45 +0200
commitc354786e79b13f0188f5a9626de7b896374e81f5 (patch)
tree84a0d822755664da32307271069cf0b145efe838 /sw
parent43d30b5031396d8842b0a70cad7d095ee4be1fdd (diff)
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 <quikee@gmail.com> (cherry picked from commit adf65471e889676a600a9c6d0454c75cbd549ad3) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121114 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/indexing/SearchResultLocatorTest.cxx15
-rw-r--r--sw/source/core/inc/SearchResultLocator.hxx19
-rw-r--r--sw/source/core/model/SearchResultLocator.cxx31
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx28
4 files changed, 57 insertions, 36 deletions
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;