1

I am using below code to get a component list from particular folder based on a particular schema.

SearchQueryData queryData = new SearchQueryData
{
    BasedOnSchemas = new BasedOnSchemaData[]
    {
        new BasedOnSchemaData()
        {
            Schema = new LinkToSchemaData {IdRef = schemaId}
        }
    },
    SearchIn = new LinkToIdentifiableObjectData { IdRef = folderId },
    ItemTypes = new ItemType[] { ItemType.Component }
}; 
IdentifiableObjectData[] compList = _client.GetSearchResults(queryData);

It is working fine for most of the folders. But for few folders it is not working properly. [No Error Message is there. Only count of the component is 0].

I have already compared the folder properties, and there is no mismatch. Also found that the issue is happening for newly created folders only.

Do you have any clue ? Please suggest. [FYI: I am Using 2013 SP1]

  • 1
    If it is a new content maybe it is not indexed by search engine yet. – Stanislav Maryenko Mar 29 '16 at 9:32
  • Exactly! When I am searching in Content Manager from the Advance search option the result is 0. – Sayantan Basu Mar 29 '16 at 10:12
  • 2
    The content is not immediately indexed. Search Indexer service should pick up new messages and process them. It polls for new messages every 30 seconds by default. – Stanislav Maryenko Mar 29 '16 at 10:42
  • 1
    Thanks @Stanislav for the information, I have found the issue. Our Search indexer was not working from last few day. We have restarted the services and It started working now. So from Code also I am able to get the result back. – Sayantan Basu Mar 29 '16 at 11:37
  • Please put this as answer so that we have an answered question rather than discussed. :) – Vikas Kumar Mar 29 '16 at 20:51
2

The issue is resolved now. The Search indexer service went down initially because of which the data was not indexed properly.

As a resolution, I have restarted the indexer and search host services and it's working as expected.

2

If you want to avoid dependency on Search Indexer, below are few options:

Option1: Use OrganizationalItemItemsFilterData

If you are not looking to get components recursively from a folder, another option could be to use OrganizationalItemItemsFilterData to filter items from the folder.

The good thing about this approach is, you don't need to care about the search indexer and it could be faster in execution as well.

The only downside is the OrganizationalItemItemsFilterData doesn't work recursively. Though there is a property filter.Recursive, but if you set it to true, filter.BasedOnSchemas condition stops working and returns components with other schemas as well. So you will have to further filter the xml results.

Example Code:

LinkToSchemaData[] schemas = new[] { 
        new LinkToSchemaData { IdRef = "{SchemaId}" } 
    };

OrganizationalItemItemsFilterData filter = 
    new OrganizationalItemItemsFilterData();

filter.BaseColumns = ListBaseColumns.Extended;
filter.ItemTypes = new ItemType[] { ItemType.Component };
filter.BasedOnSchemas = schemas;

XElement items = client.GetListXml("{folderId}", filter);

Option2: Use UsingItemsFilterData

You can use below code sample to get the component based on a schema, but it will return all the components from a publication. So you would have to filter the result XML based on the organizational item (folder), there will be an attribute named "OrgItemID" for the same in the result XML.

 UsingItemsFilterData filter = new UsingItemsFilterData();

            filter.BaseColumns = ListBaseColumns.Extended;
            filter.ItemTypes = new ItemType[] { ItemType.Component };
            filter.InRepository = new LinkToRepositoryData() { IdRef="{PublicationId}" };
            XElement items = client.GetListXml("{schemaId}", filter);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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