find_documents_by_content
Search RSpace documents by content terms using AND/OR operators, with options to exclude terms, sort results, and control page size.
Instructions
Advanced content-based document search
Usage: Find documents containing specific content terms
Parameters:
content_terms: List of terms that should appear in document content
operator: "and" (all terms must appear) or "or" (any term can appear)
exclude_terms: Optional list of terms to exclude from results
order_by: Sort results by field
page_size: Number of results to return
Returns: Dictionary with search results
Example: find_documents_by_content(["DNA", "extraction"], operator="and")
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content_terms | Yes | ||
| operator | No | and | |
| exclude_terms | No | ||
| order_by | No | lastModified desc | |
| page_size | No |
Implementation Reference
- main.py:355-404 (handler)The handler function for the 'find_documents_by_content' MCP tool. It uses RSpace's AdvancedQueryBuilder for full-text search on document content with support for AND/OR operators and post-query exclusion filtering on document metadata.@mcp.tool(tags={"rspace", "search"}) def find_documents_by_content( content_terms: List[str], operator: Literal["and", "or"] = "and", exclude_terms: List[str] = None, order_by: str = "lastModified desc", page_size: int = 20 ) -> dict: """ Advanced content-based document search Usage: Find documents containing specific content terms Parameters: - content_terms: List of terms that should appear in document content - operator: "and" (all terms must appear) or "or" (any term can appear) - exclude_terms: Optional list of terms to exclude from results - order_by: Sort results by field - page_size: Number of results to return Returns: Dictionary with search results Example: find_documents_by_content(["DNA", "extraction"], operator="and") """ builder = AdvancedQueryBuilder(operator=operator) for term in content_terms: builder.add_term(term, AdvancedQueryBuilder.QueryType.FULL_TEXT) # Note: RSpace API doesn't directly support exclusion, but we can filter results advanced_query = builder.get_advanced_query() results = eln_cli.get_documents_advanced_query( advanced_query=advanced_query, order_by=order_by, page_number=0, page_size=page_size ) # Filter out documents containing excluded terms if specified if exclude_terms and 'documents' in results: filtered_docs = [] for doc in results['documents']: # Check if any exclude terms are in the document name or other available text doc_text = (doc.get('name', '') + ' ' + doc.get('tags', '')).lower() if not any(exclude_term.lower() in doc_text for exclude_term in exclude_terms): filtered_docs.append(doc) results['documents'] = filtered_docs results['totalHits'] = len(filtered_docs) return results