1

MarkLogic 9.0.8

On UI, apart from search text, few filters are applied including publish date year. As we can't control how end user will write query in multiline textbox.

So at end query look like something

  • AU:Manish AND PY:>=2001 AND CT:Control AND UT:uncontrol AND PY:<=2010
  • (AU:Manish AND PY:>=2001) OR (CT:Control AND UT:uncontrol AND PY:<=2010)
  • AU:Manish AND CT:Control AND UT:uncontrol AND PY:>=2001 AND PY:<=2010

Till now we managed with having year range at the end in query and was working with following code

Qyery: AU:Manish AND CT:Control AND UT:uncontrol OR PY:>=2001 AND PY:<=2010

<additional-query>
{
  cts:and-query((
       cts:path-range-query("contg/sortdate/yr", ">=",xs:int($startYear)),
       cts:path-range-query("contg/sortdate/yr", "<=",xs:int($endYear))))  
}
</additional-query>

But now as user can put year range anywhere in the query text, its not working as expected

So can we write condition in constraint directly and how to put additional query inside ?

<constraint name="Year">
   <range type="xs:int" facet="false">
       <path-index>article/date/year</path-index>
   </range>
</constraint>

Expected Behavior

If user pass year range then it should return documents within given range if not then it will not apply year range

Manish Joisar
  • 1,256
  • 3
  • 23
  • 47
  • As worded, it sounds like the requirement is both to allow the user and program to specify the publish year. Can you expand on the expected behavior? Is the goal to supply a default year if the user doesn't specify the year? Otherwise, what is the expected result happens if the user and program both specify a year? – ehennum Apr 22 '20 at 23:49
  • Thanks Ehennum for your reply. I have added expected behavior details – Manish Joisar Apr 23 '20 at 04:27
  • One approach would be to use search:parse() to parse the user's query. Then, inspect the parsed query to determine whether to add the programmatic query. By the way, these days cts:parse() is preferred to search:parse() because faster and more flexible. – ehennum Apr 23 '20 at 16:33
  • Thanks Ehennum for your reply. So you mean to say not possible with constraint ? – Manish Joisar Apr 24 '20 at 04:44
  • The Search API does support a custom constraint, but the custom constraint doesn't have the ability to inspect other constraints. – ehennum Apr 24 '20 at 18:15
  • Hello Ehennum, Thanks for you reply. "What do you mean by doesn't have ability to inspec other constraints ?" – Manish Joisar Apr 27 '20 at 05:40
  • A custom contraint can only see the query criteria tagged with the tag bound to the custom constraint. Query criteria tagged with other constraints aren't visible to the custom constraint. So, the custom constraint can't know whether the user has specified a year or not. – ehennum Apr 27 '20 at 15:19

0 Answers0