· Jun 18, 2018

Using iKnow metadata to get aggregate metadata values

I have iKnow domain of forum posts, their full text is an iKnow data, and each post also has a number of views as a metadata field.

I want to get a sum of views by concept. Let's say I have a concept called "TESTEST" and there are 10 sources that have this concept. Each source has some views. I want to get views total - impact of this concept so to say.

What's the best iKnow architecture for this use case?

So far I got this:

ClassMethod Views(id As %Integer) As %Integer
    #dim domainid As %Integer = ..#DomainId
    #dim sourceid As %String = ##class(%iKnow.Queries.SourceAPI).GetSourceId(domainid, id)
    #dim fieldId As %Integer = ##class(%iKnow.Queries.MetadataAPI).GetFieldId(domainid, "Views", .sc)
    set value = ##class(%iKnow.Queries.MetadataAPI).GetValueById(domainid, fieldId, sourceid, .sc)
    quit value

But it's a three stage process.

  1. Get all sources for a concept.
  2. Get Views metadata value for each source.
  3. Sum it all up.

Is there a better solution?

Discussion (1)0
Log in or sign up to continue

Hi Eduard,

for this sort of querying (and many other uses outside straight API calls), you can use the SQL projections generated for your domain, as documented in %iKnow.Tables.Utils. That'll generate a column for your Views metadata field on the table containing Source information, which you can then join to the Part (entity occurrence) table to filter the ones containing the requested entity.

Hope this helps,