strus  0.17
weightedDocument.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
10 #ifndef _STRUS_WEIGHTED_DOCUMENT_HPP_INCLUDED
11 #define _STRUS_WEIGHTED_DOCUMENT_HPP_INCLUDED
12 #include "strus/index.hpp"
13 #include <utility>
14 #include <cmath>
15 #include <limits>
16 
17 namespace strus {
18 
22 {
23 public:
26  :m_docno(0),m_weight(0.0){}
29  :m_docno(o.m_docno),m_weight(o.m_weight){}
31  WeightedDocument( const Index& docno_, double weight_)
32  :m_docno(docno_),m_weight(weight_){}
33 
35  Index docno() const {return m_docno;}
37  double weight() const {return m_weight;}
38 
40  bool operator < ( const WeightedDocument& o) const
41  {
42  double diff = m_weight - o.m_weight;
43  if (fabs( diff) < std::numeric_limits<double>::epsilon())
44  {
45  return m_docno < o.m_docno;
46  }
47  else
48  {
49  return (diff < 0.0);
50  }
51  }
53  bool operator > ( const WeightedDocument& o) const
54  {
55  double diff = m_weight - o.m_weight;
56  if (fabs( diff) < std::numeric_limits<double>::epsilon())
57  {
58  return m_docno > o.m_docno;
59  }
60  else
61  {
62  return (diff > 0.0);
63  }
64  }
65 
66 private:
67  Index m_docno;
68  double m_weight;
69 };
70 
71 }//namespace
72 #endif
73 
int32_t Index
Number type generally used for locally counted indices.
Definition: index.hpp:29
Numeric types used for local and global indices.
bool operator<(const WeightedDocument &o) const
Comparison for sorting.
Definition: weightedDocument.hpp:40
Pure ranking result of a strus query without the attributes.
Definition: weightedDocument.hpp:21
bool operator>(const WeightedDocument &o) const
Comparison for sorting.
Definition: weightedDocument.hpp:53
WeightedDocument()
Default constructor.
Definition: weightedDocument.hpp:25
WeightedDocument(const Index &docno_, double weight_)
Constructor.
Definition: weightedDocument.hpp:31
WeightedDocument(const WeightedDocument &o)
Copy constructor.
Definition: weightedDocument.hpp:28
Index docno() const
Get the document number of the result.
Definition: weightedDocument.hpp:35
double weight() const
Get the accumulated weight of the ranking of the result.
Definition: weightedDocument.hpp:37