Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

docs: Add docstrings to `process_batch` and `run_indexing`, update README with workflow details

thiswillbeyourgithub (aider)7420378e3283
diff --git a/mwmbl/crawl.py b/mwmbl/crawl.py
index f674ccc..64a900d 100644
--- a/mwmbl/crawl.py
+++ b/mwmbl/crawl.py
@@ -83,6 +83,18 @@ def process_batch_continuously():
def process_batch():
+ """
+ Process a single batch of URLs by crawling them sequentially with rate limiting.
+
+ This function handles the core crawling workflow:
+ 1. Gets a batch of URLs from the Redis URL queue
+ 2. Crawls each URL sequentially with configurable delay between requests
+ 3. Records crawl results in the database for URL tracking
+ 4. Pushes the completed batch to Redis queue for indexing
+
+ The sequential crawling with delays respects rate limits and reduces load on target servers.
+ Each batch is processed as a HashedBatch object containing metadata and crawl results.
+ """
user_id = "test"
urls = url_queue.get_batch(user_id)
logger.info(f"Processing batch of {len(urls)} URLs")
@@ -117,6 +129,22 @@ def run_indexing_continuously():
def run_indexing():
+ """
+ Process completed crawl batches and integrate results into the search index.
+
+ This function handles the indexing workflow:
+ 1. Pulls completed crawl batches from Redis queue (up to 10 at once)
+ 2. Indexes batches locally using the tiny search engine indexer
+ 3. For top terms, syncs high-scoring local results with the remote Mwmbl index
+ 4. Downloads updated remote results and merges them back into local index
+
+ The sync process ensures that high-quality local crawl results get submitted
+ to the main Mwmbl search index, while also keeping the local index updated
+ with the latest remote results for better search quality.
+
+ Only results that score higher than existing remote results are submitted,
+ preventing low-quality content from polluting the main index.
+ """
index_path = data_path / settings.INDEX_NAME
batch_jsons = redis.lpop(BATCH_QUEUE_KEY, 10)
if batch_jsons is None:
diff --git a/mwmbl/crawler/README.md b/mwmbl/crawler/README.md
index 69c2c82..051b713 100644
--- a/mwmbl/crawler/README.md
+++ b/mwmbl/crawler/README.md
@@ -90,6 +90,33 @@ Real-time monitoring data:
- Domain link relationships for scoring
- Error rates and success metrics
+### Batch Processing Workflow
+
+The **batch processing** handles the actual web crawling work:
+
+1. **URL Assignment**: Gets batches of URLs from the Redis URL queue
+2. **Sequential Crawling**: Crawls each URL one-by-one with configurable delays between requests (respects rate limits)
+3. **Content Extraction**: Uses justext library to extract clean text content and discover new links
+4. **Result Recording**: Records crawl results in database for URL tracking and deduplication
+5. **Queue Handoff**: Pushes completed batches to Redis queue for the indexing process
+
+Each batch is processed as a `HashedBatch` object containing metadata (user ID, timestamp) and an array of crawl results (URL, title, extract, links, errors).
+
+### Indexing Workflow
+
+The **indexing process** transforms crawl results into searchable content:
+
+1. **Batch Retrieval**: Pulls completed crawl batches from Redis queue (processes up to 10 batches at once)
+2. **Local Indexing**: Uses the tiny search engine indexer to build local search index from crawl results
+3. **Quality Filtering**: For high-activity search terms, compares local results against the remote Mwmbl index
+4. **Selective Sync**: Only submits local results that score higher than existing remote results (prevents low-quality content pollution)
+5. **Remote Integration**: Downloads updated remote results and merges them back into local index
+
+This two-stage process ensures that:
+- High-quality crawl results reach the main Mwmbl search index
+- Local crawlers maintain up-to-date search indexes
+- The main index maintains quality standards through score-based filtering
+
### Community-Driven Approach
The distributed nature allows the crawler to: