-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsearch_examples.py
More file actions
107 lines (92 loc) · 2.73 KB
/
Copy pathsearch_examples.py
File metadata and controls
107 lines (92 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3
"""
Alfresco Search API Examples
This file demonstrates how to use the Search API with the master client.
"""
import sys
import os
from python_alfresco_api import ClientFactory
def main():
"""Search API examples."""
print("🔍 Search API Examples")
# Initialize client
factory = ClientFactory(base_url="http://localhost:8080", username="admin", password="admin")
client = factory.create_master_client()
if not client.search:
print("❌ Search API not available")
return
# Example 1: Basic search
print("\n1. Basic content search...")
search_request = {
'query': {
'query': 'cm:name:*',
'language': 'afts'
},
'paging': {
'maxItems': 10
}
}
try:
results = client.search.search(search_request=search_request)
if results and hasattr(results, 'list'):
print(f"✅ Found {len(results.list.entries)} results")
else:
print("✅ Search completed (results format may vary)")
except Exception as e:
print(f"❌ Search failed: {e}")
# Example 2: Search by content type
print("\n2. Search by content type...")
type_search = {
'query': {
'query': 'TYPE:"cm:content"',
'language': 'afts'
},
'paging': {
'maxItems': 5
}
}
try:
results = client.search.search(search_request=type_search)
print("✅ Content type search completed")
except Exception as e:
print(f"❌ Type search failed: {e}")
# Example 3: Search with filters
print("\n3. Search with date filter...")
filtered_search = {
'query': {
'query': 'TYPE:"cm:content"',
'language': 'afts'
},
'filterQueries': [
{'query': 'cm:modified:[NOW-7DAYS TO NOW]'}
],
'paging': {
'maxItems': 10
}
}
try:
results = client.search.search(search_request=filtered_search)
print("✅ Filtered search completed")
except Exception as e:
print(f"❌ Filtered search failed: {e}")
# Example 4: Search with sorting
print("\n4. Search with sorting...")
sorted_search = {
'query': {
'query': '*',
'language': 'afts'
},
'sort': [
{'field': 'cm:modified', 'ascending': False}
],
'paging': {
'maxItems': 5
}
}
try:
results = client.search.search(search_request=sorted_search)
print("✅ Sorted search completed")
except Exception as e:
print(f"❌ Sorted search failed: {e}")
if __name__ == "__main__":
main()