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 libraries 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++) {
67 if (Ref_list[i]->relevance() < Ref_list[j]->relevance()) {
68 UAS_Pointer<UAS_SearchResultsEntry> temp = Ref_list[i];
69 Ref_list[i] = Ref_list[j];
76 UAS_Pointer<UAS_List<UAS_SearchResultsEntry> >
77 DtSR_SearchResults::create_results(int index, int nres)
80 if (nres == 0 || index >= (int) f_results.length())
84 if ((n = index + nres - f_results.length()) > 0)
87 UAS_Pointer<UAS_List<UAS_SearchResultsEntry> >
88 uas_res = new UAS_List<UAS_SearchResultsEntry>();
90 for (int i = index; i < nres; i++)
91 uas_res->insert_item(f_results[i]);
97 DtSR_SearchResults::merge(UAS_Pointer<DtSR_SearchResults> & res)
99 if (res == (const int)0 || res->f_ndocs == 0) // nothing to merge
104 if (f_ndocs == 0) { // none is there, just copy all of them
106 for (i = 0; i < res->f_ndocs; i++) {
108 f_results.insert_item(res->f_results[i]);
110 UAS_Pointer<UAS_SearchResultsEntry> crude_ptr = res->f_results[i];
111 UAS_SearchResultsEntry &cptr2 = *crude_ptr;
112 UAS_Pointer<DtSR_SearchResults> uas_this = this;
114 ((DtSR_SearchResultsEntry*)&cptr2)->search_result(uas_this);
118 f_ndocs = res->f_ndocs;
119 for (i = 0; i < (int) res->f_stems_list.length(); i++) {
120 f_stems_list.insert_item(res->f_stems_list[i]);
128 UAS_Pointer<DtSR_SearchResults> uas_this = this;
132 for (i = 0; i < res->f_ndocs; i++, ndocs++) {
134 if (! (position < ndocs))
138 for (j = position; j < ndocs; j++) {
139 if (f_results[j]->relevance() > res->f_results[i]->relevance())
142 f_results.insert_item(res->f_results[i], j);
144 fprintf(stderr, "(DEBUG) insert at %d\n", j);
146 UAS_SearchResultsEntry* crude_ptr =
147 (UAS_SearchResultsEntry*)res->f_results[i];
148 ((DtSR_SearchResultsEntry*)crude_ptr)->search_result(uas_this);
151 if (j == ndocs) { // insert at the tail
152 f_results.insert_item(res->f_results[i]);
154 fprintf(stderr, "(DEBUG) insert at the tail\n");
156 UAS_SearchResultsEntry* crude_ptr =
157 (UAS_SearchResultsEntry*)res->f_results[i];
158 ((DtSR_SearchResultsEntry*)crude_ptr)->search_result(uas_this);
162 for (;i < res->f_ndocs; i++) {
164 fprintf(stderr, "(DEBUG) append the remaining list\n");
166 f_results.insert_item(res->f_results[i]);
167 UAS_SearchResultsEntry* crude_ptr =
168 (UAS_SearchResultsEntry*)res->f_results[i];
169 ((DtSR_SearchResultsEntry*)crude_ptr)->search_result(uas_this);
174 for (i = 0; i < (int) res->f_stems_list.length(); i++) {
175 f_stems_list.insert_item(res->f_stems_list[i]);
178 f_ndocs += res->f_ndocs;
182 UAS_Pointer<DtSR_Stems>
183 DtSR_SearchResults::stems(int dbn)
185 int db_count = DtSR_SearchEngine::search_engine().db_count();
187 if (dbn < 0 || dbn >= db_count)
191 for (i = 0; i < f_stems_list.length(); i++) {
192 if (f_stems_list[i]->dbn() == dbn)
195 if (i == f_stems_list.length()) // not found
198 return f_stems_list[i];
202 DtSR_SearchResults::unreference()
206 UAS_Base::unreference();