How to include imported fields in the search results?

Viewed 163

I'm using document references to import parent fields into a child document. While searches against the parent fields work, the parent fields themselves do not seem to be included in the search results, only child fields.

To use the example in the documentation, salesperson_name does not appear in the fields entry for id:test:ad::1 when using query=John, or indeed when retrieving id:test:ad::1 via GET directly.

Here's a simplified configuration for my document model:

search definitions

person.sd - the parent

search person {
  document person {
    field name type string {
      indexing: summary | attribute
    }
  }

  fieldset default {
    fields: name
  }
}

event.sd - the child

search event {
  document event {
    field code type string {
      indexing: summary | attribute
    }
    field speaker type reference<person> {
      indexing: summary | attribute
    }
  }

  import field speaker.name as name {}

  fieldset default {
    fields: code
  }
}

documents

p1 - person

{
  "fields": {
    "name": "p1"
  }
}

e1 - event

{
  "fields": {
    "code": "e1",
    "speaker": "id:n1:person::1"
  }
}

query result

curl -s "http://localhost:8080/search/?yql=select%20*%20from%20sources%20*where%20name%20contains%20%22p1%22%3B" | python -m json.tool

This returns both e1 and p1, as you would expect, given that name is present in both. But the fields of e1 do not include the name.

{
  "root": {
    "children": [
      {
        "fields": {
          "documentid": "id:n1:person::1",
          "name": "p1",
          "sddocname": "person"
        },
        "id": "id:n1:person::1",
        "relevance": 0.0017429193899782135,
        "source": "music"
      },
      {
        "fields": {
          "code": "e1",
          "documentid": "id:n1:event::1",
          "sddocname": "event",
          "speaker": "id:n1:person::1"
        },
        "id": "id:n1:event::1",
        "relevance": 0.0017429193899782135,
        "source": "music"
      }
    ],
    ...
    "fields": {
      "totalCount": 2
    },
  }
}
2 Answers

Add "summary" to the indexing statement of the imported field in the parent document type.

E.g in the documentation example change the "name" field in the "salesperson" document type to say "indexing: attribute | summary".

Related