sw/qa/extras/indexing/IndexingExportTest.cxx      |   80 +++++++++++-----------
 sw/qa/extras/indexing/SearchResultLocatorTest.cxx |   27 +++++++
 sw/source/core/model/SearchResultLocator.cxx      |   18 ++++
 sw/source/filter/indexing/IndexingExport.cxx      |    4 -
 4 files changed, 86 insertions(+), 43 deletions(-)

New commits:
commit 921eb017199f1ceb303e2b65f94ac4da20b365d9
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed Sep 8 00:00:57 2021 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Sep 10 15:30:23 2021 +0200

    indexing: rename "parent" attibute and parse the attribute back
    
    Rename the attribute "parent" to "object_name" and "parent_index"
    and parse the "object_name" attribute for JSON and XML when used
    as input to SearchResultLocator.
    
    Change-Id: I46ad8d6aa14f15d1b759126af71284f7d73a7a96
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121797
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit cce5a278659b1dafacdf64da8dcfab02dba25d75)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121817
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sw/qa/extras/indexing/IndexingExportTest.cxx 
b/sw/qa/extras/indexing/IndexingExportTest.cxx
index c08cdcd282c9..87ab70758de3 100644
--- a/sw/qa/extras/indexing/IndexingExportTest.cxx
+++ b/sw/qa/extras/indexing/IndexingExportTest.cxx
@@ -192,53 +192,53 @@ void IndexingExportTest::testIndexingExport_Tables()
     assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Table1");
     assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "table");
     assertXPath(pXmlDoc, "/indexing/object[1]", "index", "9");
-    // Search paragraph with parent = 9
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=9][1]", "A");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=9][2]", "B");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=9][3]", "1");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=9][4]", "2");
+    // Search paragraph with parent_index = 9
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][1]", 
"A");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][2]", 
"B");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][3]", 
"1");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][4]", 
"2");
 
     assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Table2");
     assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", "table");
     assertXPath(pXmlDoc, "/indexing/object[2]", "index", "24");
-    // Search paragraph with parent = 24
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][1]", "A");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][2]", "B");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][3]", "C");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][4]", "1");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][5]", "10");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][6]", "100");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][7]", "2");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][8]", "20");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][9]", "200");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][10]", "3");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][11]", "30");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][12]", "300");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][13]", "4");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][14]", "40");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][15]", "400");
+    // Search paragraph with parent_index = 24
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][1]", 
"A");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][2]", 
"B");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][3]", 
"C");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][4]", 
"1");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][5]", 
"10");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][6]", 
"100");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][7]", 
"2");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][8]", 
"20");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][9]", 
"200");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][10]", 
"3");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][11]", 
"30");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][12]", 
"300");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][13]", 
"4");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][14]", 
"40");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][15]", 
"400");
 
     assertXPath(pXmlDoc, "/indexing/object[3]", "name", "WeirdTable");
     assertXPath(pXmlDoc, "/indexing/object[3]", "object_type", "table");
     assertXPath(pXmlDoc, "/indexing/object[3]", "index", "72");
-    // Search paragraph with parent = 72
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][1]", "A1");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][2]", "B1");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][3]", "C1");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][4]", "D1");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][5]", "A2B2");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][6]", "C2D2");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][7]", 
"A3B3C3D3");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][8]", "A4-1");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][9]", "A4-2");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][10]", "B4-1");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][11]", "C4-1");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][12]", "D4-1");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][13]", "D4-2");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][14]", "B4-2");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][15]", "C4-2");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][16]", 
"A5B5C5");
-    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][17]", "D5");
+    // Search paragraph with parent_index = 72
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][1]", 
"A1");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][2]", 
"B1");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][3]", 
"C1");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][4]", 
"D1");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][5]", 
"A2B2");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][6]", 
"C2D2");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][7]", 
"A3B3C3D3");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][8]", 
"A4-1");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][9]", 
"A4-2");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][10]", 
"B4-1");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][11]", 
"C4-1");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][12]", 
"D4-1");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][13]", 
"D4-2");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][14]", 
"B4-2");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][15]", 
"C4-2");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][16]", 
"A5B5C5");
+    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][17]", 
"D5");
 }
 
 void IndexingExportTest::testIndexingExport_Sections()
@@ -290,7 +290,9 @@ void IndexingExportTest::testIndexingExport_Fontwork()
     assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Gray");
     assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "shape");
 
+    assertXPath(pXmlDoc, "/indexing/paragraph[1]", "object_name", "Gray");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Fontwork Text 1");
+    assertXPath(pXmlDoc, "/indexing/paragraph[2]", "object_name", "Gray");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Fontwork Text 2");
 }
 
diff --git a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx 
b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
index 654f2639e565..62286674c9e6 100644
--- a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
+++ b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
@@ -30,12 +30,14 @@ public:
     void testSearchResultLocatorUsingXmlPayload();
     void testSearchResultLocatorUsingJsonPayload();
     void testSearchResultLocatorForSdrObjects();
+    void testSearchResultLocatorForSdrObjectsUsingJsonPayload();
 
     CPPUNIT_TEST_SUITE(SearchResultLocatorTest);
     CPPUNIT_TEST(testSearchResultLocator);
     CPPUNIT_TEST(testSearchResultLocatorUsingXmlPayload);
     CPPUNIT_TEST(testSearchResultLocatorUsingJsonPayload);
     CPPUNIT_TEST(testSearchResultLocatorForSdrObjects);
+    CPPUNIT_TEST(testSearchResultLocatorForSdrObjectsUsingJsonPayload);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -149,6 +151,31 @@ void 
SearchResultLocatorTest::testSearchResultLocatorForSdrObjects()
 #endif
 }
 
+void 
SearchResultLocatorTest::testSearchResultLocatorForSdrObjectsUsingJsonPayload()
+{
+    SwDoc* pDoc = createDoc("IndexingExport_Shapes.odt");
+    CPPUNIT_ASSERT(pDoc);
+
+    sw::search::SearchResultLocator aLocator(pDoc);
+    OString payload = "["
+                      "{ \"node_type\" : \"common\", \"index\" : 1, 
\"object_name\" : \"Circle\" }"
+                      "]";
+
+    sw::search::LocationResult aResult = 
aLocator.findForPayload(payload.getStr());
+    CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size());
+
+    // skip asserting exact values for macOS and Windows because of
+    // inconsistent results
+#if !defined(_WIN32) && !defined(MACOSX)
+    auto aRectangle = aResult.maRectangles[0];
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1478.0, aRectangle.getMinX(), 1e-4);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(3223.0, aRectangle.getMinY(), 1e-4);
+
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(2059.0, aRectangle.getWidth(), 1e-4);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(2059.0, aRectangle.getHeight(), 1e-4);
+#endif
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SearchResultLocatorTest);
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/model/SearchResultLocator.cxx 
b/sw/source/core/model/SearchResultLocator.cxx
index 208736ab86f3..c1c81d017fd8 100644
--- a/sw/source/core/model/SearchResultLocator.cxx
+++ b/sw/source/core/model/SearchResultLocator.cxx
@@ -114,17 +114,29 @@ bool SearchResultLocator::tryParseJSON(const char* 
pPayload,
         auto const& rEach = rEachNode.second;
 
         std::string sType = rEach.get<std::string>("node_type", "");
+
         auto eNodeType = sw::search::NodeType::Undefined;
         if (sType == "writer")
             eNodeType = sw::search::NodeType::WriterNode;
         else if (sType == "common")
             eNodeType = sw::search::NodeType::CommonNode;
 
+        std::string sJsonObjectName = rEach.get<std::string>("object_name", 
"");
+
         sal_Int32 nIndex = rEach.get<sal_Int32>("index", -1);
 
         // Don't add search data elements that don't have valid data
         if (eNodeType != sw::search::NodeType::Undefined && nIndex >= 0)
-            rDataVector.emplace_back(eNodeType, nIndex);
+        {
+            OUString sObjectName;
+            if (!sJsonObjectName.empty())
+            {
+                OString sObjectNameOString(sJsonObjectName.c_str());
+                sObjectName = OStringToOUString(sObjectNameOString, 
RTL_TEXTENCODING_UTF8);
+            }
+
+            rDataVector.emplace_back(eNodeType, nIndex, sObjectName);
+        }
     }
 
     return true;
@@ -157,6 +169,7 @@ bool SearchResultLocator::tryParseXML(const char* pPayload,
         {
             OString sType = aWalker.attribute("node_type");
             OString sIndex = aWalker.attribute("index");
+            OString sObjectName = aWalker.attribute("object_name");
 
             if (!sType.isEmpty() && !sIndex.isEmpty())
             {
@@ -169,7 +182,8 @@ bool SearchResultLocator::tryParseXML(const char* pPayload,
                     eNodeType = sw::search::NodeType::CommonNode;
 
                 aData.meType = eNodeType;
-
+                if (!sObjectName.isEmpty())
+                    aData.maObjectName = OStringToOUString(sObjectName, 
RTL_TEXTENCODING_UTF8);
                 rDataVector.push_back(aData);
             }
         }
diff --git a/sw/source/filter/indexing/IndexingExport.cxx 
b/sw/source/filter/indexing/IndexingExport.cxx
index 90e30a58285e..6c436f9f6180 100644
--- a/sw/source/filter/indexing/IndexingExport.cxx
+++ b/sw/source/filter/indexing/IndexingExport.cxx
@@ -101,7 +101,7 @@ public:
         m_rXmlWriter.attribute("index", pTextNode->GetIndex());
         m_rXmlWriter.attribute("node_type", OString("writer"));
         if (nParentIndex >= 0)
-            m_rXmlWriter.attribute("parent", nParentIndex);
+            m_rXmlWriter.attribute("parent_index", nParentIndex);
         m_rXmlWriter.content(rString);
         m_rXmlWriter.endElement();
     }
@@ -131,7 +131,7 @@ public:
                 m_rXmlWriter.startElement("paragraph");
                 m_rXmlWriter.attribute("index", nParagraph);
                 m_rXmlWriter.attribute("node_type", OString("common"));
-                m_rXmlWriter.attribute("parent", pObject->GetName());
+                m_rXmlWriter.attribute("object_name", pObject->GetName());
                 m_rXmlWriter.content(sText);
                 m_rXmlWriter.endElement();
             }

Reply via email to