Skip to content

Instantly share code, notes, and snippets.

@erikhatcher
erikhatcher / run_demos.js
Created April 25, 2026 12:37
Search Views
// mongosh $MONGODB_URI run_demos.js
array_size_demo = {
description: "Enriching the index with the size of an array.",
docs: [
{
_id: 1,
values: [1,2,3,4]
},
{
@erikhatcher
erikhatcher / common.js
Last active March 23, 2026 11:35
B-Tree vs. search index intersection
const NUM_DOCS = 20000000;
const NUM_REPS = 50;
use('demo'); // TODO
collection = db.demo; // TODO
function get_pipeline_stats(pipeline) {
start = performance.now();
cursor = db.demo.aggregate(pipeline);
end = performance.now();
@erikhatcher
erikhatcher / LuceneExamples.java
Created December 3, 2013 19:31
Lucene Examples for The Rich Web Experience 2013
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.codecs.simpletext.SimpleTextCodec;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
@erikhatcher
erikhatcher / update-script.js
Created September 13, 2013 14:02
Splitting key1:value1;key2:value2 strings from an incoming field and making them individual fields
function processAdd(cmd) {
doc = cmd.solrDoc; // org.apache.solr.common.SolrInputDocument
id = doc.getFieldValue("id");
logger.info("update-script#processAdd: id=" + id);
kvString = doc.removeField("kv").getValue();
kvs = kvString.split(";");
for(i=0; i < kvs.length; i++) {
kv = kvs[i].split(":");
doc.setField(kv[0] + "_s", kv[1]);