Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to query a document library to get items associated with some taxonomy terms, or items with specific documentId (site collection scoped feature, not the integer ID of the item), but the whole query doesn't give me the expected result but each separated block does.

Here's the full query :

<OrderBy>
  <FieldRef Name="Modified" Ascending="FALSE"/>
</OrderBy>
<Where>
  <Or>
    <Or>    
      <Or>
        <Or>
          <Or>
            <Eq>
              <FieldRef Name="_dlc_DocId"/>
              <Value Type="Text">7JFXJRWQRFV7-3-3726</Value>
            </Eq>
            <Eq>
              <FieldRef Name="_dlc_DocId"/>
              <Value Type="Text">7JFXJRWQRFV7-3-3731</Value>
            </Eq>
          </Or>
          <Eq>
            <FieldRef Name="_dlc_DocId"/>
            <Value Type="Text">7JFXJRWQRFV7-3-3727</Value>
          </Eq>
        </Or>
        <Eq>
          <FieldRef Name="_dlc_DocId"/>
          <Value Type="Text">7JFXJRWQRFV7-3-3732</Value>
        </Eq>
      </Or>
      <Eq>
        <FieldRef Name="_dlc_DocId"/>
        <Value Type="Text">7JFXJRWQRFV7-3-3728</Value>
      </Eq>
    </Or>
    <And>
      <In>
        <FieldRef Name="WATSON_GED_META__xTaxonomy" LookupId="True" />
        <Values>
          <Value Type="Integer">0</Value>
          <Value Type="Integer">1</Value>
          <Value Type="Integer">2</Value>
          <Value Type="Integer">230</Value>
          <Value Type="Integer">263</Value>
          <Value Type="Integer">270</Value>
          <Value Type="Integer">376</Value>
          <Value Type="Integer">377</Value>
          <Value Type="Integer">378</Value>
          <Value Type="Integer">379</Value>
        </Values>
      </In>
      <BeginsWith>
        <FieldRef Name="ContentTypeId"/>
        <Value Type="Text">0x0101</Value>
      </BeginsWith>
    </And>
  </Or>
</Where>

This query just give me the documents tagged with specified taxonomy terms (wssId), but none of the items with the specified DocumentIds in the nested "Or".

On the other side, this query (let's call it Query1) gives me the 5 items :

<OrderBy>
  <FieldRef Name="Modified" Ascending="FALSE"/>
</OrderBy>
<Where>
  <Or>  
    <Or>
      <Or>
        <Or>
          <Eq>
            <FieldRef Name="_dlc_DocId"/>
            <Value Type="Text">7JFXJRWQRFV7-3-3726</Value>
          </Eq>
          <Eq>
            <FieldRef Name="_dlc_DocId"/>
            <Value Type="Text">7JFXJRWQRFV7-3-3731</Value>
          </Eq>
        </Or>
        <Eq>
          <FieldRef Name="_dlc_DocId"/>
          <Value Type="Text">7JFXJRWQRFV7-3-3727</Value>
        </Eq>
      </Or>
      <Eq>
        <FieldRef Name="_dlc_DocId"/>
        <Value Type="Text">7JFXJRWQRFV7-3-3732</Value>
      </Eq>
    </Or>
    <Eq>
      <FieldRef Name="_dlc_DocId"/>
      <Value Type="Text">7JFXJRWQRFV7-3-3728</Value>
    </Eq>
  </Or>
</Where>

and this one (let's call it Query2) gives me 90 items :

<OrderBy>
  <FieldRef Name="Modified" Ascending="FALSE"/>
</OrderBy>
<Where>
  <And>
    <In>
      <FieldRef Name="WATSON_GED_META__xTaxonomy" LookupId="True" />
      <Values>
        <Value Type="Integer">0</Value>
        <Value Type="Integer">1</Value>
        <Value Type="Integer">2</Value>
        <Value Type="Integer">230</Value>
        <Value Type="Integer">263</Value>
        <Value Type="Integer">270</Value>
        <Value Type="Integer">376</Value>
        <Value Type="Integer">377</Value>
        <Value Type="Integer">378</Value>
        <Value Type="Integer">379</Value>
      </Values>
    </In>
    <BeginsWith>
      <FieldRef Name="ContentTypeId"/>
      <Value Type="Text">0x0101</Value>
    </BeginsWith>
  </And>
</Where>

So the union of those two queries should give me 95 items (the 5 items given by Query1 are not tagged with any of the taxonomy terms of Query2) but only gives me the same 90 items that Query2 returns. The full query seems to ignore the nested "Or". This query is however syntactically correct...

Is there some undocumented limitations querying on taxonomy fields? Could someone tell me what's wrong with my query and how I could do to make it work as expected ? I already tried to replace the "In" element with nested "Or" but in some case I have so many taxonomy wssIds (more than 200 nested "Or") that the query crashes.

Thanks.

share|improve this question
    
What happens if you "OR" on only one doc ID value instead of all 5? Maybe you are running upto some limit that effects joins on lists ? I would also try putting the taxonomy part on top and than "OR" on all the doc id values, so basically swapping your "union" of both queries around. –  Cameron Verhelst Feb 26 at 15:47

1 Answer 1

When you add these queries together, ensure that you make the ViewFields work so that if an item won't have a particular Field on it that field is marked as Nullable.

e.g. <FieldRef Name='SomeFieldOrOther' Type='URL' Nullable='TRUE'/>

i.e. do you have ViewFields specified for items returned by Query 2 that are not available on items returned from Query 1? If so and not marked as Nullable then items from query 1 will not appear in the results.

share|improve this answer
    
All the fields in the ViewFields are common to all content types of the library. I tried to add the Nullable attribute but that didn't change anything... –  sle1306 Aug 21 '12 at 6:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.