Problem when using IDatabasePtr-->Search

Hello, I try to build a small plugin which uses the “IDatabasePtr–>Search(‘Title’ is […])” function. Using “IDatabasePtr–>Search(‘Title’ IS [searchstring], …, …)” works fine in most cases. But when the title contains parenthesis, the item will not be found. Using the UI search with the same searchstring works fine. Question: Do I have to escape the parenthesis in the search string? Or has anyone another idea what this could be(encoding,…)? Best regards Christian

The search should formatted as XML, so you may need to make use of XML escape sequences.  Here is an example search:

        IRecordListPtr    pMatches;
        if( (iRet=pDB->Search("<ENQuery><FlatQuery>(‘Year’ IS GREATER THAN [1980])</FlatQuery></ENQuery>",pRecordList,&pMatches)) != kServiceNoErr )
            gwOut << "FAILURE: IDatabase::Search " << iRet << “\n”;
        else
            gwOut << “SUCCESS: IDatabase::Search (” << pMatches->GetCount()<< “)\n”;

Hello,  thanks a lot for your answer.

I’ m sorry for my short example, but the searchstring is formatted as XML. Here is the “longer version”:

        […]
        IStringPtr    pKeyword = RS::CreateInstance<IStringImp>();        
        pKeyword->assign(“Title”);
        
        // BUILD XML
        std::string sXMLSearch = “<ENQuery><FlatQuery>(‘Title’ IS [”;
        sXMLSearch.append(pKeyword->c_str());
        sXMLSearch.append("])</FlatQuery></ENQuery>");
        
        // SEARCH
        if( (iRet=pDBMain->Search(sXMLSearch.c_str(), pAllListMain, &pMatches)) != kServiceNoErr )
        […]
        
This usually works fine. But if there are parentheses in the title no items will be found. The same search done via the user interface works fine.

e.g.

    1)        pKeyword->assign(“Title one”);    // FOUND
    2)        pKeyword->assign(“Title (two)”);    // NOT FOUND
    3)        UI: Title is “Title (two)”                // FOUND

Because the items will be found via UI, I´m not sure if i have to escape the parentheses or maybe there is a flag which I have to set.

Best regards
Christian