Navin Rawat
Navin Rawat

Reputation: 3138

Marklogic Search on different values

I am working on Search in MarkLogic and my requirement is to bring result while searching "NAVIN RAWAT" is:

   o   Search should return for N Rawat

   o   Navin Rawat

   o   Navin R

   o   Navin Raw

   o   Navin Rawat

I am planning to use search:search to get these results. But, I am not getting how to get these results as they are different from each other. Could any body help or suggest me how to get these result while using MarkLogic search:search or cts:search.

Upvotes: 2

Views: 91

Answers (1)

Dave Cassel
Dave Cassel

Reputation: 8422

I think for requirements like this, you'll need to code up some search expansion. You could build a custom constraint for the Search API to do it. As a string query, you could then do something like

expand:"Navin Rawat"

A structured query would look different but convey the same thing. Next step is to do the actual expansion. It's not clear what rules you have in mind -- for the last name, is it any number of the starting letters, or is there a reason you didn't include "Navin Ra"? I'll assume you want any number of letters.

You could build a function that looks like this to provide options for the last name:

declare function local:choices($first, $last)
{
  for $i in (1 to fn:string-length($last))
  return
    fn:substring($last, 1, $i) ! ($first || " " || .)
};

local:choices("Navin", "Rawat")

=>

  • Navin R
  • Navin Ra
  • Navin Raw
  • Navin Rawa
  • Navin Rawat

With that done, your parse function could return a cts:word-query() with that sequence of strings. Throw in something for your "N Rawat" case, and you're set.

Upvotes: 4

Related Questions