Getting individual documents from a search result

The query takes in an array of document refs and returns the matching data sets:

Map(
  [
    "319171832765743691",
    "319171854858191435",
    "319171860832977483",
    "319171837619601995"
  ],
  Lambda(
    "techRef",
    Paginate(
      Union(
        Match(
          Index("jobs_search_by_tech"),Ref(Collection("Technologies"), Var("techRef"))
        )
      )
    )
  )
)

The results is as follows:

[
  {
    data: [Ref(Collection("Jobs"), "319171953497735755")]
  },
  {
    data: [
      Ref(Collection("Jobs"), "319172102476268107"),
      Ref(Collection("Jobs"), "319334582500459081")
    ]
  },
  {
    data: [Ref(Collection("Jobs"), "319173092168434251")]
  },
  {
    data: [Ref(Collection("Jobs"), "319171953497735755")]
  }
]

Trying to figure out how to get the individual documents + selected fields

I just whipped this up without testing it, but hopefully it will point you in the right direction:

Let({
  techReferences: Map(
    [
      "319171832765743691",
      "319171854858191435",
      "319171860832977483",
      "319171837619601995"
    ],
    Lambda(
      "techDocId",
      Ref(Collection("Technologies"), Var("techDocId"))
    ),
  ),
  allMatchedJobReferencesSetRef: Join(
    Var('techReferences'),
    Match(
      Index("jobs_search_by_tech"),Ref(Collection("Technologies"), Var("techRef"))
    ),
  )
},
  Map(
    Paginate(Var('allMatchedJobReferencesSetRef'), {size: 10000}),
    Lambda(
      'jobRef',
      Get(Var('jobRef'))
    ),
  )
)

It should give you a page of job documents that look like:

{
  // an array of job documents are in here
  data: [
    {
      id: ... 
      ref: ...
      data: {
        ... // job data here
      }
    },
    ... // rest of job documents   
  ],
  before: ... //standard page properties
  after: ...
}

And then if you stored that page in a variable in the Let statement called pageOfJobDocuments and wanted to extract the title of each job (assuming each one has a title property), you could add the following:

Map(
  Var('pageOfJobDocuments')
  Lambda(
    'jobDoc',
    Select(['data', 'title'], Var('jobDoc'))
  )
)
1 Like

Thanks Wallslide

Just seeing your response , Got the code below to work - But after seeing yours will refector! Thank You!

    .query(
      q.Map(
        q.Paginate(
          q.Union(
            q.Map(
              result,
              q.Lambda(
                "techName",
                q.Match(q.Index("jobs_search_by_tech"), q.Var("techName"))
              )
            )
          )
        ),
        q.Lambda(
          "X",
          q.Let(
            {
              doc: q.Get(q.Var("X")),
            },
            {
              company: q.Get(
                q.Select(["data", "companyRef"], q.Var("doc"), null)
              ),
              title: q.Select(["data", "title"], q.Var("doc"), null),
              active: q.Select(["data", "active"], q.Var("doc"), null),
              description: q.Select(
                ["data", "description"],
                q.Var("doc"),
                null
              ),
              id: q.Select(["ref", "id"], q.Var("doc"), null),
            }
          )
        )
      )
    )

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.