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 "DtSR_SearchEngine.hh"
28 #include "DtSR_SearchResultsEntry.hh"
29 #include "DtSR_SearchResults.hh"
31 DtSR_SearchResults::DtSR_SearchResults
32 (UAS_Pointer<UAS_String> query,
33 UAS_Pointer<UAS_String> scope_name,
34 UAS_Pointer<UAS_List<UAS_SearchResultsEntry> > res,
36 UAS_Pointer<DtSR_Stems> stems,
37 UAS_SearchZones zones, int stype)
38 : UAS_SearchResults(query, scope_name, res, ndocs), f_zones(zones),
41 f_stems_list.insert_item(stems);
43 UAS_List<UAS_SearchResultsEntry>& list =
44 *(UAS_List<UAS_SearchResultsEntry>*)res;
46 for (int i = 0; i < list.length(); i++) {
48 UAS_Pointer<UAS_SearchResultsEntry> crude_ptr = list[i];
49 UAS_SearchResultsEntry &cptr2 = *crude_ptr;
50 UAS_Pointer<DtSR_SearchResults> uas_this = this;
51 ((DtSR_SearchResultsEntry *)&cptr2)->search_result(uas_this);
57 DtSR_SearchResults::sort(UAS_Pointer<UAS_List<UAS_SearchResultsEntry> > res)
59 UAS_List<UAS_SearchResultsEntry>& Ref_list =
60 *(UAS_List<UAS_SearchResultsEntry>*)res;
62 unsigned int list_length = Ref_list.length();
63 for (int i = 0; i < list_length; i++) {
64 for (int j = i+1; j < list_length; j++) {
67 // this line does nothing, but if you remove it
68 // this code will not compile on novell. go figure. rCs
70 UAS_Pointer<UAS_SearchResultsEntry> reflisti = Ref_list[i];
73 if (Ref_list[i]->relevance() < Ref_list[j]->relevance()) {
74 UAS_Pointer<UAS_SearchResultsEntry> temp = Ref_list[i];
75 Ref_list[i] = Ref_list[j];
82 UAS_Pointer<UAS_List<UAS_SearchResultsEntry> >
83 DtSR_SearchResults::create_results(int index, int nres)
86 if (nres == 0 || index >= f_results.length())
90 if ((n = index + nres - f_results.length()) > 0)
93 UAS_Pointer<UAS_List<UAS_SearchResultsEntry> >
94 uas_res = new UAS_List<UAS_SearchResultsEntry>();
96 for (int i = index; i < nres; i++)
97 uas_res->insert_item(f_results[i]);
103 DtSR_SearchResults::merge(UAS_Pointer<DtSR_SearchResults> & res)
105 if (res == (const int)NULL || res->f_ndocs == 0) // nothing to merge
110 if (f_ndocs == 0) { // none is there, just copy all of them
112 for (i = 0; i < res->f_ndocs; i++) {
114 f_results.insert_item(res->f_results[i]);
116 UAS_Pointer<UAS_SearchResultsEntry> crude_ptr = res->f_results[i];
117 UAS_SearchResultsEntry &cptr2 = *crude_ptr;
118 UAS_Pointer<DtSR_SearchResults> uas_this = this;
120 ((DtSR_SearchResultsEntry*)&cptr2)->search_result(uas_this);
124 f_ndocs = res->f_ndocs;
125 for (i = 0; i < res->f_stems_list.length(); i++) {
126 f_stems_list.insert_item(res->f_stems_list[i]);
134 UAS_Pointer<DtSR_SearchResults> uas_this = this;
138 for (i = 0; i < res->f_ndocs; i++, ndocs++) {
140 if (! (position < ndocs))
143 for (int j = position; j < ndocs; j++) {
144 if (f_results[j]->relevance() > res->f_results[i]->relevance())
147 f_results.insert_item(res->f_results[i], j);
149 fprintf(stderr, "(DEBUG) insert at %d\n", j);
151 UAS_SearchResultsEntry* crude_ptr =
152 (UAS_SearchResultsEntry*)res->f_results[i];
153 ((DtSR_SearchResultsEntry*)crude_ptr)->search_result(uas_this);
156 if (j == ndocs) { // insert at the tail
157 f_results.insert_item(res->f_results[i]);
159 fprintf(stderr, "(DEBUG) insert at the tail\n");
161 UAS_SearchResultsEntry* crude_ptr =
162 (UAS_SearchResultsEntry*)res->f_results[i];
163 ((DtSR_SearchResultsEntry*)crude_ptr)->search_result(uas_this);
167 for (;i < res->f_ndocs; i++) {
169 fprintf(stderr, "(DEBUG) append the remaining list\n");
171 f_results.insert_item(res->f_results[i]);
172 UAS_SearchResultsEntry* crude_ptr =
173 (UAS_SearchResultsEntry*)res->f_results[i];
174 ((DtSR_SearchResultsEntry*)crude_ptr)->search_result(uas_this);
179 for (i = 0; i < res->f_stems_list.length(); i++) {
180 f_stems_list.insert_item(res->f_stems_list[i]);
183 f_ndocs += res->f_ndocs;
187 UAS_Pointer<DtSR_Stems>
188 DtSR_SearchResults::stems(int dbn)
190 int db_count = DtSR_SearchEngine::search_engine().db_count();
192 if (dbn < 0 || dbn >= db_count)
196 for (i = 0; i < f_stems_list.length(); i++) {
197 if (f_stems_list[i]->dbn() == dbn)
200 if (i == f_stems_list.length()) // not found
203 return f_stems_list[i];
207 DtSR_SearchResults::unreference()
211 UAS_Base::unreference();