Configure search locations programmatically

In our application, we want to exclude some by-default-checked locations (i.e., some special PST files listed in the profile), we also want to include some folders on the hard disk.

This can be done through the WDS options dialog. But we need to do it at background, a.k.a., programmatically. Is this possible

So far we found that following registries may be related:

HKEY_CURRENT_USER\Software\Microsoft\RSSearch\Gather\RSApp\MyIndex\Sites\LocalHost\Paths

HKEY_CURRENT_USER\Software\Microsoft\Windows Desktop Search\DS\Index\Rules

But we are afraid that directly deal with registry may require restart WDS, and it may also mess up WDS. In addition, if user clicks "Email and My Documents", our customizations would be gone. Is there a better way to achieve this

Thanks!



Answer this question

Configure search locations programmatically

  • AlpsInOz

    You can do this thru the crawl scope manager:

    http://msdn2.microsoft.com/en-us/library/bb266541.aspx



  • sapanasansar

    Hi wzhau2000,

    If I'm reading your question correctly, you can accomplish what you want using group policies. Please take a look at the following section of our administrator guide and let me know if this addresses your question. http://www.microsoft.com/technet/prodtechnol/windows/search/dtsguide.mspx#EGKAC

    Thanks,

    Paul Nystrom - MSFT



  • DasFox

    Hello again everybody,

    I successfully did this using the crawl scope manager like Eric said. The main code is here:

    Code Snippet

    CSearchManager manager = new CSearchManager();

    CSearchCatalogManager catalogManager = manager.GetCatalog("SystemIndex");

    ISearchCrawlScopeManager scopeManager = catalogManager.GetCrawlScopeManager();

    CSearchCrawlScopeManager cscopeManager = catalogManager.GetCrawlScopeManager();

    string endereco2 = "file:///C:/SDKWDS/";

    cscopeManager.AddUserScopeRule(endereco2, 1, 1, 0);

    cscopeManager.SaveAll();

    I also added a shared folder to the SystemIndex like Eric told me to do in another topic here in forum:

    Code Snippet

    string endereco6 = "otfs://{users SID}/server/path/";

    cscopeManager.AddUserScopeRule(endereco6, 1, 1, 0);

    cscopeManager.SaveAll();

    My problem now is: when I try to return the result from a WDS query on a webpage(which I've did with local contents), this result doesn't include the shared folder results that should be on it. Although, when I search through the WDS itself the result is complete.

    Here is the code that I use to make and show the query on the webpage:

    method that execute the query on the class Searcher:

    Code Snippet

    public ArrayList executeSqlQuery(Hashtable atributos)

    {

    // This uses SearchAPI interop assembly

    CSearchManager manager = new CSearchManager();

    // the SystemIndex catalog is the default catalog that windows uses

    CSearchCatalogManager catalogManager = manager.GetCatalog("SystemIndex");

    // get the ISearchQueryHelper which will help us to translate AQS --> SQL necessary to query the indexer

    CSearchQueryHelper queryHelper = catalogManager.GetQueryHelper();

    // --- Perform the query ---

    // create an OleDbConnection object which connects to the indexer provider with the windows application

    OleDbConnection conn = new OleDbConnection(queryHelper.ConnectionString);

    //Chama metodo para transformar a string de formato AQS para o formato WHERE

    string sqlQuery = queryParser(atributos, queryHelper);

    ArrayList resultList = new ArrayList();

    // show the sqlQuery

    resultList.Add(sqlQuery);

    conn.Open();

    // now create an OleDB command object with the query we built above and the connection we just opened.

    OleDbCommand command = new OleDbCommand(sqlQuery, conn);

    // execute the command, which returns the results as an OleDbDataReader.

    OleDbDataReader WDSResults = command.ExecuteReader();

    while (WDSResults.Read())

    {

    resultList.Add(WDSResults.GetString(0));

    }

    WDSResults.Close();

    conn.Close();

    return resultList;

    }

    Method that shows the result on the webpage:

    obs.: txtBusca is a TextBox

    Code Snippet

    Hashtable parametros = new Hashtable();

    parametros.Add("query", txtBusca.Text.Trim());

    Searcher searcher = new Searcher();

    ArrayList resultado = searcher.executeSqlQuery(parametros);

    BulletedList1.Items.Clear();

    ListItem itemList;

    foreach (string registro in resultado)

    {

    itemList = new ListItem(registro);

    BulletedList1.Items.Add(itemList);

    }

    Can anybody help me to solve this mistery

    Thanks a lot,



  • David Klitzke

    Returning to an old thread here.

    We are building a third-party app and would like to implement a feature where we could programmatically modify the search locations. I looked around the SDK documentation but found no obvious way to do it. Hacking registry is not the answer for us nor is using group policies. Is there really no way to modify the list of search locations

    Aali


  • Drake30

    Hi George,

    It may be possible to do what you want, but it isn't currently supported by Microsoft. Official words aside, I'll see if I'm not able to locate some information that might help you out.

    Paul Nystrom - MSFT



  • Calvin Wang

    That would be wonderful if there are some ways other than hacking the registry directly. Please let me know if something is available. I appreciate it.

    George


  • Lasfargues pierre

    Hello again everybody,

    I successfully did this using the crawl scope manager like Eric said. The main code is here:

    Code Snippet

    CSearchManager manager = new CSearchManager();

    CSearchCatalogManager catalogManager = manager.GetCatalog("SystemIndex");

    ISearchCrawlScopeManager scopeManager = catalogManager.GetCrawlScopeManager();

    CSearchCrawlScopeManager cscopeManager = catalogManager.GetCrawlScopeManager();

    string endereco2 = "file:///C:/SDKWDS/";

    cscopeManager.AddUserScopeRule(endereco2, 1, 1, 0);

    cscopeManager.SaveAll();

    I also added a shared folder to the SystemIndex like Eric told me to do in another topic here in forum:

    Code Snippet

    string endereco6 = "otfs://{users SID}/server/path/";

    cscopeManager.AddUserScopeRule(endereco6, 1, 1, 0);

    cscopeManager.SaveAll();

    My problem now is: when I try to return the result from a WDS query on a webpage(which I've did with local contents), this result doesn't include the shared folder results that should be on it. Although, when I search through the WDS itself the result is complete.

    Here is the code that I use to make and show the query on the webpage:

    method that execute the query on the class Searcher:

    Code Snippet

    public ArrayList executeSqlQuery(Hashtable atributos)

    {

    // This uses SearchAPI interop assembly

    CSearchManager manager = new CSearchManager();

    // the SystemIndex catalog is the default catalog that windows uses

    CSearchCatalogManager catalogManager = manager.GetCatalog("SystemIndex");

    // get the ISearchQueryHelper which will help us to translate AQS --> SQL necessary to query the indexer

    CSearchQueryHelper queryHelper = catalogManager.GetQueryHelper();

    // --- Perform the query ---

    // create an OleDbConnection object which connects to the indexer provider with the windows application

    OleDbConnection conn = new OleDbConnection(queryHelper.ConnectionString);

    //Chama metodo para transformar a string de formato AQS para o formato WHERE

    string sqlQuery = queryParser(atributos, queryHelper);

    ArrayList resultList = new ArrayList();

    // show the sqlQuery

    resultList.Add(sqlQuery);

    conn.Open();

    // now create an OleDB command object with the query we built above and the connection we just opened.

    OleDbCommand command = new OleDbCommand(sqlQuery, conn);

    // execute the command, which returns the results as an OleDbDataReader.

    OleDbDataReader WDSResults = command.ExecuteReader();

    while (WDSResults.Read())

    {

    resultList.Add(WDSResults.GetString(0));

    }

    WDSResults.Close();

    conn.Close();

    return resultList;

    }

    Method that shows the result on the webpage:

    obs.: txtBusca is a TextBox

    Code Snippet

    Hashtable parametros = new Hashtable();

    parametros.Add("query", txtBusca.Text.Trim());

    Searcher searcher = new Searcher();

    ArrayList resultado = searcher.executeSqlQuery(parametros);

    BulletedList1.Items.Clear();

    ListItem itemList;

    foreach (string registro in resultado)

    {

    itemList = new ListItem(registro);

    BulletedList1.Items.Add(itemList);

    }

    Can anybody help me to solve this mistery

    Thanks a lot,



  • sfx1

    Hello, Paul

    Thanks for the reply. I tried WDS group policies. It's very good.

    However, it seems this still can not solve our issues:

    1. In group policies, user can only ADD new locations, but not exclude locations. We want to exclude some PST files in users' profile.

    2. For PST files, it seems WDS is using its display name and a certain id to link to the PST file (see example below), is there a way that we can figure out this number

    3. The file path we want to add to search locations is not fixed. It's based on user mail alias (not samAccount). Maybe we can define some environment variables for this and use that in WDS group policies

    Example for a PST path: mapi://LocalHost/Default/Personal Folders ($ab1c)/

    How can we link the value in red to real PST files or vice versa. Or in another word, can PST be used in WDS group policies

    Thanks in advance!

    George


  • PGolini

    That result will only be return for that given user. Your web service is probably running under another user account. Items that belong on other users are trimmed out of the query result.



  • Guna Natarajan

    Hello Eric,

    I'm trying to do something like this (Configure search locations programmatically). Like you sugested, I've already got to the CrawlScopeManager, but I was wondering if there is any clear example on how to do this, because I'm having many difficulties to come to an algorithm.

    Thanks a lot,

    Andre

    P.S.: Appologizes for any spelling mistake.



  • Configure search locations programmatically