Global.helma.Search.Index (directory, analyzer)
  • Parameter {org.apache.lucene.store.Directory}:
    directory The directory where the Lucene index is located at.
  • Parameter {org.apache.lucene.analysis.Analyzer}:
    analyzer The analyzer to use when modifying the index.
Sourcecode in /home/hannes/helma/modules/helma/Search.js:
238:   helma.Search.Index = function(directory, analyzer) {
239:   
240:       /**
241:        * Tries to create a new IndexWriter or IndexModifier for up to the
242:        * number of milliseconds defined in helma.Search.Index.LOCK_TIMEOUT.
243:        * @private
244:        */
245:       var getWriterModifier = function(what, create) {
246:           var waitFor, elapsed = 0;
247:          while (elapsed < helma.Search.Index.LOCK_TIMEOUT) {
248:              if (!this.isLocked()) {
249:                  return new Packages.org.apache.lucene.index[what](directory,
250:                                     analyzer, create == true ? true : false);
251:              } else {
252:                  waitFor = Math.round(Math.random() * 100) + 50;
253:                  java.lang.Thread.sleep(waitFor);
254:                  elapsed += waitFor;
255:                  app.logger.debug("[Thread " + java.lang.Thread.currentThread().getId()
256:                                   + "] waiting for " + elapsed + "ms");
257:              }
258:          }
259:          throw("Failed to create " + what + " due to active lock (Thread "
260:                + java.lang.Thread.currentThread().getId() + ")");
261:      };
262:  
263:      /**
264:       * Returns an IndexModifier instance for adding or deleting
265:       * documents to resp. from the underlying index. If the
266:       * index is currently locked this method will try for the next
267:       * two seconds to create the IndexModifier, otherwise it will
268:       * throw an error.
269:       * @return An IndexModifier instance.
270:       * @type org.apache.lucene.index.IndexModifier
271:       */
272:      this.getModifier = function(create) {
273:          return getWriterModifier.call(this, "IndexModifier", create);
274:      };
275:  
276:      /**
277:       * Returns an IndexWriter instance that can be used to add documents to
278:       * the underlying index or to perform various other modifying operations.
279:       * If the index is currently locked this method will try for the next
280:       * two seconds to create the IndexWriter, otherwise it will
281:       * throw an error.
282:       * @return An IndexWriter instance.
283:       * @type org.apache.lucene.index.IndexWriter
284:       */
285:      this.getWriter = function(create) {
286:          return getWriterModifier.call(this, "IndexWriter", create);
287:      };
288:  
289:      /**
290:       * Returns an IndexReader instance. Due to locking issues an
291:       * IndexModifier should be used for deleting documents.
292:       * @return An IndexReader instance
293:       * @type org.apache.lucene.index.IndexReader
294:       */
295:      this.getReader = function() {
296:          return Packages.org.apache.lucene.index.IndexReader.open(directory);
297:      };
298:  
299:      /**
300:       * Returns the directory the underlying Lucene index is located at.
301:       * @return The directory of this index
302:       * @type org.apache.lucene.store.Directory
303:       */
304:      this.getDirectory = function() {
305:          return directory;
306:      };
307:  
308:      /**
309:       * Returns the analyzer used within this index.
310:       * @return The analyzer used within this index.
311:       * @type org.apache.lucene.analysis.Analyer
312:       */
313:      this.getAnalyzer = function() {
314:          return analyzer;
315:      };
316:      
317:      /**
318:       * Returns a searcher for querying this index.
319:       * @return A searcher useable for querying the index.
320:       * @type helma.Search.Searcher
321:       */
322:      this.getSearcher = function() {
323:          return new helma.Search.Searcher(this);
324:      };
325:      
326:      /** @ignore */
327:      this.toString = function() {
328:          return ("[Lucene Index " + directory + "]");
329:      };
330:  
331:      return this;
332:  }