-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Todo: Remove extraneous dependencies from core/project.json once dapper point the correct versions
- Loading branch information
1 parent
b3c83fd
commit c146d96
Showing
32 changed files
with
519 additions
and
391 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,6 @@ artifacts | |
*.vsp | ||
project.lock.json | ||
*.mdb | ||
.vs/ | ||
.build/ | ||
.vs/ | ||
.build/ | ||
.testPublish/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ static void Main(string[] args) | |
|
||
|
||
session.Save(bill); | ||
|
||
} | ||
|
||
using (var session = _store.CreateSession()) | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
//using YesSql.Core.Indexes; | ||
using YesSql.Core.Indexes; | ||
|
||
//namespace YesSql.Samples.FullText.Indexes | ||
//{ | ||
// public class ArticleByWord : ReduceIndex | ||
// { | ||
// public string Word { get; set; } | ||
// public int Count { get; set; } | ||
// } | ||
//} | ||
namespace YesSql.Samples.FullText.Indexes | ||
{ | ||
public class ArticleByWord : ReduceIndex | ||
{ | ||
public string Word { get; set; } | ||
public int Count { get; set; } | ||
} | ||
} |
65 changes: 33 additions & 32 deletions
65
samples/YesSql.Samples.FullText/Indexes/ArticleIndexProvider.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
//using System.Linq; | ||
//using YesSql.Core.Indexes; | ||
//using YesSql.Samples.FullText.Models; | ||
//using YesSql.Samples.FullText.Tokenizers; | ||
using System.Linq; | ||
using YesSql.Core.Indexes; | ||
using YesSql.Samples.FullText.Models; | ||
using YesSql.Samples.FullText.Tokenizers; | ||
|
||
//namespace YesSql.Samples.FullText.Indexes | ||
//{ | ||
// public class ArticleIndexProvider : IndexProvider<Article> | ||
// { | ||
// public override void Describe(DescribeContext<Article> context) | ||
// { | ||
// var tokenizer = new WhiteSpaceTokenizer(); | ||
// var filter = new StopWordFilter(); | ||
namespace YesSql.Samples.FullText.Indexes | ||
{ | ||
public class ArticleIndexProvider : IndexProvider<Article> | ||
{ | ||
public override void Describe(DescribeContext<Article> context) | ||
{ | ||
var tokenizer = new WhiteSpaceTokenizer(); | ||
var filter = new StopWordFilter(); | ||
|
||
// // for each BlogPost, create a BlogPostByAuthor index | ||
// context.For<ArticleByWord, string>() | ||
// .Map(article => filter | ||
// .Filter(tokenizer.Tokenize(article.Content)) | ||
// .Select(x => new ArticleByWord {Word = x, Count = 1}) | ||
// ) | ||
// .Group(article => article.Word) | ||
// .Reduce(group => new ArticleByWord | ||
// { | ||
// Word = group.Key, | ||
// Count = group.Sum(y => y.Count) | ||
// }) | ||
// .Delete((index, map) => { | ||
// index.Count -= map.Sum(x => x.Count); | ||
// for each BlogPost, create a BlogPostByAuthor index | ||
context.For<ArticleByWord, string>() | ||
.Map(article => filter | ||
.Filter(tokenizer.Tokenize(article.Content)) | ||
.Select(x => new ArticleByWord { Word = x, Count = 1 }) | ||
) | ||
.Group(article => article.Word) | ||
.Reduce(group => new ArticleByWord | ||
{ | ||
Word = group.Key, | ||
Count = group.Sum(y => y.Count) | ||
}) | ||
.Delete((index, map) => | ||
{ | ||
index.Count -= map.Sum(x => x.Count); | ||
// // if Count == 0 then delete the index | ||
// return index.Count > 0 ? index : null; | ||
// }); | ||
// } | ||
// } | ||
//} | ||
// if Count == 0 then delete the index | ||
return index.Count > 0 ? index : null; | ||
}); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
//namespace YesSql.Samples.FullText.Models | ||
//{ | ||
// public class Article | ||
// { | ||
// public string Content { get; set; } | ||
// } | ||
//} | ||
namespace YesSql.Samples.FullText.Models | ||
{ | ||
public class Article | ||
{ | ||
public string Content { get; set; } | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,65 @@ | ||
//using System; | ||
//using YesSql.Samples.FullText.Indexes; | ||
//using YesSql.Samples.FullText.Models; | ||
//using YesSql.Core.Services; | ||
//using System.Data.SQLite; | ||
//using YesSql.Core.Storage.InMemory; | ||
|
||
//namespace YesSql.Samples.FullText | ||
//{ | ||
// internal class Program | ||
// { | ||
// private static void Main(string[] args) | ||
// { | ||
// var store = new Store(cfg => | ||
// { | ||
// cfg.ConnectionFactory = new DbConnectionFactory<SQLiteConnection>(@"Data Source=:memory:", true); | ||
// cfg.DocumentStorageFactory = new InMemoryDocumentStorageFactory(); | ||
|
||
// cfg.Migrations.Add(builder => builder | ||
// .CreateReduceIndexTable(nameof(ArticleByWord), table => table | ||
// .Column<int>("Count") | ||
// .Column<string>("Word") | ||
// ) | ||
// ); | ||
// }); | ||
|
||
// // register available indexes | ||
// store.RegisterIndexes<ArticleIndexProvider>(); | ||
|
||
// // creating articles | ||
// using (var session = store.CreateSession()) | ||
// { | ||
// session.Save(new Article {Content = "This is a white fox"}); | ||
// session.Save(new Article {Content = "This is a brown cat"}); | ||
// session.Save(new Article {Content = "This is a pink elephant"}); | ||
// session.Save(new Article {Content = "This is a white tiger"}); | ||
// } | ||
|
||
// using (var session = store.CreateSession()) | ||
// { | ||
// Console.WriteLine("Simple term: 'white'"); | ||
// var simple = session.QueryAsync<Article, ArticleByWord>().Where(a => a.Word == "white").List().Result; | ||
|
||
// foreach (var article in simple) { | ||
// Console.WriteLine(article.Content); | ||
// } | ||
|
||
// Console.WriteLine("Boolean query: 'white or fox or pink'"); | ||
// var boolQuery = session.QueryAsync<Article, ArticleByWord>().Where(a => a.Word.IsIn(new [] { "white", "fox", "pink" })).List().Result; | ||
|
||
// foreach (var article in boolQuery) | ||
// { | ||
// Console.WriteLine(article.Content); | ||
// } | ||
// } | ||
// } | ||
// } | ||
//} | ||
using System; | ||
using Microsoft.Data.Sqlite; | ||
using YesSql.Core.Services; | ||
using YesSql.Samples.FullText.Indexes; | ||
using YesSql.Samples.FullText.Models; | ||
using YesSql.Storage.InMemory; | ||
|
||
namespace YesSql.Samples.FullText | ||
{ | ||
internal class Program | ||
{ | ||
private static void Main(string[] args) | ||
{ | ||
var store = new Store(cfg => | ||
{ | ||
cfg.ConnectionFactory = new DbConnectionFactory<SqliteConnection>(@"Data Source=:memory:", true); | ||
cfg.DocumentStorageFactory = new InMemoryDocumentStorageFactory(); | ||
}); | ||
|
||
store.InitializeAsync().Wait(); | ||
|
||
using (var session = store.CreateSession()) | ||
{ | ||
session.ExecuteMigration(x => x | ||
.CreateReduceIndexTable(nameof(ArticleByWord), table => table | ||
.Column<int>("Count") | ||
.Column<string>("Word") | ||
) | ||
); | ||
} | ||
|
||
// register available indexes | ||
store.RegisterIndexes<ArticleIndexProvider>(); | ||
|
||
// creating articles | ||
using (var session = store.CreateSession()) | ||
{ | ||
session.Save(new Article { Content = "This is a white fox" }); | ||
session.Save(new Article { Content = "This is a brown cat" }); | ||
session.Save(new Article { Content = "This is a pink elephant" }); | ||
session.Save(new Article { Content = "This is a white tiger" }); | ||
} | ||
|
||
using (var session = store.CreateSession()) | ||
{ | ||
Console.WriteLine("Simple term: 'white'"); | ||
var simple = session.QueryAsync<Article, ArticleByWord>().Where(a => a.Word == "white").List().Result; | ||
|
||
foreach (var article in simple) | ||
{ | ||
Console.WriteLine(article.Content); | ||
} | ||
|
||
Console.WriteLine("Boolean query: 'white or fox or pink'"); | ||
var boolQuery = session.QueryAsync<Article, ArticleByWord>().Where(a => a.Word.IsIn(new[] { "white", "fox", "pink" })).List().Result; | ||
|
||
foreach (var article in boolQuery) | ||
{ | ||
Console.WriteLine(article.Content); | ||
} | ||
} | ||
} | ||
} | ||
} |
21 changes: 11 additions & 10 deletions
21
samples/YesSql.Samples.FullText/Tokenizers/ITokenFilter.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
//using System; | ||
//using System.Collections.Generic; | ||
//using System.Linq; | ||
//using System.Text; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
//namespace YesSql.Samples.FullText.Tokenizers { | ||
// public interface ITokenFilter | ||
// { | ||
// IEnumerable<string> Filter(IEnumerable<string> tokens); | ||
// } | ||
//} | ||
namespace YesSql.Samples.FullText.Tokenizers | ||
{ | ||
public interface ITokenFilter | ||
{ | ||
IEnumerable<string> Filter(IEnumerable<string> tokens); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
//using System.Collections.Generic; | ||
using System.Collections.Generic; | ||
|
||
//namespace YesSql.Samples.FullText.Tokenizers { | ||
// public interface ITokenizer | ||
// { | ||
// IEnumerable<string> Tokenize(string text); | ||
// } | ||
//} | ||
namespace YesSql.Samples.FullText.Tokenizers | ||
{ | ||
public interface ITokenizer | ||
{ | ||
IEnumerable<string> Tokenize(string text); | ||
} | ||
} |
24 changes: 12 additions & 12 deletions
24
samples/YesSql.Samples.FullText/Tokenizers/StopWordFilter.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
//using System.Collections.Generic; | ||
//using System.Linq; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
//namespace YesSql.Samples.FullText.Tokenizers | ||
//{ | ||
// public class StopWordFilter : ITokenFilter | ||
// { | ||
// public IEnumerable<string> Filter(IEnumerable<string> tokens) | ||
// { | ||
// return tokens.Where(token => token.Length >= 2); | ||
// } | ||
// } | ||
//} | ||
namespace YesSql.Samples.FullText.Tokenizers | ||
{ | ||
public class StopWordFilter : ITokenFilter | ||
{ | ||
public IEnumerable<string> Filter(IEnumerable<string> tokens) | ||
{ | ||
return tokens.Where(token => token.Length >= 2); | ||
} | ||
} | ||
} |
Oops, something went wrong.