2
votes

I am working on an existing Marklogic application that is written in XQuery. We currently have a bucket constraint to allow faceting on defined date ranges set-up like so:

<constraint name="date" xmlns="http://marklogic.com/appservices/search">
    <range type="xs:gYear">
      <element ns="http://digital.library.ptsem.edu/ia" name="date"/>
      <bucket name="any-1800" lt="1801">–1800</bucket>
      <bucket name="1801-1825" ge="1801" lt="1826">1801–1825</bucket>
      <bucket name="1826-1850" ge="1826" lt="1851">1826–1850</bucket>
      <bucket name="1851-1875" ge="1851" lt="1876">1851–1875</bucket>
      <bucket name="1876-1900" ge="1876" lt="1901">1876–1900</bucket>
      <bucket name="1901-1925" ge="1901" lt="1926">1901–1925</bucket>
      <bucket name="1926-any" ge="1926">1926–</bucket>
    </range>
  </constraint>

Users currently have the option of selecting these date ranges by clicking the corresponding facets in the UI.

What I'd like to do is allow users to enter beginning and end dates in a form in order to search by custom date ranges. For example, they'd be able to type 1950 - 1970 in the text form and search this range. I'm thinking that these custom ranges can probably be implemented by removing the current date bucket constraint from search options and instead using range constraints so we can do something like (date-start:1800 AND date-end:1900) in the query text. Another option would be setting a bucket constraint on the fly, based on user-entered years.

I don't really know where to start or what the best approach would be. Has anyone done something similar or have a recommendation on how best to implement this?

Thanks!

1
This post (and its comments) should get you started: blog.davidcassel.net/2012/06/…joemfb

1 Answers

2
votes

Removing the buckets from your constraint will make you lose your current facets. So that doesn't sound like an option.

I am not sure, but I'd expect you can already use that date constraint as you described. The only catch is that -start and -end notation is Corona-style as far as I know, and search:search, and search:parse expect syntax like 'date GE 1800 AND date LT 1900'. The link mentioned in the comment of joemfb above mentions this syntax as well.

If you can't work with the current date constraint this way because of the buckets, just make two constraints. One dateFacets containing the buckets for facets, the other for custom searches.

You can do a bit of pre-parsing if you like. If you see patterns like date:1950-1970, you could rewrite that to the date GE/LT expression, using string functions. Should be doable given the fixed pattern. Done that as well, no problem at run-time.

Generating custom buckets works also. If is very easy to generate a special bucket for particular search patterns. I actually left a comment on the blog post mentioned above about just doing that.

So, plenty ways to go actually.

HTH!