Skip to content

Instantly share code, notes, and snippets.

@krcourville
Created April 27, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krcourville/bb6e19ae2797a800edab to your computer and use it in GitHub Desktop.
Save krcourville/bb6e19ae2797a800edab to your computer and use it in GitHub Desktop.
CouchBase Lite Prefix Saerch Issue
const string myprop = "myprop";
const string myvalue = "myvalue";
var manager = new Manager(new System.IO.DirectoryInfo(@"C:\temp\cbldb"), ManagerOptions.Default);
var db = manager.GetDatabase("test");
var newdoc = db.CreateDocument();
var props = new Dictionary<string, object>
{
{myprop, myvalue }
};
var rev = newdoc.PutProperties(props);
Debug.Assert(rev != null);
//
// View: [assetTagNumber]
var view = db.GetView("view1");
view.SetMap((doc, emit) =>
{
emit(doc[myprop], null);
}, "201");
Console.WriteLine("Refreshing view");
view.CreateQuery().Run().MoveNext();
Console.WriteLine("View refesh done");
Console.WriteLine("Query view...");
var myquery = view.CreateQuery();
//string prefix = myvalue; // this outputs results
string prefix = myvalue.Substring(0, myvalue.Length - 1); // this does NOT output results
const string highUnicodeChar = "\uFFFE";
myquery.StartKey = prefix;
myquery.EndKey = prefix + highUnicodeChar;
Console.WriteLine("Going to search for items with key in the range of: {0} - {1}", myquery.StartKey, myquery.EndKey);
myquery.Prefetch = true;
foreach (var item in myquery.Run())
{
Console.WriteLine("DocumentId: {0}; myprop: {1}",
item.DocumentId,
item.DocumentProperties[myprop]
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment