Skip to content

Commit a79c2e3

Browse files
mpimenovPolas
authored andcommitted
[search] Make HotelsClassifier look at the query too (and not only at results).
The main reason is to avoid flickering of the filter button when zoomed in to an area without hotels.
1 parent 1026a93 commit a79c2e3

File tree

5 files changed

+37
-14
lines changed

5 files changed

+37
-14
lines changed

search/emitter.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include "base/logging.hpp"
77
#include "base/timer.hpp"
88

9-
#include <utility>
9+
#include <string>
10+
#include <vector>
1011

1112
namespace search
1213
{
@@ -31,6 +32,8 @@ class Emitter
3132

3233
void AddBookmarkResult(bookmarks::Result const & result) { m_results.AddBookmarkResult(result); }
3334

35+
void PrecheckHotelQuery(std::vector<uint32_t> const & types) { m_results.PrecheckHotelQuery(types); }
36+
3437
void Emit(bool force = false)
3538
{
3639
if (m_prevEmitSize == m_results.GetCount() && !force)

search/hotels_classifier.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@
22

33
#include "search/result.hpp"
44

5-
namespace search
6-
{
7-
// static
8-
bool HotelsClassifier::IsHotelResults(Results const & results)
9-
{
10-
HotelsClassifier classifier;
11-
for (auto const & r : results)
12-
classifier.Add(r);
5+
#include "indexer/ftypes_matcher.hpp"
136

14-
return classifier.IsHotelResults();
15-
}
7+
#include "base/logging.hpp"
8+
9+
using namespace std;
1610

11+
namespace search
12+
{
1713
void HotelsClassifier::Add(Result const & result)
1814
{
1915
if (result.m_details.m_isHotel)
@@ -22,14 +18,23 @@ void HotelsClassifier::Add(Result const & result)
2218
++m_numResults;
2319
}
2420

21+
void HotelsClassifier::PrecheckHotelQuery(vector<uint32_t> const & types)
22+
{
23+
m_looksLikeHotelQuery = ftypes::IsHotelChecker::Instance()(types);
24+
}
25+
2526
void HotelsClassifier::Clear()
2627
{
2728
m_numHotels = 0;
2829
m_numResults = 0;
30+
m_looksLikeHotelQuery = false;
2931
}
3032

3133
bool HotelsClassifier::IsHotelResults() const
3234
{
35+
if (m_looksLikeHotelQuery)
36+
return true;
37+
3338
// Threshold used to activate hotels mode. Probably is too strict,
3439
// but we don't have statistics now.
3540
double const kThreshold = 0.75;

search/hotels_classifier.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
#pragma once
22

33
#include <cstdint>
4+
#include <vector>
45

56
namespace search
67
{
78
class Result;
89
class Results;
10+
911
// A binary classifier that can be used in conjunction with search
10-
// engine to decide whether the majority of results are hotels or not.
12+
// engine to decide whether the query is related to hotel search.
13+
//
14+
// Two ways we use to decide whether the user was searching for hotels:
15+
// 1. We may infer it from the query text.
16+
// 2. We may infer it from the query results: if the majority are hotels,
17+
// probably the query was too.
1118
//
1219
// *NOTE* This class is NOT thread safe.
1320
class HotelsClassifier
1421
{
1522
public:
16-
static bool IsHotelResults(Results const & results);
17-
1823
void Add(Result const & result);
24+
25+
// The types are parsed from the original query in search::Processor.
26+
void PrecheckHotelQuery(std::vector<uint32_t> const & types);
27+
1928
void Clear();
2029

2130
bool IsHotelResults() const;
2231

2332
private:
2433
uint64_t m_numHotels = 0;
2534
uint64_t m_numResults = 0;
35+
bool m_looksLikeHotelQuery = false;
2636
};
2737
} // namespace search

search/processor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ void Processor::SetQuery(string const & query)
315315
if (!m_isCategorialRequest)
316316
ForEachCategoryType(tokenSlice, [&](size_t, uint32_t t) { m_preferredTypes.push_back(t); });
317317

318+
if (m_isCategorialRequest)
319+
m_emitter.PrecheckHotelQuery(m_preferredTypes);
320+
318321
base::SortUnique(m_preferredTypes);
319322
}
320323

search/result.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ class Results
218218

219219
void AddBookmarkResult(bookmarks::Result const & result);
220220

221+
void PrecheckHotelQuery(std::vector<uint32_t> const & types) { m_hotelsClassif.PrecheckHotelQuery(types); }
222+
221223
void Clear();
222224

223225
Iter begin() { return m_results.begin(); }

0 commit comments

Comments
 (0)