If I understand correctly, you're asking how to match element-attribute-words without using an explicit query constraint? That is, you'd like q=alex to match an element-attribute like assessment/@title as well as ordinary word-query matches.
If that's right, https://docs.marklogic.com/search:search#opt-term may help. There's also some discussion of the idea at http://markmail.org/message/o67ipolmolzhm7jp In this case I think you'd end up needing to write a plugin function in XQuery (or perhaps JavaScript?) to implement your query logic. The docs have an example: <term apply="my-term-query" ns="http://custom/search" at="/lib/custom.xqy"> <empty apply="all-results"/> </term> That refers to a function, and I don't see an example in the docs. But if it uses the same interface as a custom constraint, then it might look like this: declare function cs:my-term-query( $constraint-qtext as xs:string, $right as schema-element(cts:query)) as schema-element(cts:query) { cts:or-query( (cts:word-query(string($right//cts:text), cts:element-attribute-word-query( (xs:QName('assessment'), xs:QName('assessmentSection')), xs:QName('title'), string($right//cts:text)) )) ! document{ . }/* ! element { node-name(.) } { attribute qtextconst { concat($constraint-qtext, fn:string($right//cts:text)) }, @*, node() } }; That's untested, but it may put you on the right path. You could extend the element-attribute-word-query to handle additional element QNames and attribute QNames. -- Mike > On 11 Mar 2015, at 05:49 , <[email protected]> > <[email protected]> wrote: > > Hi All: > > I am seeing a below problem in Search API. > > Let’s consider the below xml. We have title attribute (@title="Auto Test > Assessment Update"). > > XML: > > <?xml version="1.0" encoding="UTF-8"?> > <assessment title="Auto Test Assessment Update" > identifier="00154ab3-167f-4b30-a53a-ecf633ff6bd2"> > <lastModifiedDate>2015-01-30T01:00:59.03454-05:00</lastModifiedDate> > <created_by>Alex</created_by> > <assessmentSection identifier="" title="Wrapper Section" > assessmentSectionRefCount="1"> > <assessmentSectionRef identifier="463491ee-1f7d-433e-bd87-750121229dda"/> > </assessmentSection> > </assessment> > > Test-1: > > Consider the below REST URL, I am retrieving the above xml which contain the > word “Auto” in title attribute using the below search constraint and this > works fine. > > 172.17.103.44:9000/v1/search?q=title:"Auto"&collection=Assessments&options=search-assessment&format=xml > > <search:constraint name="title"> > <search:word> > <search:attribute ns="" name="title"/> > <search:element ns="" name="assessment"/> > </search:word> > </search:constraint> > > Test-2: > > I want to retrieve the same xml without constraint search (without constraint > name in URL) as below. > > 172.17.103.44:9000/v1/search?q=Auto&collection=Assessments&options=search-assessment&format=xml > > This doesn’t retrieve the above xml because Marklogic will default create > cts:word-query(“Auto”) and looks through only elements not attributes. So it > fails. > > For the below URL, Marklogic will default create cts:word-query(“Ale”). The > above xml is retrieved because we have “Alex” in “created_by” > element(<created_by>Alex</created_by>) > > 172.17.103.44:9000/v1/search?q=Alex&collection=Assessments&options=search-assessment&format=xml > > As we know attribute search is not part of Marklogic. Is there any solution > to this problem? > Is there any option in Marklogic admin page (like attribute search scope) > where I can configure to make attribute search work? > > We don’t have anything like cts:attribute-word-query() in Marklogic (to > search through attributes) like we have cts:word-query (which does for > element text content). > > Warm regards, > Melkis Penyameen Sathak J > Associate – Projects > Advanced Solution Group > Cognizant Technology Solutions > > This e-mail and any files transmitted with it are for the sole use of the > intended recipient(s) and may contain confidential and privileged > information. If you are not the intended recipient(s), please reply to the > sender and destroy all copies of the original message. Any unauthorized > review, use, disclosure, dissemination, forwarding, printing or copying of > this email, and/or any action taken in reliance on the contents of this > e-mail is strictly prohibited and may be unlawful. Where permitted by > applicable law, this e-mail and other e-mail communications sent to and from > Cognizant e-mail addresses may be monitored. > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
