mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
For websites and forvo, don't add dummy word search results (as they don't have any index to search in) -- instead, make results empty, but mark the search uncertain, and don't mark the word input line as reddish in that case.
This is just a refinement on how the word search is done in the dictionaries that don't actually ability to search words in. Previously they emitted dummy italicized suggestions, which were getting in the way. Now they don't emit anything, but mark the search as uncertain. Any uncertain searches don't mark the word input with the different color to indicate the search has failed.
This commit is contained in:
parent
cc5e5b6c77
commit
04bdf3aa36
|
@ -131,6 +131,9 @@ class WordSearchRequest: public Request
|
|||
|
||||
public:
|
||||
|
||||
WordSearchRequest(): uncertain( false )
|
||||
{}
|
||||
|
||||
/// Returns the number of matches found. The value can grow over time
|
||||
/// unless isFinished() is true.
|
||||
size_t matchesCount();
|
||||
|
@ -143,6 +146,12 @@ public:
|
|||
/// done, this can only be called after the request has finished.
|
||||
vector< WordMatch > & getAllMatches() throw( exRequestUnfinished );
|
||||
|
||||
/// Returns true if the match was uncertain -- that is, there may be more
|
||||
/// results in the dictionary itself, the dictionary index isn't good enough
|
||||
/// to tell that.
|
||||
bool isUncertain() const
|
||||
{ return uncertain; }
|
||||
|
||||
protected:
|
||||
|
||||
// Subclasses should be filling up the 'matches' array, locking the mutex when
|
||||
|
@ -150,6 +159,7 @@ protected:
|
|||
Mutex dataMutex;
|
||||
|
||||
vector< WordMatch > matches;
|
||||
bool uncertain;
|
||||
};
|
||||
|
||||
/// This request type corresponds to any kinds of data responses where a
|
||||
|
@ -202,6 +212,9 @@ public:
|
|||
|
||||
vector< WordMatch > & getMatches()
|
||||
{ return matches; }
|
||||
|
||||
void setUncertain( bool value )
|
||||
{ uncertain = value; }
|
||||
};
|
||||
|
||||
/// A helper class for syncronous data read implementations.
|
||||
|
|
5
forvo.cc
5
forvo.cc
|
@ -54,13 +54,12 @@ public:
|
|||
|
||||
virtual QIcon getIcon() throw();
|
||||
|
||||
virtual sptr< WordSearchRequest > prefixMatch( wstring const & word,
|
||||
virtual sptr< WordSearchRequest > prefixMatch( wstring const & /*word*/,
|
||||
unsigned long /*maxResults*/ ) throw( std::exception )
|
||||
{
|
||||
// Dummy
|
||||
sptr< WordSearchRequestInstant > sr = new WordSearchRequestInstant;
|
||||
|
||||
sr->getMatches().push_back( WordMatch( word, 1 ) );
|
||||
sr->setUncertain( true );
|
||||
|
||||
return sr;
|
||||
}
|
||||
|
|
|
@ -1053,7 +1053,7 @@ void MainWindow::updateMatchResults( bool finished )
|
|||
|
||||
// Visually mark the input line to mark if there's no results
|
||||
|
||||
bool setMark = results.empty();
|
||||
bool setMark = results.empty() && !wordFinder.wasSearchUncertain();
|
||||
|
||||
if ( ui.translateLine->property( "noResults" ).toBool() != setMark )
|
||||
{
|
||||
|
|
|
@ -52,12 +52,12 @@ public:
|
|||
throw( std::exception );
|
||||
};
|
||||
|
||||
sptr< WordSearchRequest > WebSiteDictionary::prefixMatch( wstring const & word,
|
||||
sptr< WordSearchRequest > WebSiteDictionary::prefixMatch( wstring const & /*word*/,
|
||||
unsigned long ) throw( std::exception )
|
||||
{
|
||||
sptr< WordSearchRequestInstant > sr = new WordSearchRequestInstant;
|
||||
|
||||
sr->getMatches().push_back( WordMatch( word, 1 ) );
|
||||
sr->setUncertain( true );
|
||||
|
||||
return sr;
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ void WordFinder::startSearch()
|
|||
finishedRequests.clear();
|
||||
|
||||
searchErrorString.clear();
|
||||
searchResultsUncertain = false;
|
||||
|
||||
searchQueued = false;
|
||||
searchInProgress = true;
|
||||
|
@ -167,6 +168,9 @@ void WordFinder::requestFinished()
|
|||
if ( searchInProgress && !(*i)->getErrorString().isEmpty() )
|
||||
searchErrorString = tr( "Failed to query some dictionaries." );
|
||||
|
||||
if ( (*i)->isUncertain() )
|
||||
searchResultsUncertain = true;
|
||||
|
||||
if ( (*i)->matchesCount() )
|
||||
{
|
||||
newResults = true;
|
||||
|
|
|
@ -28,6 +28,7 @@ private:
|
|||
|
||||
SearchResults searchResults;
|
||||
QString searchErrorString;
|
||||
bool searchResultsUncertain;
|
||||
std::list< sptr< Dictionary::WordSearchRequest > > queuedRequests,
|
||||
finishedRequests;
|
||||
bool searchInProgress;
|
||||
|
@ -104,6 +105,11 @@ public:
|
|||
QString const & getErrorString()
|
||||
{ return searchErrorString; }
|
||||
|
||||
/// Returns true if the search was inconclusive -- that is, there may be more
|
||||
/// results than the ones returned.
|
||||
bool wasSearchUncertain() const
|
||||
{ return searchResultsUncertain; }
|
||||
|
||||
/// Cancels any pending search operation, if any.
|
||||
void cancel();
|
||||
|
||||
|
|
Loading…
Reference in a new issue