source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java@ 30631

Last change on this file since 30631 was 29558, checked in by kjdon, 9 years ago

work around does_paging, does_chunking. only add in maxdocs, hitsperpage params if the service actually uses them. lucnee/solr, don't use maxdocs any more. I haven't had a chance to clean up the changes, but I need to commit, so there may be extraneous debug statements still here.

File size: 4.8 KB
Line 
1/*
2 * GS2MGPPSearch.java
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18package org.greenstone.gsdl3.service;
19
20
21// Greenstone classes
22import org.greenstone.mgpp.*;
23import org.greenstone.gsdl3.util.*;
24import org.w3c.dom.Element;
25
26import java.util.Vector;
27import java.util.ArrayList;
28import java.util.Collections;
29import org.apache.log4j.*;
30
31/**
32 *
33 * @author Shaoqun Wu
34 */
35
36public class GoogleNgramMGPPSearch
37 extends GS2MGPPSearch {
38 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GoogleNgramMGPPSearch.class.getName());
39
40 protected String default_max_docs = "-1";
41 protected String default_hits_per_page = "30";
42 /** constructor */
43 public GoogleNgramMGPPSearch(){
44 this.does_paging = true;
45 }
46
47 /** configure this service */
48 public boolean configure(Element info, Element extra_info) {
49 if (!super.configure(info, extra_info)){
50 return false;
51 }
52
53 this.default_max_docs = "-1";
54 this.default_hits_per_page = "30";
55 this.does_stem = false;
56 return true;
57 }
58
59 // sort the doc_nums by their frequency
60 protected String [] getDocIDs(Object query_result) {
61 try{
62 Vector docs = ((MGPPQueryResult)query_result).getDocs();
63 //ArrayList docList_past = new ArrayList();
64 //ArrayList docList_future = new ArrayList();
65 //ArrayList docList_present = new ArrayList();
66
67 ArrayList<DocWrapper> docList = new ArrayList<DocWrapper>();
68
69 for (int d = 0; d < docs.size(); d++) {
70 String num = Long.toString((((MGPPDocInfo) docs.elementAt(d)).num_));
71 String doc_id = internalNum2OID(num);
72 DBInfo dbInfo = this.gs_doc_db.getInfo(doc_id);
73 String fre = (String)dbInfo.getInfo("Frequency");
74 String tense = (String)dbInfo.getInfo("Tense");
75
76 if(!fre.equals("")){
77 // if (tense.equals("past")){
78 // docList_past.add(new DocWrapper(num,Integer.parseInt(fre),tense));
79 // }
80 // else{
81 // if (tense.equals("future")){
82 // docList_future.add(new DocWrapper(num,Integer.parseInt(fre),tense));
83 // }
84 // else{
85 // if(tense.equals("present")){
86 // docList_present.add(new DocWrapper(num,Integer.parseInt(fre),tense));
87 // }
88 // }
89 //}
90 docList.add(new DocWrapper(num,Integer.parseInt(fre),tense));
91 }
92
93 }
94
95
96 //Collections.sort(docList_past);
97 //Collections.sort(docList_future);
98 //Collections.sort(docList_present);
99
100 Collections.sort(docList);
101 int i_pa = 0;
102 int i_f = 0;
103 int i_pre = 0;
104
105 //String [] doc_nums = new String [docList_past.size()+docList_future.size()+docList_present.size()];
106 String [] doc_nums = new String [docList.size()];
107 int interval = 10;
108
109 for(int d = 0; d < doc_nums.length; d++){
110
111 // for(;i_pre < docList_present.size() && interval > 0;i_pre++){
112// doc_nums[d] = ((DocWrapper)docList_present.get(i_pre)).num;
113// d++;
114// interval--;
115// }
116
117// interval = 10+interval;
118
119// for(;i_pa < docList_past.size() && interval > 0;i_pa++){
120// doc_nums[d] = ((DocWrapper)docList_past.get(i_pa)).num;
121// d++;
122// interval--;
123// }
124
125
126// interval = 10+interval;
127
128// for(;i_f < docList_future.size() && interval > 0;i_f++){
129// doc_nums[d] = ((DocWrapper)docList_future.get(i_f)).num;
130// d++;
131// interval--;
132// }
133
134// interval = 10;
135
136 doc_nums[d] = docList.get(d).num;
137
138 }
139
140 return doc_nums;
141 }
142 catch(Exception e){
143 e.printStackTrace();
144 }
145
146 return null;
147 }
148
149 static class DocWrapper implements Comparable{
150 public int fre = 0;
151 public String num = "";
152 public String tense = "";
153
154
155 public DocWrapper(String num, int fre, String tense){
156 this.fre = fre;
157 this.num = num;
158 this.tense = tense;
159 }
160
161 public int compareTo(Object o){
162
163 if (!(o instanceof DocWrapper)) return -1;
164 DocWrapper docIn = (DocWrapper)o;
165 if (num.equals(docIn.num)){
166 return 0;
167 }
168
169 if (fre > docIn.fre) return -1;
170 return 1;
171 }
172
173 public boolean equals(Object o){
174 if (!(o instanceof DocWrapper)) return false;
175 DocWrapper docIn = (DocWrapper)o;
176 if (num.equals(docIn.num)){
177 return true;
178 }
179 return false;
180 }
181
182
183 }
184
185
186}
187
188
Note: See TracBrowser for help on using the repository browser.