xref: /aoo41x/main/xmlhelp/source/cxxhelp/inc/qe/Query.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _XMLSEARCH_QE_QUERY_HXX_
28 #define _XMLSEARCH_QE_QUERY_HXX_
29 
30 #include <sal/types.h>
31 #include <rtl/memory.h>
32 #include <rtl/ustring.hxx>
33 #include <vector>
34 
35 
36 namespace xmlsearch {
37 
38 	namespace qe {
39 
40 		class Search;
41 		class RoleFiller;
42 
43 		class QueryHit
44 		{
45 		public:
46 
47 			QueryHit( sal_Int32 nColumns,double penalty,sal_Int32 doc,sal_Int32 begin,sal_Int32 end )
48 				: doc_( doc ),
49 				  begin_( begin ),
50 				  end_( end ),
51   				  matchesL_( 2*nColumns ),
52   				  matches_( new sal_Int32[ 2*nColumns ] ),
53                   penalty_( penalty )
54 			{
55 				rtl_zeroMemory( matches_,sizeof( sal_Int32 ) * matchesL_ );
56 			}
57 
58 			~QueryHit() { delete[] matches_; }
59 
60 			sal_Int32 getDocument() const { return doc_; }
61 
62 			sal_Int32 countOfMatches() const { return matchesL_; }
63 
64 			sal_Int32 getBegin() const { return begin_; }
65 
66 			sal_Int32 getEnd() const { return end_; }
67 
68 			double getPenalty() const { return penalty_; }
69 
70 			bool betterThan( const QueryHit* o )
71 			{
72 				if( penalty_ != o->penalty_ )
73 					return penalty_ < o->penalty_;
74 				else if( begin_ != o->begin_ )
75 					return begin_ < o->begin_;
76 				else if( end_ != o->end_ )
77 					return end_ < o->end_;
78 				else
79 					return false;
80 			}
81 
82 			bool worseThan( const QueryHit* o )
83 			{
84 				if( penalty_ != o->penalty_ )
85 					return penalty_ > o->penalty_;
86 				else if( begin_ != o->begin_ )
87 					return begin_ > o->begin_;
88 				else if( end_ != o->end_ )
89 					return end_ > o->end_;
90 				else
91 					return false;
92 			}
93 
94 			bool worseThan( double penalty,sal_Int32 begin,sal_Int32 end )
95 			{
96 				if( penalty_ != penalty )
97 					return penalty_ > penalty;
98 				else if( begin_ != begin )
99 					return begin_ > begin;
100 				else if( end_ != end )
101 					return end_ > end;
102 				else
103 					return false;
104 			}
105 
106 			bool compareTo( const QueryHit* o ) const
107 			{
108 				if( penalty_ != o->penalty_ )
109 					return penalty_ < o->penalty_;
110 				else if( begin_ != o->begin_ )
111 					return begin_ < o->begin_;
112 				else if( end_ != o->end_ )
113 					return end_ < o->end_;
114 				else
115 					return false;
116 			}
117 
118 
119 		private:
120 
121 			sal_Int32    doc_,begin_,end_;
122 
123   			sal_Int32    matchesL_;
124   			sal_Int32    *matches_;    // ...concept, word number, ...
125 
126 			double penalty_;
127 
128 		}; // end class QueryHit
129 
130 
131 
132 		class QueryHitData
133 		{
134 		public:
135 
136 			QueryHitData( double penalty,const rtl::OUString& document,sal_Int32 termsL, rtl::OUString* terms )
137 				: penalty_( penalty ),
138 				  document_( document ),
139 				  termsL_( termsL ),
140 				  terms_( terms )      { }
141 
142 			~QueryHitData() { delete[] terms_; }
143 
144 			rtl::OUString getDocument() const { return document_; }
145 
146 			double getPenalty() const { return penalty_; }
147 
148 
149 		private:
150 
151 			double        penalty_;
152 
153 			const rtl::OUString document_;
154 
155 			sal_Int32      termsL_;
156 			rtl::OUString* terms_;
157 
158 		};  // end class QueryHitData
159 
160 
161 		class PrefixTranslator
162 		{
163 		public:
164 
165 			static PrefixTranslator* makePrefixTranslator( const rtl::OUString*,sal_Int32 )
166 			{
167 				return 0;
168 			}
169 		};
170 	}
171 
172 }
173 
174 
175 #endif
176