2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 // $XConsortium: DtSR_SearchResults.C /main/9 1996/10/16 14:23:04 cde-hal $
24 /* Copyright (c) 1995,1996 FUJITSU LIMITED */
25 /* All Rights Reserved */
27 #include "UAS_Exceptions.hh"
28 #include "DtSR_SearchEngine.hh"
29 #include "DtSR_SearchResultsEntry.hh"
30 #include "DtSR_SearchResults.hh"
32 DtSR_SearchResults::DtSR_SearchResults
33 (UAS_Pointer<UAS_String> query,
34 UAS_Pointer<UAS_String> scope_name,
35 UAS_Pointer<UAS_List<UAS_SearchResultsEntry> > res,
37 UAS_Pointer<DtSR_Stems> stems,
38 UAS_SearchZones zones, int stype)
39 : UAS_SearchResults(query, scope_name, res, ndocs), f_zones(zones),
42 f_stems_list.insert_item(stems);
44 UAS_List<UAS_SearchResultsEntry>& list =
45 *(UAS_List<UAS_SearchResultsEntry>*)res;
47 for (unsigned int i = 0; i < list.length(); i++) {
49 UAS_Pointer<UAS_SearchResultsEntry> crude_ptr = list[i];
50 UAS_SearchResultsEntry &cptr2 = *crude_ptr;
51 UAS_Pointer<DtSR_SearchResults> uas_this = this;
52 ((DtSR_SearchResultsEntry *)&cptr2)->search_result(uas_this);
58 DtSR_SearchResults::sort(UAS_Pointer<UAS_List<UAS_SearchResultsEntry> > res)
60 UAS_List<UAS_SearchResultsEntry>& Ref_list =
61 *(UAS_List<UAS_SearchResultsEntry>*)res;
63 unsigned int list_length = Ref_list.length();
64 for (unsigned int i = 0; i < list_length; i++) {
65 for (unsigned int j = i+1; j < list_length; j++) {
68 // this line does nothing, but if you remove it
69 // this code will not compile on novell. go figure. rCs
71 UAS_Pointer<UAS_SearchResultsEntry> reflisti = Ref_list[i];
74 if (Ref_list[i]->relevance() < Ref_list[j]->relevance()) {
75 UAS_Pointer<UAS_SearchResultsEntry> temp = Ref_list[i];
76 Ref_list[i] = Ref_list[j];
83 UAS_Pointer<UAS_List<UAS_SearchResultsEntry> >
84 DtSR_SearchResults::create_results(int index, int nres)
87 if (nres == 0 || index >= (int) f_results.length())
91 if ((n = index + nres - f_results.length()) > 0)
94 UAS_Pointer<UAS_List<UAS_SearchResultsEntry> >
95 uas_res = new UAS_List<UAS_SearchResultsEntry>();
97 for (int i = index; i < nres; i++)
98 uas_res->insert_item(f_results[i]);
104 DtSR_SearchResults::merge(UAS_Pointer<DtSR_SearchResults> & res)
106 if (res == (const int)0 || res->f_ndocs == 0) // nothing to merge
111 if (f_ndocs == 0) { // none is there, just copy all of them
113 for (i = 0; i < res->f_ndocs; i++) {
115 f_results.insert_item(res->f_results[i]);
117 UAS_Pointer<UAS_SearchResultsEntry> crude_ptr = res->f_results[i];
118 UAS_SearchResultsEntry &cptr2 = *crude_ptr;
119 UAS_Pointer<DtSR_SearchResults> uas_this = this;
121 ((DtSR_SearchResultsEntry*)&cptr2)->search_result(uas_this);
125 f_ndocs = res->f_ndocs;
126 for (i = 0; i < (int) res->f_stems_list.length(); i++) {
127 f_stems_list.insert_item(res->f_stems_list[i]);
135 UAS_Pointer<DtSR_SearchResults> uas_this = this;
139 for (i = 0; i < res->f_ndocs; i++, ndocs++) {
141 if (! (position < ndocs))
145 for (j = position; j < ndocs; j++) {
146 if (f_results[j]->relevance() > res->f_results[i]->relevance())
149 f_results.insert_item(res->f_results[i], j);
151 fprintf(stderr, "(DEBUG) insert at %d\n", j);
153 UAS_SearchResultsEntry* crude_ptr =
154 (UAS_SearchResultsEntry*)res->f_results[i];
155 ((DtSR_SearchResultsEntry*)crude_ptr)->search_result(uas_this);
158 if (j == ndocs) { // insert at the tail
159 f_results.insert_item(res->f_results[i]);
161 fprintf(stderr, "(DEBUG) insert at the tail\n");
163 UAS_SearchResultsEntry* crude_ptr =
164 (UAS_SearchResultsEntry*)res->f_results[i];
165 ((DtSR_SearchResultsEntry*)crude_ptr)->search_result(uas_this);
169 for (;i < res->f_ndocs; i++) {
171 fprintf(stderr, "(DEBUG) append the remaining list\n");
173 f_results.insert_item(res->f_results[i]);
174 UAS_SearchResultsEntry* crude_ptr =
175 (UAS_SearchResultsEntry*)res->f_results[i];
176 ((DtSR_SearchResultsEntry*)crude_ptr)->search_result(uas_this);
181 for (i = 0; i < (int) res->f_stems_list.length(); i++) {
182 f_stems_list.insert_item(res->f_stems_list[i]);
185 f_ndocs += res->f_ndocs;
189 UAS_Pointer<DtSR_Stems>
190 DtSR_SearchResults::stems(int dbn)
192 int db_count = DtSR_SearchEngine::search_engine().db_count();
194 if (dbn < 0 || dbn >= db_count)
198 for (i = 0; i < f_stems_list.length(); i++) {
199 if (f_stems_list[i]->dbn() == dbn)
202 if (i == f_stems_list.length()) // not found
205 return f_stems_list[i];
209 DtSR_SearchResults::unreference()
213 UAS_Base::unreference();