0
votes

I am using Marklogic's search:search() functions to handle searching within my application, and I have a use case where users need to be able to perform a text search that returns matches from an attribute on my document.

For example, using this document:

<document attr="foo attribute value">Some child content</document>

I want users to be able to perform a text search (not using constraints) for "foo", and to return my document based on the match within the attribute @attr. Is there some way to configure the query options to allow this?

Typing in attr:"foo" is not a workable solution, so using attribute range constraints won't help, and users still need to be able to search for other child content not in the attribute node. I'm thinking perhaps there is a way to add a cts:query OR'd into the search via the options, that allows this attribute to be searched?

Open to any and all other solutions.

Thanks!

Edit:

Some additional information, to help clarify:

I need to be able to find matches within the attribute, and elsewhere within the content. Using the example above, searches for "foo", "child content", or "foo child content" should all return my document as a result. This means that any query options that are AND'd with the search (like <additional-query>, which is intended to help constrain your search and not expand it) won't work. What I'm looking for is (likely) an additional query option that will be OR'd with the original search, so as to allow searching by child node content, attribute content, or a mix of the two.

In other words, I'd like MarkLogic to treat any attribute node content exactly the same as element text nodes, as far as searching is concerned.

Thanks!!

3

3 Answers

0
votes

You could accomplish this search with a serialized element-attribute-word cts query in the additional-query options for the search API. The element attribute word query will use the universal index to match individual tokens within attributes.

In MarkLogic 9 You may be able to use the following to perform your search:

import module namespace search = "http://marklogic.com/appservices/search"
 at "/MarkLogic/appservices/search/search.xqy";

search:search("",
  <options xmlns="http://marklogic.com/appservices/search">
    <additional-query>
      <cts:element-attribute-word-query xmlns:cts="http://marklogic.com/cts">
        <cts:element>document</cts:element>
        <cts:attribute>attr</cts:attribute>
        <cts:text>foo</cts:text>
      </cts:element-attribute-word-query>
    </additional-query>
  </options>
  )
0
votes

MarkLogic has ways to parse query text and map a value to an attribute word or value query.

First, you can use cts:parse():

Second, you can use search:search() with constraints defined in an XML payload:

0
votes

I'd look into using the <default> option of <term>. For details see http://docs.marklogic.com/guide/search-dev/appendixa#id_31590

Alternatively, consider doing query expansion. The idea behind that is that a end user send a search string. You parse it using search:parse of cts:parse (as suggested by Erik), and instead of submitting that query as-is to MarkLogic, you process the cts:query tree, to look for terms you want to adjust, or expand. Typically used to automatically blend in synonyms, related terms, or translations, but could be used to copy individual terms, and automatically add queries on attributes for those.

HTH!