1
/*------------------------------------------------------------------------------
2
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
4
* Distributable under the terms of either the Apache License (Version 2.0) or
5
* the GNU Lesser General Public License, as specified in the COPYING file.
6
------------------------------------------------------------------------------*/
7
#ifndef _lucene_search_Explanation
8
#define _lucene_search_Explanation
10
#include "CLucene/util/VoidList.h"
14
#define LUCENE_SEARCH_EXPLANATION_DESC_LEN 200
16
/** Expert: Describes the score computation for document and query. */
17
class CLUCENE_EXPORT Explanation {
19
float_t value; // the value of this node
20
TCHAR description[LUCENE_SEARCH_EXPLANATION_DESC_LEN]; // what it represents
21
CL_NS(util)::CLArrayList<Explanation*,
22
CL_NS(util)::Deletor::Object<Explanation> >* details; // sub-explanations
26
Explanation(float_t _value, const TCHAR* _description);
27
virtual ~Explanation();
30
* Indicates whether or not this Explanation models a good match.
33
* By default, an Explanation represents a "match" if the value is positive.
37
virtual bool isMatch() const;
39
/** The value assigned to this explanation node. */
40
float_t getValue() const;
41
/** Sets the value assigned to this explanation node. */
42
void setValue(const float_t value);
44
/** A description of this explanation node. */
45
const TCHAR* getDescription() const; ///<returns reference
46
/** Sets the description of this explanation node. */
47
void setDescription(const TCHAR* description);
50
* A short one line summary which should contain all high level
51
* information about this Explanation, without the "Details"
53
virtual TCHAR* getSummary();
56
Explanation(const Explanation& copy);
57
void set(const Explanation& other);
58
virtual Explanation* clone() const;
60
/** The sub-nodes of this explanation node.
61
* @param ret this array of Explanations should be getDetailsLength()+1 in size.
62
* The array will be null terminated.
64
void getDetails(Explanation** ret);
65
size_t getDetailsLength() const;
67
/** Watch out: no NULL reference check is made! Make sure i exists by not calling this function
68
without calling getDetailsLength() first!
70
Explanation* getDetail(const size_t i);
72
/** Adds a sub-node to this explanation node. */
73
void addDetail(Explanation* detail);
75
/** Render an explanation as text. */
77
TCHAR* toString(const int32_t depth);
79
/** Render an explanation as HTML. */
83
class CLUCENE_EXPORT ComplexExplanation : public Explanation {
88
ComplexExplanation(const ComplexExplanation& copy);
89
ComplexExplanation(const bool _match, const float_t _value, const TCHAR* _description);
90
virtual ~ComplexExplanation();
93
* The match status of this explanation node.
94
* @return May be null if match status is unknown
96
bool getMatch() const;
98
* Sets the match status assigned to this explanation node.
99
* @param match May be null if match status is unknown
101
void setMatch(const bool _match);
103
* Indicates wether or not this Explanation models a good match.
106
* If the match statis is explicitly set (ie: not null) this method
107
* uses it; otherwise it defers to the superclass.
111
bool isMatch() const;
113
Explanation* clone() const;