Created
November 21, 2015 09:20
-
-
Save ayende/41cecb9c22dea778e80f to your computer and use it in GitHub Desktop.
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
private static User FindUser(DocumentStore docStore, string query) | |
{ | |
using (var session = docStore.OpenSession()) | |
{ | |
var q = session.Query<User>("Users/Search") | |
.Search(x=>x.Name, query); | |
var user = q.FirstOrDefault(); | |
if (user != null) | |
return user; | |
var suggest = q.Suggest(); | |
switch (suggest.Suggestions.Length) | |
{ | |
case 0: | |
return null; | |
case 1: | |
return FindUser(docStore, suggest.Suggestions[0]); | |
default: | |
Console.WriteLine("Did you mean " + | |
string.Join(", ", suggest.Suggestions)); | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment