Skip to content

Instantly share code, notes, and snippets.

using (var documentStore = new DocumentStore { Url = "http://localhost:8080" })
{
documentStore.Initialise();
using (var session = documentStore.OpenSession())
{
//Only add the index if there are not posts in the database, i.e. the 1st time this is run!!
if (session.Query<Post>().Count() == 0)
{
Console.WriteLine("First time usage, creating indexes");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;
using System.Linq.Expressions;
using System.Diagnostics;
namespace Raven.Client.Tests.Document
{
@mattwarren
mattwarren / gist:990623
Created May 25, 2011 08:58
Array patching with RavenDB
using (var store = NewDocumentStore())
{
using (var s = store.OpenSession())
{
s.Store(new Post
{
//Create an empty list that we can add items to later
Comments = new List<Comment>()
});
s.SaveChanges();
@mattwarren
mattwarren / gist:1056231
Created June 30, 2011 13:27
Lucene string compare bug
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Threading;
using Lucene.Net.Analysis;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;
@mattwarren
mattwarren / gist:1056242
Created June 30, 2011 13:31
StartsWidth Locale issues
public static void RunSnippet()
{
var wholeString = "daab";
var prefix = "da";
WL("{0}.StartsWith({1}) = {2}", wholeString, prefix, wholeString.StartsWith(prefix));
WL("{0}.StartsWith({1}, StringComparision.InvariantCulture) = {2}", wholeString, prefix,
wholeString.StartsWith(prefix, StringComparison.InvariantCulture));
WL("-------------------------");
@mattwarren
mattwarren / gist:1063112
Created July 4, 2011 09:08
Wildcards with keyword analyser
static void Main(string[] args)
{
var dir = new RAMDirectory();
var analyzer = new KeywordAnalyzer();
var writer = new IndexWriter(dir, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);
var fields = new[]
{
"MRS. SHABA", "MRS. SHABA", "MRS. SMITH",
@mattwarren
mattwarren / gist:1214297
Created September 13, 2011 16:53
Faceted search SO example
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using Raven.Abstractions.Data;
using Raven.Abstractions.Indexing;
using Raven.Client;
using Raven.Client.Linq;
@mattwarren
mattwarren / gist:1265715
Created October 5, 2011 20:59
Facets and analyzed test
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using Raven.Abstractions.Data;
using Raven.Abstractions.Indexing;
using Raven.Client;
using Raven.Client.Linq;
using Raven.Client.Indexes;
@mattwarren
mattwarren / gist:1272883
Created October 8, 2011 21:13
Json Bson Benchmarks for RavenDB
var numItems = 100000;
var dictionary = new Dictionary<string, Foo>(numItems);
for (int i = 0; i < numItems; i++)
{
var foo = new Foo { Id = "foo/" + i.ToString(), Counter = i + 1, Data = "Some Data " + i.ToString() };
dictionary.Add(foo.Id, foo);
}
var timer = Stopwatch.StartNew();
var jsonObj = RavenJObject.FromObject(dictionary);
@mattwarren
mattwarren / gist:1369941
Created November 16, 2011 12:12
Querying dictionaries in RavenDB
private static void DictionaryTest()
{
var store = new EmbeddableDocumentStore
{
RunInMemory = true
};
store.Configuration.TempIndexPromotionMinimumQueryCount = 1;
store.Initialize();
var entry1 = new ClassWithDictionary { Name = "With test", Dictionary = new Dictionary<string, string> { { "test", "value" } } };
var entry2 = new ClassWithDictionary { Name = "Without test", Dictionary = new Dictionary<string, string> { { "nottest", "value" } } };