Richard Rodger
Richard Rodger

Reputation: 56

How to include imported fields in the search results?

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
    },
  }
}

Upvotes: 3

Views: 318

Answers (2)

Jo Kristian Bergum
Jo Kristian Bergum

Reputation: 3184

Currently you'll need to add the imported 'name' into the default summary by

 import field speaker.name as name {}

 document-summary default {
    summary name type string{}
  }

More about explicit document summaries in http://docs.vespa.ai/documentation/document-summaries.html

The result of your query will then return

 "children": [
        {
            "fields": {
                "documentid": "id:n1:person::1",
                "name": "p1",
                "sddocname": "person"
            },
            "id": "id:n1:person::1",
            "relevance": 0.0017429193899782135,
            "source": "stuff"
        },
        {
            "fields": {
                "code": "e1",
                "documentid": "id:n1:event::1",
                "name": "p1",
                "sddocname": "event",
                "speaker": "id:n1:person::1"
            },
            "id": "id:n1:event::1",
            "relevance": 0.0017429193899782135,
            "source": "stuff"
        }
    ],

We'll improve the documentation on this. Thanks for the very detailed write-up.

Upvotes: 6

Jon
Jon

Reputation: 2339

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".

Upvotes: 2

Related Questions