Search Worksite documents with more than one parameters

I wrote a c# code to search worksite documents.  It works fine when I only provide one single parameter, however, if I provide more than one, it will return no result (result count=0).  I would like to search either (author=srchKey) OR (fulltext=srchKey).  I have been banging my head, could anyone please help? Thanks a lot.

 

Below is my code:

 

public List<iManageVO> RunSearch(string srchKey)
{

   try
   {

         iManageSearch rds = new iManageSearch(isession);

        // Populate searchparameters
        IManProfileSearchParameters searchparams = Utility.CreateUnpopulatedProfileParams(idms);
        

        // the code works, if there is only one searchparams, but if I un-comments one, it will return no result.

        // i would like to search either author = srchKey OR Description = srchKey
        //searchparams.Add(imProfileAttributeID.imProfileAuthor, srchKey);
        //searchparams.Add(imProfileAttributeID.imProfileFullText, srchKey);
        searchparams.Add(imProfileAttributeID.imProfileDocNum, srchKey);
        //searchparams.Add(imProfileAttributeID.imProfileDescription, srchKey);

 

       // Search documents
        IManDocuments results = rds.GetDocuments(Utility.BuildDatabaseList(isession.Databases), searchparams);

        List<iManageVO> foundDocuments = null;
        // Check results
        if (results != null)
         {
                foundDocuments = new List<iManageVO>();
                strResult = "Search returned " + results.Count + " document(s).";
                foreach (IManDocument document in results)
                  {
                        
                                 iManageVO doc = new iManageVO();
                                 doc.Description = document.Description;
                                 doc.Author = document.Author.FullName;
                                 doc.DocId = document.Number;

                                  doc.iManageNrl = document.ObjectID;

                                  foundDocuments.Add(doc);
                             
                     }

             }

               return foundDocuments;
    }
    catch (ApplicationException ae)
    {
                 throw ae;
     }


}

Comments

  • Hi,

    There's a section in the API document "WorkSite COM Developers Reference Guide (8.5, English)" about using complex queries. I used it a long time ago, can't find any examples from my current code base so here's the example from the book which I think will best help you:

     

    Example C – Search Query: (CLIENT="5679") OR (MATTER="91003") OR (CLASS="LETTER" AND PRACTICE="C29ALIAS")
    private void ExampleC(IManSession sess, ManStrings dblist)
    {
    // Search Query: (CLIENT="5679") OR (MATTER="91003") OR
    // (CLASS="LETTER" AND PRACTICE="C29ALIAS")
    // Create OrQuery
    IManOrQuery orQuery = new ManOrQueryClass();
    // Use AddOrQuery to build an Or query between two different attribute
    // IDs (CLIENT="5679") OR (MATTER="91003")
    IManOrQuery oq = orQuery.AddOrQuery();
    IManFieldQuery oqC1 = _
    oq.AddFieldQuery(imProfileAttributeID.imProfileCustom1);
    oqC1.Values.Add("5679");
    IManFieldQuery oqC2 = oq.AddFieldQuery(imProfileAttributeID.imProfileCustom2);
    oqC2.Values.Add("91003");
    // Use AddAndQuery to build an And subquery between two different
    // attributeIDs (CLASS="LETTER" AND PRACTICE="C29ALIAS")
    IManAndQuery aq = orQuery.AddAndQuery();
    IManFieldQuery aqC = _
    aq.AddFieldQuery(imProfileAttributeID.imProfileClass);
    aqC.Values.Add("LETTER");
    IManFieldQuery aqC29 = _
    aq.AddFieldQuery(imProfileAttributeID.imProfileCustom29);
    aqC29.Values.Add("C29ALIAS");
    try
    {
    string strResults= string.Empty;

    int ct = 0;
    // Pass in the ManOrQuery parameter to run the search
    IManDocuments results = _
    (IManDocuments)sess.WorkArea.SearchDocumentsEx(dblist, orQuery);
    ...
    }

  • Hi RKnott1,

    Thank you so much. I tried this example, but I got an error message when I stepped the code to 

     

    (IManDocuments)isession.WorkArea.SearchDocumentsEx(Utility.BuildDatabaseList(isession.Databases), orQuery);

     

    The error message is: System.Runtime.InteropServices.COMException (0x8004265A): [WorkArea ][SearchDocumentsEx ]Search parameter invalid
    at Com.Interwoven.WorkSite.iManage.IManWorkArea.SearchDocumentsEx(ManStrings dblist, IManQuery query)

     

    I am using Interop.IManage.dll (8.5.0.0), Runtime version: 2.0.50727

     

    Below is my code: (it is short)

     

    IManDocuments results = null;
    string strResult = string.Empty;
    // build query
    IManOrQuery orQuery = new ManOrQueryClass();
    IManOrQuery oq = orQuery.AddOrQuery();
    IManFieldQuery oqC1 = oq.AddFieldQuery(imProfileAttributeID.imProfileDescription);
    oqC1.Values.Add("helpdesk");
    IManFieldQuery oqC2 = oq.AddFieldQuery(imProfileAttributeID.imProfileFullText);
    oqC2.Values.Add("helpdesk");
    try
    {

    string strResults= string.Empty;
    int ct = 0;
    // Pass in the ManOrQuery parameter to run the search
    results = (IManDocuments)isession.WorkArea.SearchDocumentsEx(Utility.BuildDatabaseList(isession.Databases), orQuery);

    ct = results.Count;

    return ct.ToString();
    }
    catch (Exception ex)
    {

    throw ex;
    }


     

Sign In or Register to comment.