Class SearchResult

java.lang.Object
com.tnsai.knowledge.SearchResult
All Implemented Interfaces:
Comparable<SearchResult>

public final class SearchResult extends Object implements Comparable<SearchResult>
Represents a search result from a knowledge base query.

Contains the matched document along with a relevance score. Higher scores indicate better matches.

Example usage:

 List<SearchResult> results = knowledgeBase.search("query", 5);
 for (SearchResult result : results) {
     System.out.println("Score: " + result.getScore());
     System.out.println("Content: " + result.getDocument().getContent());
 }
 
See Also:
  • Constructor Details

    • SearchResult

      public SearchResult(Document document, double score)
      Creates a new search result.
      Parameters:
      document - the matched document
      score - the relevance score (higher = more relevant)
  • Method Details

    • getDocument

      public Document getDocument()
      Gets the matched document.
      Returns:
      the document
    • getScore

      public double getScore()
      Gets the relevance score. Higher scores indicate more relevant results.
      Returns:
      the relevance score
    • getContent

      public String getContent()
      Convenience method to get the document content.
      Returns:
      the document content
    • getDocumentId

      public String getDocumentId()
      Convenience method to get the document ID.
      Returns:
      the document ID
    • compareTo

      public int compareTo(SearchResult other)
      Compares by score in descending order (highest score first).
      Specified by:
      compareTo in interface Comparable<SearchResult>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object