Created
April 27, 2015 14:23
-
-
Save krcourville/bb6e19ae2797a800edab to your computer and use it in GitHub Desktop.
CouchBase Lite Prefix Saerch Issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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