You can specify a collection in a query state.
The CollectionName element of the State type lets you specify the name of a collection to be used in a query. You can specify a maximum of one collection per state. However, you can use multiple states in a query, with each state potentially specifying a collection name.
Once you associate a collection with a state, then operations performed by that state will reference that collection. For example, a record search in a state with a collection name will search for records only in that collection. However, if the collection has one or more filter rules configured, then a SelectionFilter or SelectedRefinementFilter query will trigger that filter rule, which will make use of records in the target collection. For more information on filter rules (see Filter Rules).
<Request> ... <State> <Name>?</Name> <CollectionName>?<CollectionName> ... </State> ... </Request>where:
If you have a named state, you can then specify it in a ContentElementConfig in the query.
<Request xmlns="http://www.endeca.com/MDEX/conversation/3/0"> <Language>en</Language> <State> <Name>SalesRecs</Name> <CollectionName>Sales</CollectionName> <SelectionFilter Id="SalesFltr"> <filterString>FactSales_SalesAmount > 1000</filterString> </SelectionFilter> </State> <State> <Name>ResellerRecs</Name> <CollectionName>Resellers</CollectionName> </State> <RecordListConfig Id="Results"> <StateName>SalesRecs</StateName> </RecordCountConfig> </Request>
<cs:Results ...> <State ...> <Name>SalesRecs</Name> <CollectionName>Sales</CollectionName> <DataSourceFilter> <filterString>"FactSales_ProductKey" IS NOT NULL</filterString> </DataSourceFilter> <SelectionFilter Id="SalesFltr"> <filterString>FactSales_SalesAmount > 1000</filterString> </SelectionFilter> </State> <State ...> <Name>ResellerRecs</Name> <CollectionName>Resellers</CollectionName> <DataSourceFilter> <filterString>"DimReseller_ResellerKey" IS NOT NULL</filterString> </DataSourceFilter> <SelectionFilter> <filterString>"DimReseller_AnnualSales" > 1000</filterString> <AppliedFilterRule> <Source FilterId="SalesFltr"> <StateName>SalesRecs</StateName> </Source> <TargetPropertyKey>DimReseller_AnnualSales</TargetPropertyKey> </AppliedFilterRule> </SelectionFilter> </State> <cs:RecordCount Id="Results"> <cs:NumRecords>115</cs:NumRecords> </cs:RecordCount> </cs:Results>
In the response, note that the ResellerRecs state shows that a SelectionFilter implicit filter was run on the Resellers collection. The AppliedFilterRule element lists the source (filter ID and state) of the implicit filter.
<Fault> <faultcode>env:Server</faultcode> <faultstring>OES-000190: Collection 'Producs' does not exist.</faultstring> <detail> <Fault xmlns:ns2="http://www.endeca.com/MDEX/eql_parser/types" xmlns:ns3="http://www.endeca.com/MDEX/conversation/3/0"/> </detail> </Fault>
<cs:Results ...> <State ...> <Name>ResellerRecs</Name> <CollectionName>Resellers</CollectionName> <DataSourceFilter> <filterString>"DimReseller_ResellerKey" IS NOT NULL</filterString> </DataSourceFilter> <SelectionFilter> <filterString>"DimReseller_AnnualSales" > 1000</filterString> <AppliedFilterRule> <Source FilterId="SalesFltr"> <StateName>SalesRecs</StateName> </Source> <TargetPropertyKey>DimReseller_AnnualSales</TargetPropertyKey> </AppliedFilterRule> </SelectionFilter> </State> ... </cs:Results>
The purpose of adding the DataSourceFilter with the collection's unique property key ("ProductKey" in the example) is to limit the search to the records in the collection.
A FROM clause in an EQL query cannot directly reference a collection, but it can reference a state. However, if the state specifies a collection name, then the collection can be used via the state.
<Request> <Language>en</Language> <State> <Name>TotalSales</Name> <CollectionName>Sales</CollectionName> </State> <ns:EQLConfig Id="EQLQuery"> <StateName>TotalSales</StateName> <EQLQueryString> RETURN Results AS SELECT ARB(FactSales_SalesAmount) AS totalAmount FROM TotalSales GROUP BY FactSales_OrderQuantity </EQLQueryString> </EQLConfig> </Request>
The FROM clause specifies the TotalSales state as the source. Because the TotalSales state specifies the Sales collection, the records from that collection are used.