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>
This commit is contained in:
parent
be710c72a6
commit
adf65471e8
4 changed files with 56 additions and 36 deletions
|
@ -56,11 +56,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
|
||||
|
@ -84,12 +83,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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -22,15 +22,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();
|
||||
|
@ -41,13 +40,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();
|
||||
|
@ -59,12 +58,12 @@ LocationResult SearchResultLocator::find(SearchIndexData const& rSearchIndexData
|
|||
SdrObject* pObject = pPage->GetObj(nObject);
|
||||
if (pObject)
|
||||
{
|
||||
if (pObject->GetName() == rSearchIndexData.aObjectName)
|
||||
if (pObject->GetName() == rSearchIndexData.maObjectName)
|
||||
{
|
||||
auto aRect = o3tl::convert(pObject->GetLogicRect(), o3tl::Length::mm100,
|
||||
o3tl::Length::twip);
|
||||
aResult.mbFound = true;
|
||||
aResult.maRectangles.emplace_back(aRect.Left(), aRect.Top(),
|
||||
rResult.mbFound = true;
|
||||
rResult.maRectangles.emplace_back(aRect.Left(), aRect.Top(),
|
||||
aRect.Left() + aRect.GetWidth(),
|
||||
aRect.Top() + aRect.GetHeight());
|
||||
}
|
||||
|
@ -72,6 +71,13 @@ LocationResult SearchResultLocator::find(SearchIndexData const& rSearchIndexData
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LocationResult SearchResultLocator::find(std::vector<SearchIndexData> const& rSearchIndexDataVector)
|
||||
{
|
||||
LocationResult aResult;
|
||||
for (auto const& rSearchIndexData : rSearchIndexDataVector)
|
||||
findOne(aResult, rSearchIndexData);
|
||||
|
||||
return aResult;
|
||||
}
|
||||
|
|
|
@ -3407,8 +3407,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())
|
||||
{
|
||||
|
@ -3419,21 +3418,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;
|
||||
|
|
Loading…
Reference in a new issue