Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda