public class SearchResult extends Object implements Iterable<FoundDocument>
Learn more
The example demonstrates a typical usage of the class.
String indexFolder = "c:\\MyIndex\\";
String documentFolder = "c:\\MyDocuments\\";
// Creating an index
Index index = new Index(indexFolder);
// Indexing documents from the specified folder
index.add(documentFolder);
// Setting search options
SearchOptions options = new SearchOptions();
options.getFuzzySearch().setEnabled(true); // Enabling the fuzzy search
options.getFuzzySearch().setFuzzyAlgorithm(new TableDiscreteFunction(3)); // Setting the maximum number of differences to 3
// Search for documents containing the word 'Einstein' or the phrase 'Theory of Relativity'
SearchResult result = index.search("Einstein OR \"Theory of Relativity\"", options);
// Printing the result
System.out.println("Documents: " + result.getDocumentCount());
System.out.println("Total occurrences: " + result.getOccurrenceCount());
for (int i = 0; i < result.getDocumentCount(); i++) {
FoundDocument document = result.getFoundDocument(i);
System.out.println("\tDocument: " + document.getDocumentInfo().getFilePath());
System.out.println("\tOccurrences: " + document.getOccurrenceCount());
for (int j = 0; j < document.getFoundFields().length; j++) {
FoundDocumentField field = document.getFoundFields()[j];
System.out.println("\t\tField: " + field.getFieldName());
System.out.println("\t\tOccurrences: " + document.getOccurrenceCount());
// Printing found terms
if (field.getTerms() != null) {
for (int k = 0; k < field.getTerms().length; k++) {
System.out.println("\t\t\t" + field.getTerms()[k] + " - " + field.getTermsOccurrences()[k]);
}
}
// Printing found phrases
if (field.getTermSequences() != null) {
for (int k = 0; k < field.getTermSequences().length; k++) {
String[] terms = field.getTermSequences()[k];
String sequence = "";
for (int m = 0; m < terms.length; m++) {
sequence += terms[m] + " ";
}
System.out.println("\t\t\t" + sequence + " - " + field.getTermSequencesOccurrences()[k]);
}
}
}
}
Modifier | Constructor and Description |
---|---|
protected |
SearchResult(FoundDocument[] documents,
boolean truncated,
String warnings,
ChunkSearchToken nextChunkSearchToken,
boolean ignoreLicenseRestrictions)
Initializes a new instance of the
SearchResult class. |
Modifier and Type | Method and Description |
---|---|
protected static void |
appendWarning(SearchResult searchResult,
String warning) |
protected static SearchResult |
create(FoundDocument[] documents,
boolean truncated,
String warnings,
ChunkSearchToken nextChunkSearchToken,
boolean ignoreLicenseRestrictions) |
int |
getDocumentCount()
Gets the number of documents found.
|
Date |
getEndTime()
Gets the end time of the search.
|
FoundDocument |
getFoundDocument(int index)
Gets the found document by index.
|
ChunkSearchToken |
getNextChunkSearchToken()
Gets a chunk search token for searching the next chunk.
|
int |
getOccurrenceCount()
Gets the total number of occurrences found.
|
double |
getSearchDuration()
Gets the search duration in seconds.
|
Date |
getStartTime()
Gets the start time of the search.
|
boolean |
getTruncated()
Gets a value indicating that the result is truncated.
|
String |
getWarnings()
Gets a warnings describing the result.
|
Iterator<FoundDocument> |
iterator()
Returns an iterator that iterates through the collection of the documents found.
|
protected static void |
setTime(SearchResult searchResult,
com.aspose.ms.System.DateTime startTime,
com.aspose.ms.System.DateTime endTime) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
protected SearchResult(FoundDocument[] documents, boolean truncated, String warnings, ChunkSearchToken nextChunkSearchToken, boolean ignoreLicenseRestrictions)
Initializes a new instance of the SearchResult
class.
documents
- The found documents.truncated
- The value indicating that results are truncated.warnings
- The warnings describing the results.nextChunkSearchToken
- The next chunk search token.ignoreLicenseRestrictions
- Is license restriction can be ignored.public final int getDocumentCount()
Gets the number of documents found.
public final int getOccurrenceCount()
Gets the total number of occurrences found.
public final boolean getTruncated()
Gets a value indicating that the result is truncated.
public final String getWarnings()
Gets a warnings describing the result.
public final ChunkSearchToken getNextChunkSearchToken()
Gets a chunk search token for searching the next chunk.
public final Date getStartTime()
Gets the start time of the search.
public final Date getEndTime()
Gets the end time of the search.
public final double getSearchDuration()
Gets the search duration in seconds.
public final FoundDocument getFoundDocument(int index)
Gets the found document by index.
index
- The index of a found document.public final Iterator<FoundDocument> iterator()
Returns an iterator that iterates through the collection of the documents found.
iterator
in interface Iterable<FoundDocument>
protected static SearchResult create(FoundDocument[] documents, boolean truncated, String warnings, ChunkSearchToken nextChunkSearchToken, boolean ignoreLicenseRestrictions)
protected static void appendWarning(SearchResult searchResult, String warning)
protected static void setTime(SearchResult searchResult, com.aspose.ms.System.DateTime startTime, com.aspose.ms.System.DateTime endTime)