Last active
August 4, 2016 20:39
-
-
Save sleslie321/9bd572c7072ece6baa38ac18f8d35818 to your computer and use it in GitHub Desktop.
Use Examine to index and search any data source.
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Simple.Data; | |
using Examine.LuceneEngine; | |
using Examine; | |
namespace custom.indexers | |
{ | |
public class CustomDataService : ISimpleDataService | |
{ | |
public CustomDataService() { } | |
public IEnumerable<SimpleDataSet> GetAllData(string indexType) | |
{ | |
List<SimpleDataSet> data = new List<SimpleDataSet>(); | |
var db = Database.OpenNamedConnection("sqlConnection"); | |
///The Sql Database has a table call BookTable | |
/// Structure is: | |
/// ID int | |
/// Title varchar(50) | |
/// Author varchar(50) | |
List<Book> Books = db.BookTable.All(); | |
foreach (Book book in Books) | |
{ | |
data.Add(new SimpleDataSet() | |
{ | |
NodeDefinition = new IndexedNode() | |
{ | |
NodeId = book.ID, | |
Type = "CustomData" | |
}, | |
RowData = new Dictionary<string, string>() | |
{ | |
{"title", book.title}, | |
{"author", book.author} | |
} | |
}); | |
} | |
return data; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment