Mercurial > hg > classical
view common/Matcher.cpp @ 29:9729919e589c classical-rdf
* minor fix to text matching
author | Chris Cannam |
---|---|
date | Mon, 01 Mar 2010 16:55:27 +0000 |
parents | 7d8a6167febb |
children | 8bed05455706 |
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ #include "Matcher.h" #include "Objects.h" #include <QMultiMap> using namespace Dataquay; namespace ClassicalData { UriList ComposerTypingQuickMatcher::match(QString text, int maxResults) const { UriList results; QMultiMap<float, Composer *> matches; foreach (Composer *c, m_composers) { float value = c->matchTypingQuick(text); matches.insert(value, c); } int n = 0; for (QMultiMap<float, Composer *>::const_iterator i = matches.end(); i != matches.begin(); ) { --i; if (i.key() <= 0) continue; results.push_back(i.value()->property("uri").value<Uri>()); if (++n > maxResults) break; } return results; } UriList ComposerTypingThoroughMatcher::match(QString text, int maxResults) const { UriList results; QMultiMap<float, Composer *> matches; foreach (Composer *c, m_composers) { float value = c->matchTyping(text); matches.insert(value, c); } int n = 0; for (QMultiMap<float, Composer *>::const_iterator i = matches.end(); i != matches.begin(); ) { --i; if (i.key() <= 0) continue; results.push_back(i.value()->property("uri").value<Uri>()); if (++n > maxResults) break; } return results; } }