Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
Concatenate json fields and search on concatenated value in MarkLogic

I have below json format for storing person's firstname and lastname. I also store person's nickname as well.

{
  "Person": {
    "Records": [
      {
        "nameType": "Primary",
        "firstName": "Sagar",
        "lastName": "Dravid"
      },
      {
        "nameType": "konw as",
        "firstName": "Bunny",
        "lastName": "Bhau"
      }
    ]
  }
}

I am developing typeahead search API for that I need to combine both first name and last name. I am able to search on single individual field like only on either first name or on last name. tried below code

.where(cts.jsonPropertyValueQuery("firstName", [str + "* *"], ["wildcarded", "punctuation-insensitive", "diacritic-insensitive", "unstemmed", "case-insensitive"]))
  .map(mapper)
  .withOptions({
    search: ['filtered']
  })
  .result();

How I can concatenate json fields to achieve complete name search so, if user types "Sagar Dravid" or "Bunny Bhau" I should get result, but I should not get result if user types "Sagar Bhau" or "Bunny Dravid". Any suggestions?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If I understand your requirement correctly, you could use a cts.nearQuery with a cts.orQuery for each property (lastName and firstName) that has a cts.jsonPropertyValueQuery for each of the name values (splitting the on space):

const searchString = "Bunny Bhau"
const query = 
  cts.nearQuery(
    searchString.split(" ").map(term => 
      cts.orQuery(["firstName", "lastName"]
        .map(property => 
          cts.jsonPropertyValueQuery(property, term + "*" , 
            ["wildcarded", "punctuation-insensitive", "diacritic-insensitive", "unstemmed", "case-insensitive"])
        )
      )
    ), 
    1)

Which would generate the following:

cts.nearQuery([
  cts.orQuery([
    cts.jsonPropertyValueQuery("firstName", "Bunny*",
        [ "case-insensitive", "diacritic-insensitive", "punctuation-insensitive", "unstemmed", "wildcarded", "lang=en"], 1), 
    cts.jsonPropertyValueQuery("lastName", "Bunny*",
        [ "case-insensitive", "diacritic-insensitive", "punctuation-insensitive", "unstemmed", "wildcarded", "lang=en"], 1)
  ],[]), 
  cts.orQuery([
    cts.jsonPropertyValueQuery("firstName", "Dravid*",
        [ "case-insensitive", "diacritic-insensitive", "punctuation-insensitive", "unstemmed", "wildcarded", "lang=en"], 1), 
    cts.jsonPropertyValueQuery("lastName", "Dravid*",
        [ "case-insensitive", "diacritic-insensitive", "punctuation-insensitive", "unstemmed", "wildcarded", "lang=en"], 1)
  ],[])],
  1,[], 1)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!