private void buildDocument() throws IOException {
    _docId = _documentDescriptor;
    String currentDocId = DocumentIdOperations.documentDescriptorToId(_documentDescriptor);
    int lastSnippetId = 0;
    DocumentHolder docHolder = new DocumentHolder(_indexReader, _docId);
    DocForReport reportDocument = new DocForReport(currentDocId);
    for (MatchDescriptor match : _searchResult.matches) {
      // there are ~ 100 matches in a regular report page, and it's OK to traverse them all each
      // time building
      // a new document node
      DocumentDescriptor docDescriptor = match.doc;
      if (!(docDescriptor.equals(_docId))) {
        continue;
      }
      if (!_searchType.equals("all-documents") && !docDescriptor.equals(_docId)) {
        continue;
      }
      // searching for the specific snippet
      if (_searchType.equals("snippet") && lastSnippetId != _sId) {
        ++lastSnippetId;
        continue;
      }

      addMatchToDocument(match, reportDocument, docHolder);
      ++lastSnippetId;
    }
    createDocumentNode(_documentDescriptor);
    _rootNode.setAttribute("snippets", String.valueOf(reportDocument.snippets.size()));
    for (Snippet snippet : reportDocument.snippets) {
      Element snippetNode = createSnippetNode(snippet);
      _rootNode.appendChild(snippetNode);
    }
  }
 public static DocumentDescriptor idToDocumentDescriptor(final String inId) {
   String[] idTokens = StringUtils.split(inId, "_");
   DocumentDescriptor result = new DocumentDescriptor();
   result.globalId = Integer.parseInt(idTokens[0]);
   result.segmentNumber = Integer.parseInt(idTokens[1]);
   result.localId = Integer.parseInt(idTokens[2]);
   return result;
 }
  protected void buildResult(final SearchResult inSearchResult) {
    _resultNode = (Element) getLastElement(_rootNode.getElementsByTagName("result"));
    if (_docId != null) {
      _searchType = "document";
    }
    if (_sId != -1) {
      _searchType = "snippet";
    }
    _resultNode.setAttribute("search-type", _searchType);
    int docsNumber = inSearchResult.totalDocumentsNumber,
        contextsNumber = inSearchResult.totalMatchesNumber;
    // in the cases of 'document' and 'snippet' search we will accumulate contexts number
    // while building the result
    if (_searchType.equals("document")) {
      docsNumber = 1;
      contextsNumber = 0;
    }
    if (_searchType.equals("snippet")) {
      docsNumber = 1;
      contextsNumber = 0;
    }
    _resultNode.setAttribute("documents", Integer.toString(docsNumber));
    _resultNode.setAttribute("contexts", Integer.toString(contextsNumber));

    _documentLoaders = new ArrayList<Callable<Integer>>();
    DocumentDescriptor lastDocId = null;
    for (MatchDescriptor match : inSearchResult.matches) {
      DocumentDescriptor currentDocumentDescriptor = match.doc;
      if (lastDocId == null || !(currentDocumentDescriptor.equals(lastDocId))) {
        DocumentNodeBuilder currentDocumentLoader = new DocumentNodeBuilder(_indexReader);
        currentDocumentLoader.getTask(inSearchResult, currentDocumentDescriptor);
        _documentLoaders.add(currentDocumentLoader);
        lastDocId = currentDocumentDescriptor;
      }
    }

    try {
      _documentLoadingExecutor.invokeAll(_documentLoaders);
    } catch (InterruptedException exc) {
      exc.printStackTrace();
    }
    System.out.println("Document nodes built");

    for (Callable<Integer> docBuilder : _documentLoaders) {
      Node documentNode = ((DocumentNodeBuilder) docBuilder).getDocumentNode();
      Node adoptedDocumentNode = _document.adoptNode(documentNode);
      _resultNode.appendChild(adoptedDocumentNode);
    }
  }
Beispiel #4
0
  @Override
  protected JSONObject getJson() throws Exception {
    JSONObject doc = documentDescriptor.getJson();

    return doc.getJSONObject(key);
  }