New to GroupDocs search

I have created a basic Java application which creates an index, adds documents to index and executes a query for a word. All looks good and using the highlighting example html files are opened.

I have a a couple of questions which I’m hoping you can assist with.
First it appears that found documents return how do I know if the rest have failed because no matching search criteria or the document is not covered or is corrupt perhaps
Next does the indexing/search include embedded objects for example a chart in excel or word

Many thanks

@matdave

Suppose we have 10+ documents in a directory and want to perform search over that. When we pass a search string/query to the API, it will return all the documents that match the search string.

How Search Works?
The Search method returns an object of type SearchResult. This page describes the information available in an object of type SearchResult.
Out of 10 if we get 5 documents in the result, that means other 5 don’t have the specified search string.

API supports search for different object types: text, numbers, dates, file names, document types, metadata fields, document creation/modification dates.
Could you please explain “chart in excel”. How you are going to perform search here? What would be your search string? Do you mean search chart data (that is eventually some text)?

Thanks for the reply, my code mostly mirrors the code in your reply.

If I have 10 documents in my document folder and am searching for the word ‘Oxygen’ and the results brought back five document that contained the search word what should i consider about the five documents not found. Is it the case that the search completed but the word was not found or could it be that there was a corrupt of unsupported file format and the search did not complete.

If I create a chart based on data in an excel spreadsheet with labelled axis etc then cut and paste the chart into a word document will the search of the word document find labels that match the search criteria

Many thanks

@matdave

We are investigating these scenarios. Your investigation ticket ID SEARCHJAVA-215. We’ll notify you in case of any update.

Hi,

Both are good questions — let me take them separately.

1. What happened to the other five documents

The key thing is that search never touches your files. It only queries what is already in the index. So the five documents that came back empty fall into three different buckets, and you can tell them apart:

  • they were indexed fine and simply do not contain “Oxygen”;
  • they were indexed, but text extraction failed or only partly succeeded (corrupt file, password-protected, an embedded part that could not be read);
  • they never entered the index at all (unsupported format, filtered out, skipped).

To separate those, start from the list of what actually made it in:

DocumentInfo[] documents = index.getIndexedDocuments();
for (DocumentInfo document : documents) {
    System.out.println(document.getFilePath() + " indexedWithError=" + document.getIndexedWithError());
}

Any of your ten files missing from that array never got indexed. Any file present with getIndexedWithError() returning true is one where extraction ran into trouble — that is your “the search did not complete” case. Whatever is left is a genuine “the word is not in this document”.

For the reason behind a failure, subscribe while indexing:

index.getEvents().ErrorOccurred.add(new EventHandler<IndexErrorEventArgs>() {
    public void invoke(Object sender, IndexErrorEventArgs args) {
        System.out.println(args.getMessage() + ", critical: " + args.isCritical());
    }
});

index.getEvents().OperationProgressChanged.add(new EventHandler<OperationProgressEventArgs>() {
    public void invoke(Object sender, OperationProgressEventArgs args) {
        System.out.println(args.getLastDocumentPath() + " -> " + args.getLastDocumentStatus());
    }
});

index.add(documentsFolder);

getLastDocumentStatus() returns SuccessfullyProcessed, Skipped or ProcessedWithError, per document. Worth adding PasswordRequired too, since protected files are a common cause of an empty result.

If you need this after the fact rather than live, the index keeps it:

for (IndexingReport report : index.getIndexingReports()) {
    System.out.println(Arrays.toString(report.getErrors()));
    System.out.println(Arrays.toString(report.getIndexedDocuments()));
}

And when you want to settle a specific document for certain, dump what was actually extracted from it and look with your own eyes (this needs text storage enabled on the index through IndexSettings.setTextStorageSettings):

index.getDocumentText(documents[0], new FileOutputAdapter("C:\\Text.html"));

That last one is the one I would reach for first. It answers “was the word there and missed, or was it never extracted” directly, with no guessing.

2. Chart pasted from Excel into Word

Most likely no, and it depends on how the chart landed in the document.

Searching works on the plain text extracted from the file. Axis titles, series names and data labels of a Word chart are not part of the document’s text flow — they live in the chart part with its own embedded workbook. Plain text extraction does not walk into that, so a search for a label will not match. If you pasted the chart as a picture instead, the labels are pixels, and nothing short of OCR will see them; GroupDocs.Search can do that, but only if you enable OCR indexing and plug in an OCR connector via OcrIndexingOptions.

Rather than take my word for it, run the same check as above on that one document: index it, call getDocumentText, and search the output for one of your labels. Thirty seconds, and it tells you exactly what the index has to work with.

If those labels do need to be findable, the practical routes are to keep the source workbook in the indexed folder as well, or to repeat the wording in the document body — a caption under the chart, for instance.

Hope this helps.