[Solved]Contact Filter returns wrong Info



  • Hello All,

    The purpose is to add a contact iff the contact doesn't already exists. So i did the following

    @ // Filter for Contact Name search
    //First Name Filter
    QContactDetailFilter firstNameFilter;
    firstNameFilter.setDetailDefinitionName(QContactName::DefinitionName,
    QContactName::FieldFirstName);
    firstNameFilter.setMatchFlags(QContactFilter::MatchCaseSensitive | QContactFilter::MatchContains);
    firstNameFilter.setValue(firstName);

    //Last name Filter
    QContactDetailFilter lastNameFilter;
    lastNameFilter.setDetailDefinitionName(QContactName::DefinitionName,
                                        QContactName::FieldLastName);
    lastNameFilter.setMatchFlags(QContactFilter::MatchCaseSensitive | QContactFilter::MatchContains);
    lastNameFilter.setValue(lastName);
    
    QContactUnionFilter ufil;
    if(middleName.isEmpty())
    {
        ufil.prepend(firstNameFilter);
        ufil.prepend(lastNameFilter);
        //ufil = (firstNameFilter | lastNameFilter);
    }
    else
    {
        //Middle Name Filter
        QContactDetailFilter middleNameFilter;
        middleNameFilter.setDetailDefinitionName(QContactName::DefinitionName,
                                            QContactName::FieldMiddleName);
        middleNameFilter.setMatchFlags(QContactFilter::MatchCaseSensitive | QContactFilter::MatchContains);
        middleNameFilter.setValue(middleName);
    
        ufil.prepend(firstNameFilter);
        ufil.prepend(lastNameFilter);
        ufil.prepend(middleNameFilter);
        //ufil = (firstNameFilter | lastNameFilter | middleNameFilter);
    }
    
    QList<QContact> matchingContacts = m_contactManager->contacts(ufil);@
    

    But it always returns with wrong info. For example if i want to add "ABC(first name) XYZ(last name)" and the contact contains "QWE XYZ" it returns QWE XYZ instead of returning null.

    Could anybody help me with this please.



  • Hi,

    With what device / environment are you seeing this behaviour?
    There is a bug http://bugreports.qt.nokia.com/browse/QTMOBILITY-856 about something similar on Symbian, but I don't know whether this is the same issue as reported there.

    Cheers,
    Chris.



  • Thanks a lot Chris i commented on the bug report as i am facing the same problem. I tested it on 5230, N97 mini and 5800 (Qt: 4.6.3 and mobility: 1.0.2).

    Is there any workaround? I have no idea about symbian programming.



  • Well, you can filter manually (by retrieving all contacts, and checking the name fields in a for-loop). But the other possibility is that maybe your usecase is better fulfilled by an intersection filter instead of a union filter, as I believe that intersection filters do not suffer the same problem.

    Eg: create an intersection filter from a first-name-filter and a last-name-filter, then manually compare the contacts returned which match that filter, to the contact which you're searching for.

    Good luck!



  • I replaced QContactUnionFilter with QContactIntersectionFilter and it works now. Thank you.

    What is the difference between these two as functionality looks same? I mean other than Union Vs Intersection difference.



  • No difference - internally they're just a (sorted) list of filters, thereby allowing arbitrarily complex filter trees. How each filter is handled is backend specific, so backends can perform canonicalisation or logical reduction to improve performance, which is why a bug in the backend can affect the results of a query with a filter.

    In general, for a union filter, the query will return any contact which matches any of the filters in the union; for an intersection filter, the query will return any contact which matches ALL of the filters in the intersection.

    Cheers,
    Chris.



  • Thanks for the explanation Chris it makes much sense now. The Qt Docs for Qt Mobility needs an update :)



  • No worries :-)

    Please do file bugs on JIRA about any doc issues you see in Mobility, so that the issue can be tracked, prioritised and fixed.

    Thanks,
    Chris.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.