You are here

Structured Query - query against elements of same entity type

(Note: not displaying the elements that arent needed for this question to save space)

 

<StructuredQuery>

     <DigestQueryStatement>

        <PersonGivenName>Jane</PersonGivenName><QueryMatch>exact</QueryMatch>

    <DigestQueryStatement>

    <DigestQueryStatement>

        <PersonGivenName>Mary</PersonGivenName><QueryMatch>exact</QueryMatch>

    <DigestQueryStatement>

    <DigestQueryStatement>

        <PersonSurName>Smith</PersonSurName><QueryMatch>exact</QueryMatch>

    <DigestQueryStatement>

</StructuredQuery>  

 

Shows a query for a Person with a first name of Jane or Mary and a last name of Smith.

 

Does that mean it returns both Jane Smith and Mary Smith? Or only the first match?

 

What is the difference between the above structured query and the one below?

 

<StructuredQuery>

    <DigestQueryStatement>

        <PersonGivenName>John</PersonGivenName><QueryMatch>exact</QueryMatch>

    <DigestQueryStatement>

    <DigestQueryStatement>

        <PersonSurName>Smith</PersonSurName><QueryMatch>exact</QueryMatch>

    <DigestQueryStatement>

</StructuredQuery>

</StructuredQuery>

    <DigestQueryStatement>

        <PersonGivenName>Mary</PersonGivenName><QueryMatch>exact</QueryMatch>

    <DigestQueryStatement>

    <DigestQueryStatement>

        <PersonSurName>Doe</PersonSurName><QueryMatch>exact</QueryMatch>

    <DigestQueryStatement>

</StructuredQuery>

 

The StructuredQuery element groups parameters for a single entity, as documented in the LEXS User Guide (pg 106-108).   Multiple StructuredQuery elements in a single query mean the search is for Data Items that include both entities.

So in the first example, all fields are contained in the same StructuredQuery element indicating that the search is for a Data Item containing a person with the last name Smith and the first name either Jane or Mary.  So if there are Data Items containing a person Mary Smith, that will be included in the list of hits returned, and if there is a Jane Smith, that will also be included in the list of hits.  Searches can return multiple hits, with the limit determined by the query as well as any limits the responder may have.

The second example has 2 StructuredQuery elements, so the search is only going to return Data Items that contain BOTH a person named John Smith AND a person named Mary Doe.

Thanks for the response. I really appreciate it..

yes. I did read pages 106..108 in the user guide. but still not clear on the two structured entites for two person entites. lexs/niem etc is new to me.

isnt a data item like a row in a relational dbase table? 

so the first query with only structuredquery is similar to

     SELECT * FROM Persons WHERE LastName='Smith' AND (FirstName='Jane' OR FirstName='Mary');

what does the second query with two sets of structuredQueries look like in sql? would it be an sql Union between two diff person tables that have first and last names?

     SELECT * FROM PersonTableONE WHERE LastName='Smith' AND FirstName='John'

     UNION

     SELECT * FROM PersonTableTWO WHERE LastName='Doe' AND FirstName='Mary'

if you can give a real world example when you would use the second kind of query, it would help a lot.

Thanks once again.  - Kamala

A Data Item isn't necessarily equivalent to rows in a table.  A Data Item is really in the eye of the beholder in that it represents a logical "thing" to whoever is defining it.  So in the case of an incident based reporting system, a Data Item would be an incident report.  In the case of a motor vehicle department, a Data Item might be a vehicle registration.  

So for an incident report, if you are looking for John Smith and Mary Doe,  you are looking for incident reports where both people were involved.  So maybe they were both victims, or maybe one was a subject and one was a witness, whatever.   So the SQL statement for that would involve some sort of join between say an incident table, a person table, and a table that links people to incidents in order to say I want incidents that involve both these people.

For something like a vehicle registration, inclusion of two separate people in the query might be used to find vehicles registered jointly to two people, or a registration transferred between the two people.