From 3d0c30e568d1524d9ee5663366852e4d4bff700a Mon Sep 17 00:00:00 2001 From: Erwan Croze Date: Tue, 20 Feb 2018 12:00:25 +0100 Subject: [PATCH] Fixing searching cache --- include/linphone/api/c-magic-search.h | 5 +++ src/search/magic-search.cpp | 46 ++++++++++++++++++--------- src/search/magic-search.h | 5 ++- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/include/linphone/api/c-magic-search.h b/include/linphone/api/c-magic-search.h index a26f6e7fc..72d68029c 100644 --- a/include/linphone/api/c-magic-search.h +++ b/include/linphone/api/c-magic-search.h @@ -120,8 +120,13 @@ LINPHONE_PUBLIC void linphone_magic_search_reset_search_cache(LinphoneMagicSearc /** * Create a sorted list of SearchResult from SipUri, Contact name, * Contact displayname, Contact phone number, which match with a filter word + * During the first search, a cache is created and used for the next search and so on + * Use linphone_magic_search_reset_search_cache() to begin a new search * @param[in] filter word we search * @param[in] withDomain domain which we want to search only + * - "" for searching in all contact + * - "*" for searching in contact with sip SipUri + * - "yourdomain" for searching in contact from "yourdomain" domain * @return sorted list of \bctbx_list{LinphoneSearchResult} **/ LINPHONE_PUBLIC bctbx_list_t* linphone_magic_search_get_contact_list_from_filter(LinphoneMagicSearch *magicSearch, const char *filter, const char *withDomain); diff --git a/src/search/magic-search.cpp b/src/search/magic-search.cpp index 663877665..df23ef61c 100644 --- a/src/search/magic-search.cpp +++ b/src/search/magic-search.cpp @@ -35,7 +35,7 @@ MagicSearch::MagicSearch(const std::shared_ptr &core) : CoreAccessor(core) L_D(); d->mMinWeight = 0; d->mMaxWeight = 1000; - d->mSearchLimit = 10; + d->mSearchLimit = 30; d->mLimitedSearch = true; d->mDelimiter = "+_-"; d->mUseDelimiter = true; @@ -119,7 +119,10 @@ list MagicSearch::getContactListFromFilter(const string &filter, c if (filter.empty()) return list(); - if (getSearchCache() != nullptr) { + // We begin a new search if the last result size is superior or equal of the search limit size + if (getSearchCache() != nullptr && + (getLimitedSearch() && getSearchLimit() > getSearchCache()->size()) + ) { resultList = continueSearch(filter, withDomain); } else { resultList = beginNewSearch(filter, withDomain); @@ -186,36 +189,49 @@ list *MagicSearch::continueSearch(const string &filter, const stri SearchResult MagicSearch::search(const LinphoneFriend* lFriend, const string &filter, const string &withDomain) { unsigned int weight = getMinWeight(); const LinphoneAddress* lAddress = linphone_friend_get_address(lFriend); + bool allDomain = !withDomain.empty() && withDomain.compare("*") == 0; - if (lAddress == nullptr) return SearchResult(weight, nullptr); + if (allDomain && + lAddress == nullptr && + linphone_friend_get_presence_model(lFriend) == nullptr + ) return SearchResult(weight, nullptr); // Check domain - if (!withDomain.empty() && + if (!allDomain && + !withDomain.empty() && + lAddress != nullptr && withDomain.compare(linphone_address_get_domain(lAddress)) != 0 ) return SearchResult(weight, nullptr); + if (lAddress != nullptr) { + // SIPURI + if (linphone_address_get_username(lAddress) != nullptr) { + weight += getWeight(linphone_address_get_username(lAddress), filter); + } + // DISPLAYNAME + if (linphone_address_get_display_name(lAddress) != nullptr) { + weight += getWeight(linphone_address_get_display_name(lAddress), filter); + } + } + // NAME if (linphone_friend_get_name(lFriend) != nullptr) { weight += getWeight(linphone_friend_get_name(lFriend), filter); } // PHONE NUMBER - bctbx_list_t *phoneNumbers = linphone_friend_get_phone_numbers(lFriend); + bctbx_list_t *begin, *phoneNumbers = linphone_friend_get_phone_numbers(lFriend); + begin = phoneNumbers; while (phoneNumbers != nullptr && phoneNumbers->data != nullptr) { string number = static_cast(phoneNumbers->data); + const LinphonePresenceModel *presence = linphone_friend_get_presence_model_for_uri_or_tel(lFriend, number.c_str()); weight += getWeight(number, filter); + if (presence != nullptr) { + weight += getWeight(linphone_presence_model_get_contact(presence), filter); + } phoneNumbers = phoneNumbers->next; } - - // SIPURI - if (linphone_address_get_username(lAddress) != nullptr) { - weight += getWeight(linphone_address_get_username(lAddress), filter); - } - - // DISPLAYNAME - if (linphone_address_get_display_name(lAddress) != nullptr) { - weight += getWeight(linphone_address_get_display_name(lAddress), filter); - } + if (begin) bctbx_list_free(begin); return SearchResult(weight, lAddress, lFriend); } diff --git a/src/search/magic-search.h b/src/search/magic-search.h index c3f901ffc..e360ea249 100644 --- a/src/search/magic-search.h +++ b/src/search/magic-search.h @@ -116,7 +116,10 @@ public: * During the first search, a cache is created and used for the next search and so on * Use resetSearchCache() to begin a new search * @param[in] filter word we search - * @param[in] withDomain domain which we want to search only + * @param[in] withDomain + * - "" for searching in all contact + * - "*" for searching in contact with sip SipUri + * - "yourdomain" for searching in contact from "yourdomain" domain * @return sorted list of SearchResult with "filter" or an empty list if "filter" is empty **/ std::list getContactListFromFilter(const std::string &filter, const std::string &withDomain = "");