xref: /aoo41x/main/xmlhelp/source/cxxhelp/inc/qe/Query.hxx (revision 7b6bd0c4)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _XMLSEARCH_QE_QUERY_HXX_
24 #define _XMLSEARCH_QE_QUERY_HXX_
25 
26 #include <sal/types.h>
27 #include <rtl/memory.h>
28 #include <rtl/ustring.hxx>
29 #include <vector>
30 
31 
32 namespace xmlsearch {
33 
34 	namespace qe {
35 
36 		class Search;
37 		class RoleFiller;
38 
39 		class QueryHit
40 		{
41 		public:
42 
QueryHit(sal_Int32 nColumns,double penalty,sal_Int32 doc,sal_Int32 begin,sal_Int32 end)43 			QueryHit( sal_Int32 nColumns,double penalty,sal_Int32 doc,sal_Int32 begin,sal_Int32 end )
44 				: doc_( doc ),
45 				  begin_( begin ),
46 				  end_( end ),
47   				  matchesL_( 2*nColumns ),
48   				  matches_( new sal_Int32[ 2*nColumns ] ),
49                   penalty_( penalty )
50 			{
51 				rtl_zeroMemory( matches_,sizeof( sal_Int32 ) * matchesL_ );
52 			}
53 
~QueryHit()54 			~QueryHit() { delete[] matches_; }
55 
getDocument() const56 			sal_Int32 getDocument() const { return doc_; }
57 
countOfMatches() const58 			sal_Int32 countOfMatches() const { return matchesL_; }
59 
getBegin() const60 			sal_Int32 getBegin() const { return begin_; }
61 
getEnd() const62 			sal_Int32 getEnd() const { return end_; }
63 
getPenalty() const64 			double getPenalty() const { return penalty_; }
65 
betterThan(const QueryHit * o)66 			bool betterThan( const QueryHit* o )
67 			{
68 				if( penalty_ != o->penalty_ )
69 					return penalty_ < o->penalty_;
70 				else if( begin_ != o->begin_ )
71 					return begin_ < o->begin_;
72 				else if( end_ != o->end_ )
73 					return end_ < o->end_;
74 				else
75 					return false;
76 			}
77 
worseThan(const QueryHit * o)78 			bool worseThan( const QueryHit* o )
79 			{
80 				if( penalty_ != o->penalty_ )
81 					return penalty_ > o->penalty_;
82 				else if( begin_ != o->begin_ )
83 					return begin_ > o->begin_;
84 				else if( end_ != o->end_ )
85 					return end_ > o->end_;
86 				else
87 					return false;
88 			}
89 
worseThan(double penalty,sal_Int32 begin,sal_Int32 end)90 			bool worseThan( double penalty,sal_Int32 begin,sal_Int32 end )
91 			{
92 				if( penalty_ != penalty )
93 					return penalty_ > penalty;
94 				else if( begin_ != begin )
95 					return begin_ > begin;
96 				else if( end_ != end )
97 					return end_ > end;
98 				else
99 					return false;
100 			}
101 
compareTo(const QueryHit * o) const102 			bool compareTo( const QueryHit* o ) const
103 			{
104 				if( penalty_ != o->penalty_ )
105 					return penalty_ < o->penalty_;
106 				else if( begin_ != o->begin_ )
107 					return begin_ < o->begin_;
108 				else if( end_ != o->end_ )
109 					return end_ < o->end_;
110 				else
111 					return false;
112 			}
113 
114 
115 		private:
116 
117 			sal_Int32    doc_,begin_,end_;
118 
119   			sal_Int32    matchesL_;
120   			sal_Int32    *matches_;    // ...concept, word number, ...
121 
122 			double penalty_;
123 
124 		}; // end class QueryHit
125 
126 
127 
128 		class QueryHitData
129 		{
130 		public:
131 
QueryHitData(double penalty,const rtl::OUString & document,sal_Int32 termsL,rtl::OUString * terms)132 			QueryHitData( double penalty,const rtl::OUString& document,sal_Int32 termsL, rtl::OUString* terms )
133 				: penalty_( penalty ),
134 				  document_( document ),
135 				  termsL_( termsL ),
136 				  terms_( terms )      { }
137 
~QueryHitData()138 			~QueryHitData() { delete[] terms_; }
139 
getDocument() const140 			rtl::OUString getDocument() const { return document_; }
141 
getPenalty() const142 			double getPenalty() const { return penalty_; }
143 
144 
145 		private:
146 
147 			double        penalty_;
148 
149 			const rtl::OUString document_;
150 
151 			sal_Int32      termsL_;
152 			rtl::OUString* terms_;
153 
154 		};  // end class QueryHitData
155 
156 
157 		class PrefixTranslator
158 		{
159 		public:
160 
makePrefixTranslator(const rtl::OUString *,sal_Int32)161 			static PrefixTranslator* makePrefixTranslator( const rtl::OUString*,sal_Int32 )
162 			{
163 				return 0;
164 			}
165 		};
166 	}
167 
168 }
169 
170 
171 #endif
172