The get_combined_text() Method
The get_combined_text() Method
The get_combined_text() method is a high-level utility designed to quickly retrieve and aggregate search data into a single, human-readable string. This method is particularly useful for generating context for LLMs (Large Language Models), creating summaries, or displaying quick search previews without manually parsing JSON responses.
Syntax
get_combined_text(query)
Parameters
| Parameter | Type | Description |
| :--- | :--- | :--- |
| query | str | The search term or phrase you want to look up on the web. |
Return Value
- Type:
str - Description: Returns a formatted string containing the top 5 results. Each result includes the index number, page title, a brief snippet of content, and the source URL. If no results are found, it returns an empty string.
Usage Example
To use this method, initialize the Eternity class with your Google API credentials and call get_combined_text() with your desired search query.
from eternity.eternity import Eternity
# Initialize the client
client = Eternity(api_key="YOUR_GOOGLE_API_KEY", engine_id="YOUR_ENGINE_ID")
# Retrieve formatted results
search_summary = client.get_combined_text("Python real-time data retrieval")
print(search_summary)
Example Output:
Result 1:
Title: How to retrieve real-time data in Python
Snippet: Learn the best libraries for fetching live data from the web...
URL: https://example.com/python-data
Result 2:
Title: Eternity: Real-time Web Search Library
Snippet: Eternity is a Python library for real-time data retrieval...
URL: https://github.com/UditAkhourii/Eternity
...
Key Features
- Automatic Formatting: No need to iterate through result dictionaries; the method handles the layout for you.
- Optimized for Context: It automatically limits results to the top 5 most relevant items to keep the output concise and manageable.
- Error Handling: If the underlying search fails or the API returns an error, the method gracefully returns an empty string or the partial results successfully retrieved.