How to search the given text into marklogic XHTML file, like clt+f

340 Views Asked by At

I have below XHTML file saved in the marklogic with the URI(/54ab8c234f3c8ce1f5c30ddc).

I need to search the Marklogic DB based on the string (if it is tag name or attribute name or text in the XHTML).

I am able to search only text either attribute. But not able to search at a time all.

Note: if I pass "SS_Default"(it is a attribute value) string it will return the URI of marklogic or if I pass the "META" (it is a tag name) it should return the corresponding URIs or if I pass "Narrowed by"(it is a text) it should return the URI of corresponding file.

            <?xml version="1.0" encoding="UTF-8"?>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <meta>
            </meta>
        <body class="Default">

        </body>
    </html>
2

There are 2 best solutions below

2
On BEST ANSWER

The kinds of searches you are trying to do are typically done differently from each other, as they are different types of data. For instance, if you want to search for "meta" and find documents that have that element, you are querying the structure. You can do that in MarkLogic with this kind of query:

cts:uris((), (), cts:element-query(xs:QName("meta"), ()))

When you want to search for "narrowed by", that's just text, nice and simple:

cts:uris((), (), "narrowed by")

If you want to search within attributes, that's typically done by specifying the attribute you want to search for:

cts:uris((), (), cts:attribute-value-query(xs:QName("body"), xs:QName("class"), "SS_Default"))

If you wanted to combine those, you could run an or-query. I suggest looking through the types of queries you plan to run and see whether they can be segmented this way. As mholstege notes, you could load the document as text and be able to search everything as strings, but you'd lose a lot of value in the structure, so it's probably better to step back and think about whether you really need to run those queries the same way.

0
On

On ingestion, you could use the envelope pattern by creating a wrapper around your original document.

<envelope>
  <original>
    <html>...</html>
  </original>
  <plain-text>
    put the plain text content of your html here
  </plain-text>
</envelope>

Your text searches can be executed on the plain-text element only and on returning the resulting docs you could return the content element. But as Dave mentioned, you are loosing valuable information. Here you can find documentation on ways to ingest data https://docs.marklogic.com/guide/ingestion