File tree Expand file tree Collapse file tree 5 files changed +37
-14
lines changed Expand file tree Collapse file tree 5 files changed +37
-14
lines changed Original file line number Diff line number Diff line change 6
6
#include " base/logging.hpp"
7
7
#include " base/timer.hpp"
8
8
9
- #include < utility>
9
+ #include < string>
10
+ #include < vector>
10
11
11
12
namespace search
12
13
{
@@ -31,6 +32,8 @@ class Emitter
31
32
32
33
void AddBookmarkResult (bookmarks::Result const & result) { m_results.AddBookmarkResult (result); }
33
34
35
+ void PrecheckHotelQuery (std::vector<uint32_t > const & types) { m_results.PrecheckHotelQuery (types); }
36
+
34
37
void Emit (bool force = false )
35
38
{
36
39
if (m_prevEmitSize == m_results.GetCount () && !force)
Original file line number Diff line number Diff line change 2
2
3
3
#include " search/result.hpp"
4
4
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"
13
6
14
- return classifier.IsHotelResults ();
15
- }
7
+ #include " base/logging.hpp"
8
+
9
+ using namespace std ;
16
10
11
+ namespace search
12
+ {
17
13
void HotelsClassifier::Add (Result const & result)
18
14
{
19
15
if (result.m_details .m_isHotel )
@@ -22,14 +18,23 @@ void HotelsClassifier::Add(Result const & result)
22
18
++m_numResults;
23
19
}
24
20
21
+ void HotelsClassifier::PrecheckHotelQuery (vector<uint32_t > const & types)
22
+ {
23
+ m_looksLikeHotelQuery = ftypes::IsHotelChecker::Instance ()(types);
24
+ }
25
+
25
26
void HotelsClassifier::Clear ()
26
27
{
27
28
m_numHotels = 0 ;
28
29
m_numResults = 0 ;
30
+ m_looksLikeHotelQuery = false ;
29
31
}
30
32
31
33
bool HotelsClassifier::IsHotelResults () const
32
34
{
35
+ if (m_looksLikeHotelQuery)
36
+ return true ;
37
+
33
38
// Threshold used to activate hotels mode. Probably is too strict,
34
39
// but we don't have statistics now.
35
40
double const kThreshold = 0.75 ;
Original file line number Diff line number Diff line change 1
1
#pragma once
2
2
3
3
#include < cstdint>
4
+ #include < vector>
4
5
5
6
namespace search
6
7
{
7
8
class Result ;
8
9
class Results ;
10
+
9
11
// 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.
11
18
//
12
19
// *NOTE* This class is NOT thread safe.
13
20
class HotelsClassifier
14
21
{
15
22
public:
16
- static bool IsHotelResults (Results const & results);
17
-
18
23
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
+
19
28
void Clear ();
20
29
21
30
bool IsHotelResults () const ;
22
31
23
32
private:
24
33
uint64_t m_numHotels = 0 ;
25
34
uint64_t m_numResults = 0 ;
35
+ bool m_looksLikeHotelQuery = false ;
26
36
};
27
37
} // namespace search
Original file line number Diff line number Diff line change @@ -315,6 +315,9 @@ void Processor::SetQuery(string const & query)
315
315
if (!m_isCategorialRequest)
316
316
ForEachCategoryType (tokenSlice, [&](size_t , uint32_t t) { m_preferredTypes.push_back (t); });
317
317
318
+ if (m_isCategorialRequest)
319
+ m_emitter.PrecheckHotelQuery (m_preferredTypes);
320
+
318
321
base::SortUnique (m_preferredTypes);
319
322
}
320
323
Original file line number Diff line number Diff line change @@ -218,6 +218,8 @@ class Results
218
218
219
219
void AddBookmarkResult (bookmarks::Result const & result);
220
220
221
+ void PrecheckHotelQuery (std::vector<uint32_t > const & types) { m_hotelsClassif.PrecheckHotelQuery (types); }
222
+
221
223
void Clear ();
222
224
223
225
Iter begin () { return m_results.begin (); }
You can’t perform that action at this time.
0 commit comments