Class: Ragdoll::CLI::StandaloneClient
- Inherits:
-
Object
- Object
- Ragdoll::CLI::StandaloneClient
- Includes:
- DebugMe
- Defined in:
- lib/ragdoll/cli/standalone_client.rb
Instance Method Summary collapse
- #add_document(path, **options) ⇒ Object
- #add_keywords_to_document(document_id, keywords) ⇒ Object
- #cleanup_searches(**options) ⇒ Object
- #configuration ⇒ Object
- #delete_document(id) ⇒ Object
- #document_status(id) ⇒ Object
- #enhance_prompt(prompt, **options) ⇒ Object
- #fulltext_search(query, **options) ⇒ Object
- #get_context(query, **options) ⇒ Object
- #get_document(id) ⇒ Object
- #healthy? ⇒ Boolean
- #hybrid_search(query, **options) ⇒ Object
- #keyword_frequencies(limit: 100, min_count: 1) ⇒ Object
- #keyword_statistics ⇒ Object
- #list_documents(**options) ⇒ Object
- #remove_keywords_from_document(document_id, keywords) ⇒ Object
- #search(query = nil, **options) ⇒ Object
- #search_analytics(days: 30) ⇒ Object
-
#search_by_keywords(keywords, **options) ⇒ Object
Keywords-specific search methods.
- #search_by_keywords_all(keywords, **options) ⇒ Object
- #search_history(limit: 20, **options) ⇒ Object
- #set_document_keywords(document_id, keywords) ⇒ Object
- #stats ⇒ Object
- #trending_queries(limit: 10, days: 7) ⇒ Object
- #update_document(id, **options) ⇒ Object
Instance Method Details
#add_document(path, **options) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 8 def add_document(path, **) # Map force_duplicate option to force parameter for core library = .dup if .key?(:force_duplicate) [:force] = .delete(:force_duplicate) end Ragdoll.add_document(path: path, **) end |
#add_keywords_to_document(document_id, keywords) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 197 def add_keywords_to_document(document_id, keywords) begin document = Ragdoll::Document.find(document_id) Array(keywords).each { |keyword| document.add_keyword(keyword) } document.save! { success: true, keywords: document.keywords_array } rescue StandardError => e { success: false, message: e. } end end |
#cleanup_searches(**options) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 105 def cleanup_searches(**) # TODO: This will delegate to Ragdoll core when analytics are implemented if defined?(Ragdoll) && Ragdoll.respond_to?(:cleanup_searches) Ragdoll.cleanup_searches(**) else # Placeholder response for now { orphaned_count: 0, unused_count: 0 } end end |
#configuration ⇒ Object
163 164 165 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 163 def configuration Ragdoll.configuration end |
#delete_document(id) ⇒ Object
34 35 36 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 34 def delete_document(id) Ragdoll.delete_document(id: id) end |
#document_status(id) ⇒ Object
19 20 21 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 19 def document_status(id) Ragdoll.document_status(id: id) end |
#enhance_prompt(prompt, **options) ⇒ Object
58 59 60 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 58 def enhance_prompt(prompt, **) Ragdoll.enhance_prompt(prompt: prompt, **) end |
#fulltext_search(query, **options) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 120 def fulltext_search(query, **) # Perform full-text search using Document.search_content limit = [:limit] || 20 threshold = [:threshold] || 0.0 # Get full-text search results documents = Ragdoll::Document.search_content(query, **) # Format results to match expected structure results = documents.map do |doc| { document_id: doc.id.to_s, document_title: doc.title, document_location: doc.location, content: doc.content[0..500], # Preview fulltext_similarity: doc.respond_to?(:fulltext_similarity) ? doc.fulltext_similarity : nil, document_type: doc.document_type, status: doc.status } end { query: query, search_type: 'fulltext', results: results, total_results: results.length, threshold_used: threshold } rescue StandardError => e { query: query, search_type: 'fulltext', results: [], total_results: 0, error: "Full-text search failed: #{e.}" } end |
#get_context(query, **options) ⇒ Object
53 54 55 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 53 def get_context(query, **) Ragdoll.get_context(query: query, **) end |
#get_document(id) ⇒ Object
24 25 26 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 24 def get_document(id) Ragdoll.get_document(id: id) end |
#healthy? ⇒ Boolean
158 159 160 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 158 def healthy? Ragdoll.healthy? end |
#hybrid_search(query, **options) ⇒ Object
115 116 117 118 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 115 def hybrid_search(query, **) # Properly delegate to Ragdoll core's hybrid_search Ragdoll.hybrid_search(query: query, **) end |
#keyword_frequencies(limit: 100, min_count: 1) ⇒ Object
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 186 def keyword_frequencies(limit: 100, min_count: 1) if defined?(Ragdoll::Document) && Ragdoll::Document.respond_to?(:keyword_frequencies) frequencies = Ragdoll::Document.keyword_frequencies # Filter by min_count and limit filtered = frequencies.select { |_keyword, count| count >= min_count } filtered.first(limit).to_h else {} end end |
#keyword_statistics ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 248 def keyword_statistics begin total_keywords = 0 documents_with_keywords = 0 total_keyword_count = 0 keyword_frequencies = {} if defined?(Ragdoll::Document) documents_with_keywords = Ragdoll::Document.where.not(keywords: []).count Ragdoll::Document.where.not(keywords: []).find_each do |doc| doc_keywords = doc.keywords_array total_keyword_count += doc_keywords.length doc_keywords.each do |keyword| keyword_frequencies[keyword] = (keyword_frequencies[keyword] || 0) + 1 end end total_keywords = keyword_frequencies.keys.length avg_keywords_per_document = documents_with_keywords > 0 ? (total_keyword_count.to_f / documents_with_keywords) : 0 # Top 10 most common keywords top_keywords = keyword_frequencies.sort_by { |_k, v| -v }.first(10) # Count singleton keywords (used by only 1 document) singleton_keywords = keyword_frequencies.count { |_k, v| v == 1 } { total_keywords: total_keywords, documents_with_keywords: documents_with_keywords, avg_keywords_per_document: avg_keywords_per_document, top_keywords: top_keywords, singleton_keywords: singleton_keywords } else { total_keywords: 0, documents_with_keywords: 0, avg_keywords_per_document: 0, top_keywords: [], singleton_keywords: 0 } end rescue StandardError => e { total_keywords: 0, documents_with_keywords: 0, avg_keywords_per_document: 0, top_keywords: [], singleton_keywords: 0, error: e. } end end |
#list_documents(**options) ⇒ Object
39 40 41 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 39 def list_documents(**) Ragdoll.list_documents(**) end |
#remove_keywords_from_document(document_id, keywords) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 214 def remove_keywords_from_document(document_id, keywords) begin document = Ragdoll::Document.find(document_id) Array(keywords).each { |keyword| document.remove_keyword(keyword) } document.save! { success: true, keywords: document.keywords_array } rescue StandardError => e { success: false, message: e. } end end |
#search(query = nil, **options) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 44 def search(query = nil, **) if query Ragdoll.search(query: query, **) else Ragdoll.search(**) end end |
#search_analytics(days: 30) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 67 def search_analytics(days: 30) # TODO: This will delegate to Ragdoll core when analytics are implemented if defined?(Ragdoll) && Ragdoll.respond_to?(:search_analytics) Ragdoll.search_analytics(days: days) else # Placeholder response for now { total_searches: 0, unique_queries: 0, avg_results_per_search: 0.0, avg_execution_time: 0.0, search_types: {}, searches_with_results: 0, avg_click_through_rate: 0.0 } end end |
#search_by_keywords(keywords, **options) ⇒ Object
Keywords-specific search methods
168 169 170 171 172 173 174 175 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 168 def search_by_keywords(keywords, **) if defined?(Ragdoll::Document) && Ragdoll::Document.respond_to?(:search_by_keywords) Ragdoll::Document.search_by_keywords(keywords, **).map(&:to_hash) else # Fallback to regular search with keywords filter search(keywords: keywords, **) end end |
#search_by_keywords_all(keywords, **options) ⇒ Object
177 178 179 180 181 182 183 184 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 177 def search_by_keywords_all(keywords, **) if defined?(Ragdoll::Document) && Ragdoll::Document.respond_to?(:search_by_keywords_all) Ragdoll::Document.search_by_keywords_all(keywords, **).map(&:to_hash) else # Fallback to regular search with keywords filter search(keywords: keywords, **) end end |
#search_history(limit: 20, **options) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 85 def search_history(limit: 20, **) # TODO: This will delegate to Ragdoll core when analytics are implemented if defined?(Ragdoll) && Ragdoll.respond_to?(:search_history) Ragdoll.search_history(limit: limit, **) else # Placeholder response for now [] end end |
#set_document_keywords(document_id, keywords) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 231 def set_document_keywords(document_id, keywords) begin document = Ragdoll::Document.find(document_id) document.keywords = Array(keywords) document.save! { success: true, keywords: document.keywords_array } rescue StandardError => e { success: false, message: e. } end end |
#stats ⇒ Object
63 64 65 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 63 def stats Ragdoll.stats end |
#trending_queries(limit: 10, days: 7) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 95 def trending_queries(limit: 10, days: 7) # TODO: This will delegate to Ragdoll core when analytics are implemented if defined?(Ragdoll) && Ragdoll.respond_to?(:trending_queries) Ragdoll.trending_queries(limit: limit, days: days) else # Placeholder response for now [] end end |
#update_document(id, **options) ⇒ Object
29 30 31 |
# File 'lib/ragdoll/cli/standalone_client.rb', line 29 def update_document(id, **) Ragdoll.update_document(id: id, **) end |