コード例 #1
0
 public FileInfo getFileInfo(String uriString)
     throws SearchLibException, UnsupportedEncodingException, URISyntaxException {
   AbstractSearchRequest searchRequest =
       (AbstractSearchRequest) dbClient.getNewRequest(SearchTemplate.fileInfo.name());
   StringBuilder sb = new StringBuilder();
   FileItemFieldEnum.INSTANCE.uri.addQuery(sb, uriString, true);
   searchRequest.setQueryString(sb.toString());
   searchRequest.setStart(0);
   searchRequest.setRows(1);
   AbstractResultSearch<?> result = (AbstractResultSearch<?>) dbClient.request(searchRequest);
   if (result.getNumFound() == 0) return null;
   return new FileInfo(result.getDocument(0));
 }
コード例 #2
0
 public void getFileInfoList(URI parentDirectory, Map<String, FileInfo> indexFileMap)
     throws SearchLibException, UnsupportedEncodingException, URISyntaxException {
   AbstractSearchRequest searchRequest =
       (AbstractSearchRequest) dbClient.getNewRequest(SearchTemplate.fileInfo.name());
   StringBuilder sb = new StringBuilder();
   String parentUriString = parentDirectory.toASCIIString();
   FileItemFieldEnum.INSTANCE.directory.addQuery(sb, parentUriString, true);
   searchRequest.setQueryString(sb.toString());
   searchRequest.setStart(0);
   searchRequest.setRows(Integer.MAX_VALUE);
   AbstractResultSearch<?> result = (AbstractResultSearch<?>) dbClient.request(searchRequest);
   int l = result.getNumFound();
   for (int i = 0; i < l; i++) {
     FileInfo fileInfo = new FileInfo(result.getDocument(i));
     indexFileMap.put(fileInfo.getUri(), fileInfo);
   }
 }
コード例 #3
0
  private final boolean deleteByRepositoryFromTargetIndex(String repository)
      throws SearchLibException, IOException, ParseException, SyntaxError, URISyntaxException,
          ClassNotFoundException, InterruptedException, InstantiationException,
          IllegalAccessException {

    List<TargetField> mappedPath =
        targetClient
            .getFileCrawlerFieldMap()
            .getLinks(new SourceField(FileItemFieldEnum.INSTANCE.repository.toString()));

    if (mappedPath == null || mappedPath.isEmpty()) return false;

    AbstractSearchRequest deleteRequest = new SearchPatternRequest(targetClient);
    deleteRequest.setQueryString(mappedPath.get(0).getName() + ":\"" + repository + "\"");

    targetClient.deleteDocuments(deleteRequest);
    return true;
  }
コード例 #4
0
  public AbstractSearchRequest fileQuery(
      SearchTemplate searchTemplate,
      String repository,
      String fileName,
      String lang,
      String langMethod,
      Integer minSize,
      Integer maxSize,
      String fileExtension,
      FetchStatus fetchStatus,
      ParserStatus parserStatus,
      IndexStatus indexStatus,
      Date startcrawlDate,
      Date endCrawlDate,
      Date startModifiedDate,
      Date endModifiedDate,
      FileTypeEnum fileType,
      String subDirectory,
      Integer minTime,
      Integer maxTime,
      String parser)
      throws SearchLibException {
    try {

      AbstractSearchRequest searchRequest =
          (AbstractSearchRequest) dbClient.getNewRequest(searchTemplate.name());

      StringBuilder query = new StringBuilder();

      if (fileName != null)
        if ((fileName = fileName.trim()).length() > 0)
          FileItemFieldEnum.INSTANCE.fileName.addQuery(query, fileName, true);

      if (repository != null)
        if ((repository = repository.trim()).length() > 0)
          FileItemFieldEnum.INSTANCE.repository.addFilterQuery(
              searchRequest, repository, true, false);

      if (fileExtension != null)
        if ((fileExtension = fileExtension.trim()).length() > 0)
          FileItemFieldEnum.INSTANCE.fileExtension.addFilterQuery(
              searchRequest, QueryUtils.escapeQuery(fileExtension), false, false);

      if (lang != null)
        if ((lang = lang.trim()).length() > 0)
          FileItemFieldEnum.INSTANCE.lang.addFilterQuery(
              searchRequest, QueryUtils.escapeQuery(lang), false, false);

      if (langMethod != null) {
        langMethod = langMethod.trim();
        if (langMethod.length() > 0)
          FileItemFieldEnum.INSTANCE.langMethod.addFilterQuery(
              searchRequest, QueryUtils.escapeQuery(langMethod), false, false);
      }

      if (fetchStatus != null && fetchStatus != FetchStatus.ALL)
        FileItemFieldEnum.INSTANCE.fetchStatus.addFilterQuery(
            searchRequest, fetchStatus.value, false, false);
      if (parserStatus != null && parserStatus != ParserStatus.ALL)
        FileItemFieldEnum.INSTANCE.parserStatus.addFilterQuery(
            searchRequest, parserStatus.value, false, false);
      if (indexStatus != null && indexStatus != IndexStatus.ALL)
        FileItemFieldEnum.INSTANCE.indexStatus.addFilterQuery(
            searchRequest, indexStatus.value, false, false);

      if (fileType != null && fileType != FileTypeEnum.ALL)
        FileItemFieldEnum.INSTANCE.fileType.addFilterQuery(
            searchRequest, fileType.name(), true, false);

      if (minSize != null || maxSize != null) {
        String from, to;
        if (minSize == null) from = FileItem.contentLengthFormat.format(0);
        else from = FileItem.contentLengthFormat.format(minSize);
        if (maxSize == null) to = FileItem.contentLengthFormat.format(Integer.MAX_VALUE);
        else to = FileItem.contentLengthFormat.format(maxSize);
        FileItemFieldEnum.INSTANCE.fileSize.addFilterRange(searchRequest, from, to, false, false);
      }

      if (minTime != null || maxTime != null) {
        String from, to;
        if (minTime == null) from = FileItem.contentLengthFormat.format(0);
        else from = FileItem.contentLengthFormat.format(minTime);
        if (maxTime == null) to = FileItem.contentLengthFormat.format(Integer.MAX_VALUE);
        else to = FileItem.contentLengthFormat.format(maxTime);
        FileItemFieldEnum.INSTANCE.time.addFilterRange(searchRequest, from, to, false, false);
      }

      if (startcrawlDate != null || endCrawlDate != null) {
        String from, to;
        if (startcrawlDate == null) from = "00000000000000";
        else from = FileItem.dateFormat.format(startcrawlDate);
        if (endCrawlDate == null) to = "99999999999999";
        else to = FileItem.dateFormat.format(endCrawlDate);
        FileItemFieldEnum.INSTANCE.crawlDate.addFilterRange(searchRequest, from, to, false, false);
      }

      if (startModifiedDate != null || endModifiedDate != null) {
        String from, to;
        if (startModifiedDate == null) from = "00000000000000";
        else from = FileItem.dateFormat.format(startModifiedDate);
        if (endModifiedDate == null) to = "99999999999999";
        else to = FileItem.dateFormat.format(endModifiedDate);
        FileItemFieldEnum.INSTANCE.fileSystemDate.addFilterRange(
            searchRequest, from, to, false, false);
      }

      if (subDirectory != null)
        FileItemFieldEnum.INSTANCE.subDirectory.addFilterQuery(
            searchRequest, subDirectory, true, false);

      if (parser != null)
        if ((parser = parser.trim()).length() > 0)
          FileItemFieldEnum.INSTANCE.parser.addFilterQuery(searchRequest, parser, true, false);

      searchRequest.setEmptyReturnsAll(true);
      searchRequest.setQueryString(query.toString().trim());
      return searchRequest;
    } catch (ParseException e) {
      throw new SearchLibException(e);
    }
  }