Developer forum

Forum » Development » Finding all indexes

Finding all indexes

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

For a custom load balancing index updater I need to find all available indexes and their builds (full disclosure, we're using DFS which synchronizes files rather than share them; this means we need to exclude the index files which in turn means we need to update them remotely)

For now, I have this:

private const string BaseIndexUrl = "http://{0}/Admin/Api/repositories/build/eCommerce/eCommerce-index-index/{1}/eCommerce/";

where {0} is replaced with the remote IP and {1} with a hard coded value of A and B for the two builds. This code assumes the index is called eCommerce.

However, I now have another site that has multiple indexes (for users and products) and different builds.

How do I make this more generic? Is there an API I can use to get all indexes and builds? Or a folder on disk I can analyze for this data?

Thanks!

Imar


Replies

 
Steffen Kruse Hansen Dynamicweb Employee
Steffen Kruse Hansen
Reply
This post has been marked as an answer

Hi Imar,

You should be able to use the 'Dynamicweb.Indexing.Repositories.RepositoryService' for this.

You can do something like this:

            var repositoryService = new Dynamicweb.Indexing.Repositories.RepositoryService();
            var repositories = repositoryService.GetRepositories();
            foreach (var repository in repositories)
            {
                var repositoryItems = repositoryService.GetRepositoryItems(repository);
                foreach (var repositoryItem in repositoryItems)
                {
                    if (repositoryItem.TypeName == "Index")
                    {
                        //Do something <br/> 
                    }
                }
            }

 

Hope this helps you.

Best regards,

Steffen

 

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Steffen,

That helps somewhat, thank you. This gives me all the indexes. But what about builds? In order to build the "Rebuild index URL", I need the Build as well in addition to the index. It seems that the RepositoryItem is a general purpose class and doesn't expose much information about the index, right? Is there a separate BuildService I can instantiate to query more data like the builds?

Thanks!

Imar

 
Steffen Kruse Hansen Dynamicweb Employee
Steffen Kruse Hansen
Reply
This post has been marked as an answer

Hi Imar,

When you have the RepositoryItem, which is your index, you can use the 'Dynamicweb.Indexing.IndexService' to load the actual Index object, which contains all the information you need, e.g. Build, Instances, etc.

See code below:

            var indexService = new Dynamicweb.Indexing.IndexService();
            var repositoryService = new Dynamicweb.Indexing.Repositories.RepositoryService();
            var repositories = repositoryService.GetRepositories();
            foreach (var repository in repositories)
            {
                var repositoryItems = repositoryService.GetRepositoryItems(repository);
                foreach (var repositoryItem in repositoryItems)
                {
                    if (repositoryItem.TypeName == "Index")
                    {
                        //Do something
                        var index = indexService.LoadIndex(repository, repositoryItem.Name);
                        var builds = index.Builds;
                    }
                }
            }

 

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Thanks Steffen. That helped a lot and I can now access the Builds and Instances.

For anyone else trying to build the URL to update a remote index, the format is as follows:

http://server/admin/api/repositories/build/RepoName/IndexName-index-index/InstanceName/BuildName

Imar

 

You must be logged in to post in the forum