Пример #1
0
  private void renderDocuments()
      throws IOException, ParseException, SyntaxError, SearchLibException {
    AbstractSearchRequest searchRequest = result.getRequest();
    int start = searchRequest.getStart();
    int end = result.getDocumentCount() + searchRequest.getStart();

    for (int i = start; i < end; i++) this.renderDocument(i);
  }
Пример #2
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));
 }
Пример #3
0
  private void renderDocument(int i)
      throws IOException, ParseException, SyntaxError, SearchLibException {
    ResultDocument doc = result.getDocument(i, null);
    for (ReturnField field : searchRequest.getReturnFieldList()) {
      renderField(doc, field);
      if (field.getName() != null && !field.getName().equals("")) writer.print(',');
    }
    for (SnippetField field : searchRequest.getSnippetFieldList()) {
      renderSnippetValue(doc, field);
      String fName = field.getName();
      if (fName != null && fName.length() > 0) writer.print(',');
    }

    writer.print('\n');
  }
 public List<String> getFieldList() throws SearchLibException, InterruptedException {
   if (fieldType == null) return null;
   Client client = getClient();
   if (client == null) return null;
   if (searchTemplate == null) new AlertController("Please Select an Query Template");
   AbstractSearchRequest request =
       (AbstractSearchRequest) client.getRequestMap().get(searchTemplate);
   if (request == null) return null;
   List<String> nameList = new ArrayList<String>();
   nameList.add(null);
   if (fieldType == OpenSearchTypes.FIELD) request.getReturnFieldList().toNameList(nameList);
   else if (fieldType == OpenSearchTypes.SNIPPET)
     request.getSnippetFieldList().toNameList(nameList);
   return nameList;
 }
Пример #5
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);
   }
 }
Пример #6
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;
  }
Пример #7
0
 public long getFileList(
     AbstractSearchRequest searchRequest, long start, long rows, List<FileItem> list)
     throws SearchLibException {
   searchRequest.reset();
   searchRequest.setStart((int) start);
   searchRequest.setRows((int) rows);
   try {
     AbstractResultSearch<?> result = (AbstractResultSearch<?>) dbClient.request(searchRequest);
     if (list != null) for (ResultDocument doc : result) list.add(getNewFileItem(doc));
     return result.getNumFound();
   } catch (RuntimeException e) {
     throw new SearchLibException(e);
   } catch (UnsupportedEncodingException e) {
     throw new SearchLibException(e);
   } catch (URISyntaxException e) {
     throw new SearchLibException(e);
   }
 }
 public List<String> getSnippetFieldLeft() throws SearchLibException {
   synchronized (this) {
     Client client = getClient();
     if (client == null) return null;
     AbstractSearchRequest request = (AbstractSearchRequest) getRequest();
     if (request == null) return null;
     if (snippetFieldLeft != null) return snippetFieldLeft;
     snippetFieldLeft = new ArrayList<String>();
     SnippetFieldList snippetFields = request.getSnippetFieldList();
     for (SchemaField field : client.getSchema().getFieldList())
       if (field.checkStored(Stored.YES, Stored.COMPRESS))
         if (field.getTermVector() == TermVector.POSITIONS_OFFSETS)
           if (snippetFields.get(field.getName()) == null) {
             if (selectedSnippet == null) selectedSnippet = field.getName();
             snippetFieldLeft.add(field.getName());
           }
     return snippetFieldLeft;
   }
 }
Пример #9
0
  public long getFiles(
      AbstractSearchRequest searchRequest,
      ItemField orderBy,
      boolean orderAsc,
      long start,
      long rows,
      List<FileItem> list)
      throws SearchLibException {
    searchRequest.setStart((int) start);
    searchRequest.setRows((int) rows);
    try {
      if (orderBy != null) orderBy.addSort(searchRequest, !orderAsc);
      AbstractResultSearch<?> result = (AbstractResultSearch<?>) dbClient.request(searchRequest);
      if (list != null) for (ResultDocument doc : result) list.add(getNewFileItem(doc));
      return result.getNumFound();

    } catch (IOException e) {
      throw new SearchLibException(e);
    } catch (RuntimeException e) {
      throw new SearchLibException(e);
    } catch (URISyntaxException e) {
      throw new SearchLibException(e);
    }
  }
Пример #10
0
 public Params(ReaderAbstract reader, AbstractSearchRequest searchRequest, FilterHits filterHits)
     throws ParseException, SyntaxError, SearchLibException, IOException {
   this.reader = reader;
   this.query = searchRequest.getQuery();
   this.isScoreRequired = searchRequest.isScoreRequired();
   this.isDistanceRequired = searchRequest.isDistanceRequired();
   this.geoParameters = searchRequest.getGeoParameters();
   this.advancedScore = searchRequest.getAdvancedScore();
   this.isDocIdRequired = searchRequest.isDocIdRequired();
   this.filterHits = filterHits;
   this.forFilterHits = searchRequest instanceof SearchFilterRequest;
 }
Пример #11
0
 public final void apply(final AbstractSearchRequest searchRequest)
     throws SearchLibException, IOException {
   if (!isJoin()) searchRequest.getFilterList().addAuthFilter();
   else searchRequest.getJoinList().addAuthJoin();
 }
Пример #12
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);
    }
  }