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
|
# File 'lib/glancer/indexer/context_indexer.rb', line 8
def index!
Glancer::Utils::Logger.info("Indexer::ContextIndexer", "Starting context indexing...")
path = Glancer.configuration.context_file_path
if path.nil? || !File.exist?(path)
Glancer::Utils::Logger.error("Indexer::ContextIndexer", "Context file not found at path: #{path.inspect}")
raise Glancer::Error, "Context file not found. Expected at: #{path.inspect}"
end
Glancer::Utils::Logger.debug("Indexer::ContextIndexer", "Reading context file from: #{path}")
content = File.read(path)
Glancer::Utils::Logger.debug("Indexer::ContextIndexer", "Read #{content.bytesize} bytes from context file")
if content.lines.first&.strip == "--glancer-ignore"
Glancer::Utils::Logger.info("Indexer::ContextIndexer",
"Context file marked with --glancer-ignore, skipping indexing.")
return []
end
chunks = split_into_chunks(content)
Glancer::Utils::Logger.info("Indexer::ContextIndexer", "Split content into #{chunks.size} chunk(s)")
chunks.map do |chunk|
{
content: chunk,
source_type: "context",
source_path: path
}
end
rescue StandardError => e
Glancer::Utils::Logger.error("Indexer::ContextIndexer",
"Failed to index context: #{e.class} - #{e.message}")
Glancer::Utils::Logger.debug("Indexer::ContextIndexer", "Backtrace:\n#{e.backtrace.join("\n")}")
raise Glancer::Error, "Context indexing failed: #{e.message}"
end
|