Skip to content

Instantly share code, notes, and snippets.

@sleslie321
Last active August 4, 2016 20:39
Show Gist options
  • Save sleslie321/9bd572c7072ece6baa38ac18f8d35818 to your computer and use it in GitHub Desktop.
Save sleslie321/9bd572c7072ece6baa38ac18f8d35818 to your computer and use it in GitHub Desktop.
Use Examine to index and search any data source.
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