/[MITgcm]/mitgcm.org/devel/buildweb/pkg/swish-e/perl/SWISHE.xs
ViewVC logotype

Contents of /mitgcm.org/devel/buildweb/pkg/swish-e/perl/SWISHE.xs

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Fri Sep 20 19:47:30 2002 UTC (22 years, 10 months ago) by adcroft
Branch: Import, MAIN
CVS Tags: baseline, HEAD
Changes since 1.1: +0 -0 lines
Error occurred while calculating annotation data.
Importing web-site building process.

1 #ifdef __cplusplus
2 extern "C" {
3 #endif
4 #include "EXTERN.h"
5 #include "perl.h"
6 #include "XSUB.h"
7 #ifdef __cplusplus
8 }
9 #endif
10
11 #include "../src/swish.h"
12 #include "../src/stemmer.h"
13 #include "../src/merge.h"
14 #include "../src/docprop.h"
15 #include "../src/mem.h"
16 #include "../src/search.h"
17 #include "../src/error.h"
18
19 MODULE = SWISHE PACKAGE = SWISHE
20 PROTOTYPES: DISABLE
21
22 void *
23 SwishOpen(IndexFiles)
24 char *IndexFiles
25 CODE:
26 RETVAL = (void *)SwishOpen(IndexFiles);
27 OUTPUT:
28 RETVAL
29
30
31 void
32 SwishClose(handle)
33 void *handle
34 CODE:
35 SwishClose(handle);
36
37 void
38 MemSummary()
39 CODE:
40 Mem_Summary("At end of program", 1);
41
42 int
43 SwishSearch(handle,words,structure,properties,sortspec)
44 void *handle
45 char *words
46 int structure
47 char *properties
48 char *sortspec
49 CODE:
50 RETVAL = SwishSearch(handle,words,structure,properties,sortspec);
51 OUTPUT:
52 RETVAL
53
54 void
55 SwishNext(handle)
56 void *handle
57 PREINIT:
58 RESULT *result;
59 int i;
60 int numPropertiesToDisplay;
61 int *metaIDs;
62 PropValue *pv;
63 SWISH *sw;
64
65
66 PPCODE:
67 result = (RESULT *)SwishNext(handle);
68
69 if(result)
70 {
71 sw = (SWISH *) handle;
72
73 numPropertiesToDisplay = sw->Search->numPropertiesToDisplay
74 ? sw->Search->numPropertiesToDisplay
75 : 0;
76
77
78 PUSHMARK(SP);
79
80 if ( (pv = getResultPropValue( sw, result, AUTOPROPERTY_RESULT_RANK, 0)) )
81 {
82 XPUSHs(sv_2mortal(newSViv(pv->value.v_int)));
83 freeResultPropValue(pv);
84 }
85 else
86 XPUSHs(&PL_sv_undef);
87
88
89
90 if ( (pv = getResultPropValue( sw, result, AUTOPROPERTY_DOCPATH, 0)) )
91 {
92 XPUSHs(sv_2mortal(newSVpv(pv->value.v_str,0)));
93 freeResultPropValue(pv);
94 }
95 else
96 XPUSHs(&PL_sv_undef);
97
98
99 if ( (pv = getResultPropValue( sw, result, AUTOPROPERTY_TITLE, 0)) )
100 {
101 XPUSHs(sv_2mortal(newSVpv(pv->value.v_str,0)));
102 freeResultPropValue(pv);
103 }
104 else
105 XPUSHs(&PL_sv_undef);
106
107 if ( (pv = getResultPropValue( sw, result, AUTOPROPERTY_DOCSIZE, 0)) )
108 {
109 XPUSHs(sv_2mortal(newSViv(pv->value.v_int)));
110 freeResultPropValue(pv);
111 }
112 else
113 XPUSHs(&PL_sv_undef);
114
115
116
117 metaIDs = result->indexf->propIDToDisplay;
118
119 for( i=0; i < numPropertiesToDisplay; i++ )
120 {
121 if ( !(pv = getResultPropValue( sw, result, NULL, metaIDs[i])) )
122 {
123 XPUSHs(&PL_sv_undef);
124 continue;
125 }
126
127 switch (pv->datatype)
128 {
129 case PROP_INTEGER:
130 XPUSHs(sv_2mortal(newSViv(pv->value.v_int)));
131 break;
132
133 case PROP_ULONG:
134 XPUSHs(sv_2mortal(newSViv(pv->value.v_ulong)));
135 break;
136
137 case PROP_STRING:
138 XPUSHs(sv_2mortal(newSVpv(pv->value.v_str,0)));
139 break;
140
141 /* Let perl format the data, if needed */
142 case PROP_DATE:
143 XPUSHs(sv_2mortal(newSViv(pv->value.v_date)));
144 break;
145
146 default:
147 XPUSHs(&PL_sv_undef);
148 break;
149 }
150
151 freeResultPropValue(pv);
152 }
153 PUTBACK;
154
155 // SwishClose or SwishSearch (which calls SwishResetSearch) should free this
156 // so is optional, but this just frees the memory earlier
157 freefileinfo(&result->fi);
158 }
159
160
161 void
162 SetLimitParameter(handle,propertyname,low,hi)
163 void *handle;
164 char *propertyname;
165 char *low;
166 char *hi;
167 CODE:
168 SetLimitParameter((SWISH *)handle,propertyname,low,hi);
169
170
171 void
172 ClearLimitParameter(handle)
173 void *handle;
174 CODE:
175 ClearLimitParameter( (SWISH *)handle );
176
177
178
179 int
180 SwishSeek(handle,number)
181 void *handle
182 int number
183 CODE:
184 RETVAL = SwishSeek(handle,number);
185 OUTPUT:
186 RETVAL
187
188 int
189 SwishError(handle)
190 void *handle
191 CODE:
192 RETVAL = SwishError(handle);
193 OUTPUT:
194 RETVAL
195
196 char *
197 SwishHeaderParameter(handle,parameter_name)
198 void *handle
199 char *parameter_name
200 PREINIT:
201 IndexFILE *indexlist;
202 char *value;
203 PPCODE:
204 indexlist=((SWISH *)handle)->indexlist;
205 PUSHMARK(SP);
206 while(indexlist)
207 {
208 value = (char *)SwishHeaderParameter(indexlist,parameter_name);
209 XPUSHs(sv_2mortal(newSVpv(value,0)));
210 indexlist=indexlist->next;
211 }
212 PUTBACK;
213
214
215 void
216 SwishStopWords(handle, filename)
217 void *handle
218 char *filename
219 PREINIT:
220 int NumStopWords;
221 int i;
222 char **StopWords;
223 PPCODE:
224 StopWords=(char **)SwishStopWords(handle,filename,&NumStopWords);
225 PUSHMARK(SP);
226 for(i=0;i<NumStopWords;i++)
227 {
228 XPUSHs(sv_2mortal(newSVpv(StopWords[i],0)));
229 }
230 PUTBACK;
231
232 void
233 SwishWords(handle, filename, c)
234 void *handle
235 char *filename
236 char c
237 PREINIT:
238 char *Words,*tmp;
239 int c2;
240 PPCODE:
241 PUSHMARK(SP);
242 if(c=='*')
243 {
244 for(c2=1;c2<256;c2++)
245 {
246 Words=(char *)SwishWords(handle,filename,(unsigned char)c2);
247 for(tmp=Words;tmp && tmp[0];tmp+=strlen(tmp)+1)
248 {
249 XPUSHs(sv_2mortal(newSVpv(tmp,0)));
250 }
251 }
252 } else {
253 Words=(char *)SwishWords(handle,filename,c);
254 for(tmp=Words;tmp && tmp[0];tmp+=strlen(tmp)+1)
255 {
256 XPUSHs(sv_2mortal(newSVpv(tmp,0)));
257 }
258 }
259 PUTBACK;
260
261
262 SV *
263 SwishStem(word)
264 char *word
265 PREINIT:
266 char *newword;
267 int length;
268 CODE:
269 /* default to undefined */
270 ST(0) = sv_newmortal();
271
272 length = strlen( word ) + 100;
273 newword = (char *)emalloc( length+1 ); /* leak! */
274 strcpy( newword, word );
275
276 /* set return value only if stem returns OK */
277 if ( Stem(&newword, &length) == STEM_OK )
278 sv_setpv( ST(0), newword );
279 efree( newword );
280
281
282 char *
283 SwishErrorString(handle)
284 void *handle;
285 PREINIT:
286 char *value;
287 PPCODE:
288 PUSHMARK(SP);
289 value = (char *)SwishErrorString((SWISH *)handle);
290 XPUSHs(sv_2mortal(newSVpv(value,0)));
291 PUTBACK;
292
293 SV *
294 SwishHeaders(handle)
295 void *handle;
296 CODE:
297 AV *headers;
298 HV *indexheader;
299 SWISH *sw = (SWISH *)handle;
300 IndexFILE *indexf;
301
302 headers = newAV();
303 indexf = sw->indexlist;
304 while(indexf)
305 {
306 indexheader = newHV();
307 hv_store(indexheader,"IndexFile",9, newSVpv(indexf->line,0),0);
308 hv_store(indexheader,"WordCharacters",14,newSVpv(indexf->header.wordchars,0),0);
309 hv_store(indexheader,"BeginCharacters",15,newSVpv(indexf->header.beginchars,0),0);
310 hv_store(indexheader,"EndCharacters",13,newSVpv(indexf->header.endchars,0),0);
311 hv_store(indexheader,"IgnoreLastChar",14,newSVpv(indexf->header.ignorelastchar,0),0);
312 hv_store(indexheader,"IgnoreFirstChar",15,newSVpv(indexf->header.ignorefirstchar,0),0);
313 hv_store(indexheader,"IndexName",9,newSVpv(indexf->header.indexn,0),0);
314 hv_store(indexheader,"IndexDescription",16,newSVpv(indexf->header.indexd,0),0);
315 hv_store(indexheader,"IndexPointer",12,newSVpv(indexf->header.indexp,0),0);
316 hv_store(indexheader,"IndexAdmin",10,newSVpv(indexf->header.indexa,0),0);
317
318 hv_store(indexheader,"UseStemming",11,newSViv(indexf->header.fuzzy_mode == FUZZY_STEMMING ? 1 : 0 ),0);
319 hv_store(indexheader,"UseSoundex",10,newSViv(indexf->header.fuzzy_mode == FUZZY_SOUNDEX ? 1 : 0),0);
320 hv_store(indexheader,"FuzzyIndexingMode",17,newSVpv(fuzzy_mode_to_string(indexf->header.fuzzy_mode),0),0);
321
322 hv_store(indexheader,"TotalWords",10,newSViv(indexf->header.totalwords),0);
323 hv_store(indexheader,"TotalFiles",10,newSViv(indexf->header.totalfiles),0);
324
325 av_push(headers,newRV_noinc((SV *)indexheader));
326 indexf = indexf->next;
327 }
328 RETVAL = newRV_noinc((SV *) headers);
329 OUTPUT:
330 RETVAL

  ViewVC Help
Powered by ViewVC 1.1.22