Beispiel #1
0
  /**
   * Construct Indexer
   *
   * @param directory the main BlackLab index directory
   * @param create if true, creates a new index; otherwise, appends to existing index
   * @param docIndexerClass how to index the files, or null to autodetect
   * @param indexTemplateFile JSON file to use as template for index structure / metadata (if
   *     creating new index)
   * @throws DocumentFormatException if no DocIndexer was specified and autodetection failed
   * @throws IOException
   */
  public Indexer(
      File directory,
      boolean create,
      Class<? extends DocIndexer> docIndexerClass,
      File indexTemplateFile)
      throws DocumentFormatException, IOException {
    this.docIndexerClass = docIndexerClass;

    searcher = Searcher.openForWriting(directory, create, indexTemplateFile);
    if (!create) searcher.getIndexStructure().setModified();

    if (this.docIndexerClass == null) {
      // No DocIndexer supplied; try to detect it from the index
      // metadata.
      String formatId = searcher.getIndexStructure().getDocumentFormat();
      if (formatId != null && formatId.length() > 0)
        setDocIndexer(DocumentFormats.getIndexerClass(formatId));
      else {
        throw new DocumentFormatException("Cannot detect document format for index!");
      }
    }

    metadataFieldTypeTokenized = new FieldType();
    metadataFieldTypeTokenized.setStored(true);
    metadataFieldTypeTokenized.setIndexed(true);
    metadataFieldTypeTokenized.setTokenized(true);
    metadataFieldTypeTokenized.setOmitNorms(true); // @@@ <-- depending on setting?
    metadataFieldTypeTokenized.setStoreTermVectors(true);
    metadataFieldTypeTokenized.setStoreTermVectorPositions(true);
    metadataFieldTypeTokenized.setStoreTermVectorOffsets(true);
    metadataFieldTypeTokenized.freeze();

    metadataFieldTypeUntokenized = new FieldType(metadataFieldTypeTokenized);
    metadataFieldTypeUntokenized.setTokenized(false);
    metadataFieldTypeUntokenized.freeze();
  }
Beispiel #2
0
  /**
   * Close the index
   *
   * @throws IOException
   * @throws CorruptIndexException
   */
  public void close() throws CorruptIndexException, IOException {

    // Signal to the listener that we're done indexing and closing the index (which might take a
    // while)
    getListener().indexEnd();
    getListener().closeStart();

    searcher.getIndexStructure().addToTokenCount(getListener().getTokensProcessed());
    searcher.getIndexStructure().writeMetadata();

    searcher.close();

    // Signal that we're completely done now
    getListener().closeEnd();
    getListener().indexerClosed();
  }
  @Override
  public Response handle() throws BlsException {
    Collection<String> indices = searchMan.getAllAvailableIndices(user.getUserId());
    DataObjectMapAttribute doIndices = new DataObjectMapAttribute("index", "name");
    // DataObjectList doIndices = new DataObjectList("index");
    for (String indexName : indices) {
      DataObjectMapElement doIndex = new DataObjectMapElement();
      Searcher searcher = searchMan.getSearcher(indexName);
      IndexStructure struct = searcher.getIndexStructure();
      doIndex.put("displayName", struct.getDisplayName());
      doIndex.put("status", searchMan.getIndexStatus(indexName));
      String documentFormat = struct.getDocumentFormat();
      if (documentFormat != null && documentFormat.length() > 0)
        doIndex.put("documentFormat", documentFormat);
      doIndex.put("timeModified", struct.getTimeModified());
      if (struct.getTokenCount() > 0) doIndex.put("tokenCount", struct.getTokenCount());
      doIndices.put(indexName, doIndex);
    }

    DataObjectMapElement doUser = new DataObjectMapElement();
    doUser.put("loggedIn", user.isLoggedIn());
    if (user.isLoggedIn()) doUser.put("id", user.getUserId());
    doUser.put(
        "canCreateIndex", user.isLoggedIn() ? searchMan.canCreateIndex(user.getUserId()) : false);

    DataObjectMapElement response = new DataObjectMapElement();
    response.put("blacklabBuildTime", Searcher.getBlackLabBuildTime());
    response.put("indices", doIndices);
    response.put("user", doUser);
    response.put("helpPageUrl", servlet.getServletContext().getContextPath() + "/help");
    if (debugMode) {
      response.put("cacheStatus", searchMan.getCacheStatusDataObject());
    }

    Response responseObj = new Response(response);
    responseObj.setCacheAllowed(false); // You can create/delete indices, don't cache the list
    return responseObj;
  }