Hi Rahul,


If the year value would be stored in a properly QNamed element, this would
be easy. Add a decimal index on that QName element in the database, add a
range constraint on that QName in the options, and simply use GT and LT
operators in your $searchTerm:



mysearchterm AND year GT 1999 AND year LT 2011



Kind regards,

Geert



*Van:* [email protected] [mailto:
[email protected]] *Namens *Rahul Landge
*Verzonden:* vrijdag 11 november 2011 8:00
*Aan:* [email protected]
*Onderwerp:* [MarkLogic Dev General] Creating constraints in search:search



Hi,



     I have written a marklogic query where in we search for a term and
limit the record to a particular date range.



 *declare function local:getMatchDate($date1 as xs:string ,$fromYear as
xs:integer,$toYear as xs:integer)as xs:boolean *

* { let $year := xs:integer(substring($date1 ,0,5)) *

* return *

* if (fn:not($fromYear eq 0) and fn:not($toYear eq 0)) then *

* boolean  (($fromYear <= $year) and ($toYear>=$year ))*

* else fn:true()*

* };*

* *

*let $search:=search:search($searchTerm,*

*<options xmlns="http://marklogic.com/appservices/search";>*

*</options>,1,500000)*

* *

*let $results:= $search/search:result*

* *

*let $res :=( for $result in $results*

*where
local:getMatchDate(doc($result/@uri)/marc21:record/marc21:datafield[@tag='792'],$fromYear
,$toYear)*



I have explicitly used a where clause to limit the number of records to a
date range .However ,I need to use a constraint to limit the number of
records.

Please note that the date ie year is found in the
“*/marc21:record/marc21:datafield[@tag='792']”
 *tag of each document where the search is to be executed.



Kindly suggest how to go about doing this.



Thanks







*Rahul Landge**  |  Principal Software Engineer  |  **Arrk Group*



Tel +91 (0)22 2278 4275  |  Fax +91 (0)22 2278 4210  |  Mobile +91
(0)9867195337  |  www.arrkgroup.com



*THINK DIFFERENT. THINK ARRK.*

Web & mobile development specialists - Application Management services -
unique hybrid delivery.



*** British Computer Society & Computer Weekly National IT Awards medal
winner ***

*** Proud developers and supporters of Virgin Money Giving -
www.virginmoneygiving.org ***



Email Disclaimer: www.arrkgroup.com/EmailDisclaimer
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to