The R Project SVN R

Rev

Rev 3765 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3765 Rev 5458
1
/*==============================================================================
1
/*==============================================================================
2
 
2
 
3
  Project: Simple JAVA Search Engine for Keyword Search
3
  Project: Simple JAVA Search Engine for Keyword Search
4
  
4
  
5
  JAVA Source file for the class SearchEngine
5
  JAVA Source file for the class SearchEngine
6
  
6
  
7
  COPYRIGHT (C), 1998, Thomas Baier
7
  COPYRIGHT (C), 1998, Thomas Baier
8
 
8
 
9
 *  This program is free software; you can redistribute it and/or modify
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  (at your option) any later version.
12
 *  (at your option) any later version.
13
 *
13
 *
14
 *  This program is distributed in the hope that it will be useful,
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
17
 *  GNU General Public License for more details.
18
 *
18
 *
19
 *  You should have received a copy of the GNU General Public License
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program; if not, write to the Free Software
20
 *  along with this program; if not, write to the Free Software
21
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
21
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
  
22
 
23
  $Source: /scratch/CVS-ARCHIVE/R/doc/html/search/SearchEngine.java,v $
23
  $Source: /scratch/CVS-ARCHIVE/R/doc/html/search/SearchEngine.java,v $
24
  
24
  
25
  $Revision: 1.2 $
25
  $Revision: 1.3 $
26
 
26
 
27
  $Date: 1999/03/04 17:15:18 $
27
  $Date: 1999/08/10 09:56:03 $
28
  
28
  
29
  $Author: leisch $
29
  $Author: ripley $
30
 
30
 
31
==============================================================================*/
31
==============================================================================*/
32
 
32
 
33
 
33
 
34
/* -------------------------------- Imports --------------------------------- */
34
/* -------------------------------- Imports --------------------------------- */
35
 
35
 
36
import java.applet.*;
36
import java.applet.*;
37
import java.awt.*;
37
import java.awt.*;
38
import java.net.*;
38
import java.net.*;
39
import java.io.*;
39
import java.io.*;
40
import java.util.*;
40
import java.util.*;
41
 
41
 
42
 
42
 
43
/*==============================================================================
43
/*==============================================================================
44
                          Interface of class SearchEngine
44
                          Interface of class SearchEngine
45
==============================================================================*/
45
==============================================================================*/
46
 
46
 
47
/*------------------------------------------------------------------------------
47
/*------------------------------------------------------------------------------
48
  CLASS:    SearchEngine
48
  CLASS:    SearchEngine
49
  SUPER:    Applet
49
  SUPER:    Applet
50
  CONF. TO: 
50
  CONF. TO: 
51
  PURPOSE:  
51
  PURPOSE:  
52
  NOTES:    
52
  NOTES:    
53
 
53
 
54
  HISTORY:  98-04-26: created 
54
  HISTORY:  98-04-26: created 
55
            98-05-15: new member for search mode
55
            98-05-15: new member for search mode
56
------------------------------------------------------------------------------*/
56
------------------------------------------------------------------------------*/
57
public class SearchEngine extends Applet
57
public class SearchEngine extends Applet
58
{
58
{
59
  /*============================================================================
59
  /*============================================================================
60
                                Public methods
60
                                Public methods
61
  ============================================================================*/
61
  ============================================================================*/
62
 
62
 
63
  /*----------------------------------------------------------------------------
63
  /*----------------------------------------------------------------------------
64
    INTERFACE: 
64
    INTERFACE: 
65
    PURPOSE:   default constructor
65
    PURPOSE:   default constructor
66
  	      
66
  	      
67
    NOTES:     
67
    NOTES:     
68
  
68
  
69
    PARAMS:    
69
    PARAMS:    
70
    THROWS:    
70
    THROWS:    
71
    RETURNS:   void
71
    RETURNS:   void
72
  
72
  
73
    HISTORY:   98-04-26: created
73
    HISTORY:   98-04-26: created
74
               98-05-03: now reads the index file
74
               98-05-03: now reads the index file
75
	       98-05-15: init new member
75
	       98-05-15: init new member
76
  ----------------------------------------------------------------------------*/
76
  ----------------------------------------------------------------------------*/
77
  public SearchEngine ()
77
  public SearchEngine ()
78
  {
78
  {
79
    iIndexTable = null;
79
    iIndexTable = null;
80
    iSearchTerm = null;
80
    iSearchTerm = null;
81
    iSearchMode = 0;
81
    iSearchMode = 0;
82
 
82
 
83
    Tracer.write ("SearchEngine initializing\n");
83
    Tracer.write ("SearchEngine initializing\n");
84
 
84
 
85
    return;
85
    return;
86
  }
86
  }
87
 
87
 
88
 
88
 
89
  /*----------------------------------------------------------------------------
89
  /*----------------------------------------------------------------------------
90
    INTERFACE: 
90
    INTERFACE: 
91
    PURPOSE:   return general information about the applet
91
    PURPOSE:   return general information about the applet
92
  	       
92
  	       
93
    NOTES:     
93
    NOTES:     
94
  
94
  
95
    PARAMS:    
95
    PARAMS:    
96
    THROWS:    
96
    THROWS:    
97
    RETURNS:   String: the information
97
    RETURNS:   String: the information
98
  
98
  
99
    HISTORY:   98-04-26: created
99
    HISTORY:   98-04-26: created
100
  ----------------------------------------------------------------------------*/
100
  ----------------------------------------------------------------------------*/
101
  public String getAppletInfo ()
101
  public String getAppletInfo ()
102
  {
102
  {
103
    return "Name: SearchEngine\r\n" +
103
    return "Name: SearchEngine\r\n" +
104
      "Author: Thomas Baier\r\n" +
104
      "Author: Thomas Baier\r\n" +
105
      "(C) 1998 Thomas Baier, ALL RIGHTS RESERVED";
105
      "(C) 1998 Thomas Baier, ALL RIGHTS RESERVED";
106
  }
106
  }
107
 
107
 
108
 
108
 
109
  /*----------------------------------------------------------------------------
109
  /*----------------------------------------------------------------------------
110
    INTERFACE: 
110
    INTERFACE: 
111
    PURPOSE:   perform initialization
111
    PURPOSE:   perform initialization
112
  	      
112
  	      
113
    NOTES:     creates the controls
113
    NOTES:     creates the controls
114
  
114
  
115
    PARAMS:    
115
    PARAMS:    
116
    THROWS:    
116
    THROWS:    
117
    RETURNS:   void
117
    RETURNS:   void
118
  
118
  
119
    HISTORY:   98-04-26: created
119
    HISTORY:   98-04-26: created
120
               98-05-03: now a do-nothing
120
               98-05-03: now a do-nothing
121
  ----------------------------------------------------------------------------*/
121
  ----------------------------------------------------------------------------*/
122
  public void init ()
122
  public void init ()
123
  {
123
  {
124
    resize(640, 240);
124
    resize(640, 240);
125
 
125
 
126
    // get the name of the index file
126
    // get the name of the index file
127
    String indexName = getParameter (cIndexKeyword);
127
    String indexName = getParameter (cIndexKeyword);
128
    String searchTerm = getParameter (cSearchKeyword);
128
    String searchTerm = getParameter (cSearchKeyword);
129
 
129
 
130
    Tracer.write ("Index file is \"" + indexName + "\"\n");
130
    Tracer.write ("Index file is \"" + indexName + "\"\n");
131
    Tracer.write ("Search term is \"" + searchTerm + "\"\n");
131
    Tracer.write ("Search term is \"" + searchTerm + "\"\n");
132
 
132
 
133
    // use a default index file if none specified
133
    // use a default index file if none specified
134
    if (indexName == null) {
134
    if (indexName == null) {
135
      indexName = cIndexFile;
135
      indexName = cIndexFile;
136
    }
136
    }
137
 
137
 
138
    iSearchTerm = searchTerm;
138
    iSearchTerm = searchTerm;
139
 
139
 
140
    /*
140
    /*
141
     * examine the URL to get the search term...
141
     * examine the URL to get the search term...
142
     *
142
     *
143
     * if the URL ends with ?SEARCHTERM=xxxxx we know, xxxxx is the search term
143
     * if the URL ends with ?SEARCHTERM=xxxxx we know, xxxxx is the search term
144
     */
144
     */
145
    {
145
    {
146
      URL url = getDocumentBase ();
146
      URL url = getDocumentBase ();
147
      String urlString = url.toString ();
147
      String urlString = url.toString ();
148
      int index = urlString.indexOf ("?" + cSearchKeyword + "=");
148
      int index = urlString.indexOf ("?" + cSearchKeyword + "=");
149
 
149
 
150
      Tracer.write ("URL is \"" + urlString + "\"\n");
150
      Tracer.write ("URL is \"" + urlString + "\"\n");
151
 
151
 
152
      // if found, take the rest as the search string
152
      // if found, take the rest as the search string
153
      if (index >= 0) {
153
      if (index >= 0) {
154
	iSearchTerm =
154
	iSearchTerm =
155
	  urlString.substring (index + 2 + cSearchKeyword.length ());
155
	  urlString.substring (index + 2 + cSearchKeyword.length ());
156
	Tracer.write ("found search term \"" + iSearchTerm + "\" in URL\n");
156
	Tracer.write ("found search term \"" + iSearchTerm + "\" in URL\n");
157
      }
157
      }
158
    }
158
    }
159
 
159
 
160
    readIndexFile (indexName);
160
    readIndexFile (indexName);
161
 
161
 
162
    return;
162
    return;
163
  }
163
  }
164
 
164
 
165
 
165
 
166
  /*----------------------------------------------------------------------------
166
  /*----------------------------------------------------------------------------
167
    INTERFACE: 
167
    INTERFACE: 
168
    PURPOSE:   perform "destructor" code
168
    PURPOSE:   perform "destructor" code
169
  	      
169
  	      
170
    NOTES:     not required here
170
    NOTES:     not required here
171
  
171
  
172
    PARAMS:    
172
    PARAMS:    
173
    THROWS:    
173
    THROWS:    
174
    RETURNS:   void
174
    RETURNS:   void
175
  
175
  
176
    HISTORY:   98-04-26: created
176
    HISTORY:   98-04-26: created
177
  ----------------------------------------------------------------------------*/
177
  ----------------------------------------------------------------------------*/
178
  public void destroy ()
178
  public void destroy ()
179
  {
179
  {
180
    return;
180
    return;
181
  }
181
  }
182
 
182
 
183
 
183
 
184
  /*----------------------------------------------------------------------------
184
  /*----------------------------------------------------------------------------
185
    INTERFACE: 
185
    INTERFACE: 
186
    PURPOSE:   perform painting of the applet
186
    PURPOSE:   perform painting of the applet
187
  	      
187
  	      
188
    NOTES:     not required for our applet, controls do everything
188
    NOTES:     not required for our applet, controls do everything
189
  
189
  
190
    PARAMS:    Graphics g: the graphics context to draw on
190
    PARAMS:    Graphics g: the graphics context to draw on
191
    THROWS:    
191
    THROWS:    
192
    RETURNS:   void
192
    RETURNS:   void
193
  
193
  
194
    HISTORY:   98-04-26: created
194
    HISTORY:   98-04-26: created
195
  ----------------------------------------------------------------------------*/
195
  ----------------------------------------------------------------------------*/
196
  public void paint (Graphics g)
196
  public void paint (Graphics g)
197
  {
197
  {
198
  
198
  
199
    return;
199
    return;
200
  }
200
  }
201
 
201
 
202
 
202
 
203
  /*----------------------------------------------------------------------------
203
  /*----------------------------------------------------------------------------
204
    INTERFACE: 
204
    INTERFACE: 
205
    PURPOSE:   perform startup code everytime visiting the applet
205
    PURPOSE:   perform startup code everytime visiting the applet
206
  	      
206
  	      
207
    NOTES:     
207
    NOTES:     
208
  
208
  
209
    PARAMS:    
209
    PARAMS:    
210
    THROWS:    
210
    THROWS:    
211
    RETURNS:   void
211
    RETURNS:   void
212
  
212
  
213
    HISTORY:   98-04-26: created
213
    HISTORY:   98-04-26: created
214
               98-05-10: start the tracer
214
               98-05-10: start the tracer
215
  ----------------------------------------------------------------------------*/
215
  ----------------------------------------------------------------------------*/
216
  public void start ()
216
  public void start ()
217
  {
217
  {
218
    Tracer.start ();
218
    Tracer.start ();
219
    return;
219
    return;
220
  }
220
  }
221
 
221
 
222
 
222
 
223
  /*----------------------------------------------------------------------------
223
  /*----------------------------------------------------------------------------
224
    INTERFACE: 
224
    INTERFACE: 
225
    PURPOSE:   perform cleanup evertime the applet "loses" the focus
225
    PURPOSE:   perform cleanup evertime the applet "loses" the focus
226
  	      
226
  	      
227
    NOTES:     
227
    NOTES:     
228
  
228
  
229
    PARAMS:    
229
    PARAMS:    
230
    THROWS:    
230
    THROWS:    
231
    RETURNS:   void
231
    RETURNS:   void
232
  
232
  
233
    HISTORY:   98-04-26: created
233
    HISTORY:   98-04-26: created
234
               98-05-10: stop the tracer
234
               98-05-10: stop the tracer
235
  ----------------------------------------------------------------------------*/
235
  ----------------------------------------------------------------------------*/
236
  public void stop ()
236
  public void stop ()
237
  {
237
  {
238
    Tracer.stop ();
238
    Tracer.stop ();
239
    return;
239
    return;
240
  }
240
  }
241
 
241
 
242
 
242
 
243
  /*----------------------------------------------------------------------------
243
  /*----------------------------------------------------------------------------
244
    INTERFACE: 
244
    INTERFACE: 
245
    PURPOSE:   perform the search and return the search results as a string
245
    PURPOSE:   perform the search and return the search results as a string
246
  	      
246
  	      
247
    NOTES:     
247
    NOTES:     
248
  
248
  
249
    PARAMS:    
249
    PARAMS:    
250
    THROWS:    
250
    THROWS:    
251
    RETURNS:   void
251
    RETURNS:   void
252
  
252
  
253
    HISTORY:   98-05-03: created
253
    HISTORY:   98-05-03: created
254
               98-05-08: new format for output
254
               98-05-08: new format for output
255
	       98-05-09: added trace
255
	       98-05-09: added trace
256
	       98-05-10: now a front-end for search()
256
	       98-05-10: now a front-end for search()
257
	       98-05-15: new parameter for search-mode
257
	       98-05-15: new parameter for search-mode
258
  ----------------------------------------------------------------------------*/
258
  ----------------------------------------------------------------------------*/
259
  public String search (String key,boolean searchTitles)
259
  public String search (String key,boolean searchTitles)
260
  {
260
  {
261
    iSearchTerm = key;
261
    iSearchTerm = key;
262
 
262
 
263
    if (searchTitles) {
263
    if (searchTitles) {
264
      iSearchMode = IndexTable.cSearchDescription;
264
      iSearchMode = IndexTable.cSearchDescription;
265
    } else {
265
    } else {
266
      iSearchMode = 0;
266
      iSearchMode = 0;
267
    }
267
    }
268
 
268
 
269
    return internalSearch ();
269
    return internalSearch ();
270
  }
270
  }
271
 
271
 
272
 
272
 
273
  /*----------------------------------------------------------------------------
273
  /*----------------------------------------------------------------------------
274
    INTERFACE: 
274
    INTERFACE: 
275
    PURPOSE:   perform the search (back-end)
275
    PURPOSE:   perform the search (back-end)
276
  	      
276
  	      
277
    NOTES:     
277
    NOTES:     
278
  
278
  
279
    PARAMS:    
279
    PARAMS:    
280
    THROWS:    
280
    THROWS:    
281
    RETURNS:   void
281
    RETURNS:   void
282
  
282
  
283
    HISTORY:   98-05-10: created
283
    HISTORY:   98-05-10: created
284
               98-05-15: forward search-mode
284
               98-05-15: forward search-mode
285
  ----------------------------------------------------------------------------*/
285
  ----------------------------------------------------------------------------*/
286
  public String internalSearch ()
286
  public String internalSearch ()
287
  {
287
  {
288
    Tracer.write ("Search for \"" + iSearchTerm + "\" started");
288
    Tracer.write ("Search for \"" + iSearchTerm + "\" started");
289
 
289
 
290
    Vector foundItems = null;
290
    Vector foundItems = null;
291
 
291
 
292
    if (iSearchTerm != null) {
292
    if (iSearchTerm != null) {
293
      foundItems = iIndexTable.search (iSearchTerm,iSearchMode);
293
      foundItems = iIndexTable.search (iSearchTerm,iSearchMode);
294
    } else {
294
    } else {
295
      foundItems = null;
295
      foundItems = null;
296
    }
296
    }
297
 
297
 
298
    String result = null;
298
    String result = null;
299
 
299
 
300
    // if nothing found, return a special string
300
    // if nothing found, return a special string
301
    if (foundItems == null) {
301
    if (foundItems == null) {
302
      result = "No matches for <b>\"" + 
302
      result = "No matches for <b>\"" + 
303
	iSearchTerm +
303
	iSearchTerm +
304
	"\"</b> have been found!<hr>";
304
	"\"</b> have been found!<hr>";
305
    } else {
305
    } else {
306
      Enumeration cursor = foundItems.elements ();
306
      Enumeration cursor = foundItems.elements ();
307
 
307
 
308
      result =
308
      result =
309
	"The search string was <b>\"" +
309
	"The search string was <b>\"" +
310
	iSearchTerm +
310
	iSearchTerm +
311
	"</b>\"" +
311
	"</b>\"" +
312
	"<hr>" +
312
	"<hr>" +
313
	"<dl>";
313
	"<dl>";
314
 
314
 
315
      while (cursor.hasMoreElements ()) {
315
      while (cursor.hasMoreElements ()) {
316
	IndexEntry entry = (IndexEntry) cursor.nextElement ();
316
	IndexEntry entry = (IndexEntry) cursor.nextElement ();
317
 
317
 
318
	/*
318
	/*
319
	 * the format for every entry is
319
	 * the format for every entry is
320
	 *
320
	 *
321
	 * title
321
	 * title
322
	 *   description
322
	 *   description
323
	 */
323
	 */
324
 
324
 
325
	result +=
325
	result +=
326
	  "<dt><a href=\"" +
326
	  "<dt><a href=\"" +
327
	  entry.getURL () +
327
	  entry.getURL () +
328
	  "\">" +
328
	  "\">" +
329
	  entry.getTitle () +
329
	  entry.getTitle () +
330
	  "</a></dt>\n";
330
	  "</a></dt>\n";
331
	result += "<dd>" + entry.getDescription () + "</dd>\n";
331
	result += "<dd>" + entry.getDescription () + "</dd>\n";
332
      }
332
      }
333
 
333
 
334
      result += "</dl>";
334
      result += "</dl>";
335
    }
335
    }
336
 
336
 
337
    return result;
337
    return result;
338
  }
338
  }
339
 
339
 
340
 
340
 
341
  /*============================================================================
341
  /*============================================================================
342
                              Protected methods
342
                              Protected methods
343
  ============================================================================*/
343
  ============================================================================*/
344
 
344
 
345
  /*============================================================================
345
  /*============================================================================
346
                               Private methods
346
                               Private methods
347
  ============================================================================*/
347
  ============================================================================*/
348
 
348
 
349
  /*----------------------------------------------------------------------------
349
  /*----------------------------------------------------------------------------
350
    INTERFACE: 
350
    INTERFACE: 
351
    PURPOSE:   read the index file
351
    PURPOSE:   read the index file
352
  	      
352
  	      
353
    NOTES:     
353
    NOTES:     
354
  
354
  
355
    PARAMS:    
355
    PARAMS:    
356
    THROWS:    
356
    THROWS:    
357
    RETURNS:   void
357
    RETURNS:   void
358
  
358
  
359
    HISTORY:   98-04-26: created
359
    HISTORY:   98-04-26: created
360
               98-05-08: now use an IndexStream
360
               98-05-08: now use an IndexStream
361
	       98-05-10: also use prefix and suffix, build URL from first key
361
	       98-05-10: also use prefix and suffix, build URL from first key
362
	       98-05-19: add "Alias:" entry to keywords
362
	       98-05-19: add "Alias:" entry to keywords
363
	       98-06-01: bugfix: don't null the variables
363
	       98-06-01: bugfix: don't null the variables
364
  ----------------------------------------------------------------------------*/
364
  ----------------------------------------------------------------------------*/
365
  private void readIndexFile (String idxFile)
365
  private void readIndexFile (String idxFile)
366
  {
366
  {
367
    // create the index table
367
    // create the index table
368
    iIndexTable = new IndexTable ();
368
    iIndexTable = new IndexTable ();
369
 
369
 
370
    URL baseURL = getCodeBase ();
370
    URL baseURL = getCodeBase ();
371
 
371
 
372
    // get the index file and parse its contents
372
    // get the index file and parse its contents
373
    try {
373
    try {
374
      URL idxFileURL = new URL (baseURL,idxFile);
374
      URL idxFileURL = new URL (baseURL,idxFile);
375
 
375
 
376
      // get an IndexStream object for ease of parsing
376
      // get an IndexStream object for ease of parsing
377
      IndexStream idxStream = new IndexStream (idxFileURL);
377
      IndexStream idxStream = new IndexStream (idxFileURL);
378
 
378
 
379
      // now start parsing...
379
      // now start parsing...
380
      
380
      
381
      /*
381
      /*
382
       * An entry consists of a title, keywords, an URL and a description.
382
       * An entry consists of a title, keywords, an URL and a description.
383
       * everything else is ignored. Every entry starts with the keyword
383
       * everything else is ignored. Every entry starts with the keyword
384
       * "Entry" (case is ignored)
384
       * "Entry" (case is ignored)
385
       *
385
       *
386
       * must-have entries are "Entry" and "Keywords"
386
       * must-have entries are "Entry" and "Keywords"
387
       *
387
       *
388
       * 98-06-01: bugfix: don't null the variables
388
       * 98-06-01: bugfix: don't null the variables
389
       */
389
       */
390
      String entry = "";
390
      String entry = "";
391
      String keywords = "";
391
      String keywords = "";
392
      String url = "";
392
      String url = "";
393
      String description = "";
393
      String description = "";
394
      String prefix = "";
394
      String prefix = "";
395
      String suffix = "";
395
      String suffix = "";
396
 
396
 
397
      Value value = idxStream.popEntry ();
397
      Value value = idxStream.popEntry ();
398
 
398
 
399
      while (value != null) {
399
      while (value != null) {
400
	// parse the value now
400
	// parse the value now
401
	if (value.getKey ().equalsIgnoreCase ("entry")) {
401
	if (value.getKey ().equalsIgnoreCase ("entry")) {
402
	  // if a new entry is about to start, add the current one
402
	  // if a new entry is about to start, add the current one
403
	  addEntry (entry,keywords,description,url,prefix,suffix);
403
	  addEntry (entry,keywords,description,url,prefix,suffix);
404
 
404
 
405
	  entry = value.getValue ();
405
	  entry = value.getValue ();
406
	  keywords = "";
406
	  keywords = "";
407
	  url = "";
407
	  url = "";
408
	  description = "";
408
	  description = "";
409
	} else if (value.getKey ().equalsIgnoreCase ("keywords")) {
409
	} else if (value.getKey ().equalsIgnoreCase ("keywords")) {
410
	  keywords += value.getValue ();
410
	  keywords += value.getValue ();
411
	} else if (value.getKey ().equalsIgnoreCase ("url")) {
411
	} else if (value.getKey ().equalsIgnoreCase ("url")) {
412
	  // use prefix and suffix
412
	  // use prefix and suffix
413
	  url = prefix + value.getValue () + suffix;
413
	  url = prefix + value.getValue () + suffix;
414
	} else if (value.getKey ().equalsIgnoreCase ("description")) {
414
	} else if (value.getKey ().equalsIgnoreCase ("description")) {
415
	  description = value.getValue ();
415
	  description = value.getValue ();
416
	} else if (value.getKey ().equalsIgnoreCase ("prefix")) {
416
	} else if (value.getKey ().equalsIgnoreCase ("prefix")) {
417
	  prefix = value.getValue ();
417
	  prefix = value.getValue ();
418
	  Tracer.write ("using new URL prefix \"" + prefix + "\"\n");
418
	  Tracer.write ("using new URL prefix \"" + prefix + "\"\n");
419
	} else if (value.getKey ().equalsIgnoreCase ("suffix")) {
419
	} else if (value.getKey ().equalsIgnoreCase ("suffix")) {
420
	  suffix = value.getValue ();
420
	  suffix = value.getValue ();
421
	  Tracer.write ("using new URL suffix \"" + suffix + "\"\n");
421
	  Tracer.write ("using new URL suffix \"" + suffix + "\"\n");
422
	} else if (value.getKey ().equalsIgnoreCase ("alias")) {
422
	} else if (value.getKey ().equalsIgnoreCase ("alias")) {
423
	  keywords += value.getValue ();
423
	  keywords += value.getValue ();
424
	}
424
	}
425
	value = idxStream.popEntry ();
425
	value = idxStream.popEntry ();
426
      }
426
      }
427
 
427
 
428
      // the final entry just read
428
      // the final entry just read
429
      addEntry (entry,keywords,description,url,prefix,suffix);
429
      addEntry (entry,keywords,description,url,prefix,suffix);
430
    } catch (MalformedURLException exc) {
430
    } catch (MalformedURLException exc) {
431
      // an error occured while reading...
431
      // an error occured while reading...
432
    }
432
    }
433
 
433
 
434
    return;
434
    return;
435
  }
435
  }
436
 
436
 
437
  
437
  
438
  /*----------------------------------------------------------------------------
438
  /*----------------------------------------------------------------------------
439
    INTERFACE: 
439
    INTERFACE: 
440
    PURPOSE:   
440
    PURPOSE:   
441
  	      
441
  	      
442
    NOTES:     
442
    NOTES:     
443
  
443
  
444
    PARAMS:    
444
    PARAMS:    
445
    THROWS:    
445
    THROWS:    
446
    RETURNS:   void
446
    RETURNS:   void
447
  
447
  
448
    HISTORY:   98-05-10: created
448
    HISTORY:   98-05-10: created
449
               98-06-01: value is "", not null if empty
449
               98-06-01: value is "", not null if empty
450
  ----------------------------------------------------------------------------*/
450
  ----------------------------------------------------------------------------*/
451
  private void addEntry (String entry,String keywords,
451
  private void addEntry (String entry,String keywords,
452
			 String description,String url,
452
			 String description,String url,
453
			 String prefix,String suffix)
453
			 String prefix,String suffix)
454
  {
454
  {
455
    // the entry must be set
455
    // the entry must be set
456
    if (entry.length () == 0) {
456
    if (entry.length () == 0) {
457
      return;
457
      return;
458
    }
458
    }
459
 
459
 
460
    // the keywords must be set, else ignore it
460
    // the keywords must be set, else ignore it
461
    if (keywords.length () != 0) {
461
    if (keywords.length () != 0) {
462
      if (url.length () == 0) {
462
      if (url.length () == 0) {
463
	// if the URL is empty, construct one following the rule:
463
	// if the URL is empty, construct one following the rule:
464
	// URL = prefix + first keyword + suffix
464
	// URL = prefix + first keyword + suffix
465
	int endOfFirstKeyword = keywords.indexOf (" ");
465
	int endOfFirstKeyword = keywords.indexOf (" ");
466
	
466
	
467
	// because we have trimmed the string, the first character must
467
	// because we have trimmed the string, the first character must
468
	// not be a blank
468
	// not be a blank
469
	if (endOfFirstKeyword >= 0) {
469
	if (endOfFirstKeyword >= 0) {
470
	  url = keywords.substring (0,endOfFirstKeyword);
470
	  url = keywords.substring (0,endOfFirstKeyword);
471
	  Tracer.write ("constructing URL, keywords=\"" +
471
	  Tracer.write ("constructing URL, keywords=\"" +
472
			keywords + "\"" +
472
			keywords + "\"" +
473
			"using \"" + 
473
			"using \"" + 
474
			url +
474
			url +
475
			"\" (results in \"" +
475
			"\" (results in \"" +
476
			prefix + url + suffix + "\")\n");
476
			prefix + url + suffix + "\")\n");
477
	} else {
477
	} else {
478
	  // just a single keyword
478
	  // just a single keyword
479
	  url = keywords;
479
	  url = keywords;
480
	  Tracer.write ("constructing URL, using keyword \"" + 
480
	  Tracer.write ("constructing URL, using keyword \"" + 
481
			url +
481
			url +
482
			"\" (results in \"" +
482
			"\" (results in \"" +
483
			prefix + url + suffix + "\")\n");
483
			prefix + url + suffix + "\")\n");
484
	}
484
	}
485
	// add prefix and suffix
485
	// add prefix and suffix
486
	url = prefix + url + suffix;
486
	url = prefix + url + suffix;
487
      }
487
      }
488
      IndexEntry idxEntry =
488
      IndexEntry idxEntry =
489
	new IndexEntry (entry,keywords,description,url);
489
	new IndexEntry (entry,keywords,description,url);
490
      iIndexTable.addElement (idxEntry);
490
      iIndexTable.addElement (idxEntry);
491
    }
491
    }
492
 
492
 
493
    return;
493
    return;
494
  }
494
  }
495
 
495
 
496
 
496
 
497
  /*============================================================================
497
  /*============================================================================
498
                             Instance Variables
498
                             Instance Variables
499
  ============================================================================*/
499
  ============================================================================*/
500
  private IndexTable iIndexTable;
500
  private IndexTable iIndexTable;
501
  private String     iSearchTerm;
501
  private String     iSearchTerm;
502
  private int        iSearchMode;
502
  private int        iSearchMode;
503
 
503
 
504
 
504
 
505
  /*============================================================================
505
  /*============================================================================
506
                                Static Data
506
                                Static Data
507
  ============================================================================*/
507
  ============================================================================*/
508
 
508
 
509
  private static final String cIndexFile = "index.txt";
509
  private static final String cIndexFile = "index.txt";
510
  private static final String cIndexKeyword = "INDEXFILE";
510
  private static final String cIndexKeyword = "INDEXFILE";
511
  private static final String cSearchKeyword = "SEARCHTERM";
511
  private static final String cSearchKeyword = "SEARCHTERM";
512
}
512
}
513
 
513
 
514
/*==============================================================================
514
/*==============================================================================
515
 
515
 
516
  HISTORY:
516
  HISTORY:
517
  
517
  
518
  $Log: SearchEngine.java,v $
518
  $Log: SearchEngine.java,v $
-
 
519
  Revision 1.3  1999/08/10 09:56:03  ripley
-
 
520
  change FSF address in copyrights
-
 
521
  add some copyrights in src/gnome and elsewhere
-
 
522
 
519
  Revision 1.2  1999/03/04 17:15:18  leisch
523
  Revision 1.2  1999/03/04 17:15:18  leisch
520
  various bugfixes
524
  various bugfixes
521
 
525
 
522
  Revision 1.1.4.1  1999/03/02 15:19:57  leisch
526
  Revision 1.1.4.1  1999/03/02 15:19:57  leisch
523
  search used only kewords, no titles
527
  search used only kewords, no titles
524
 
528
 
525
  Revision 1.6  1998/05/19 20:23:13  baier
529
  Revision 1.6  1998/05/19 20:23:13  baier
526
  added alias support
530
  added alias support
527
 
531
 
528
  Revision 1.5  1998/05/15 22:10:05  baier
532
  Revision 1.5  1998/05/15 22:10:05  baier
529
  allow searching in description, fix bug in results list
533
  allow searching in description, fix bug in results list
530
 
534
 
531
  Revision 1.4  1998/05/10 22:56:53  baier
535
  Revision 1.4  1998/05/10 22:56:53  baier
532
  internal search function, parameter expansion
536
  internal search function, parameter expansion
533
 
537
 
534
  Revision 1.3  1998/05/10 02:44:32  baier
538
  Revision 1.3  1998/05/10 02:44:32  baier
535
  traces, output in HTML via JavaScript, new index generation
539
  traces, output in HTML via JavaScript, new index generation
536
 
540
 
537
  Revision 1.2  1998/04/26 22:36:34  baier
541
  Revision 1.2  1998/04/26 22:36:34  baier
538
  documentation changes
542
  documentation changes
539
 
543
 
540
 
544
 
541
 
545
 
542
  Revision 1.1  1998/04/26 21:32:54  baier
546
  Revision 1.1  1998/04/26 21:32:54  baier
543
  Initial revision
547
  Initial revision
544
 
548
 
545
 
549
 
546
==============================================================================*/
550
==============================================================================*/
547
 
551
 
548
 
552
 
549
// Local Variables:
553
// Local Variables:
550
// mode: Java
554
// mode: Java
551
// mode: font-lock
555
// mode: font-lock
552
// End:
556
// End: