Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Connie DeCinko 931 posts 1160 karma points
    May 12, 2011 @ 00:42
    Connie DeCinko
    0

    Using Examine to index search with ANY data source

    Now that Examine is part of Umbraco, I figure I might be able to get help here since documentation is pretty scare anywhere else.

    I am trying to set this up for the current version (FarmCode docs are for old version) and trying to use a SQL database (sample uses XML file).  I seems to be working, sort of.  I can get the index to create but not populate.

    My ExamineIndex.config  (abreviated):

    <?xml version="1.0"?>
    <ExamineLuceneIndexSets>
      <!-- The custom data index set -->
      <IndexSet SetName="MemberFinderIndexSet" IndexPath="~/App_Data/ExamineIndexes/MemberFinder/">
        <IndexUserFields>
          <add Name="name_first" />
          <add Name="name_middle" />
          <add Name="name_last" />
        </IndexUserFields>
      </IndexSet>
    </ExamineLuceneIndexSets>

    My ExamineSettings.config  (abbreviated):

    <?xml version="1.0"?>
    <Examine>
      <ExamineIndexProviders>
        <providers>
          <add name="MemberFinderIndexer"
               type="Examine.LuceneEngine.Providers.SimpleDataIndexer, Examine"
               dataService="SBA.AZBar.UserControls.MemberFinderDataService, SBA.AZBar.UserControls"
               indexTypes="MemberFinderData"
               runAsync="false"/>
        </providers>
      </ExamineIndexProviders>
    
      <ExamineSearchProviders defaultProvider="InternalSearcher">
        <providers>
          <add name="MemberFinderSearcher"
               type="Examine.LuceneEngine.Providers.LuceneSearcher, Examine" />
        </providers>
      </ExamineSearchProviders>
    </Examine>
    

    and My MemberFinderDataService.cs:

    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Text;
    using Examine;
    using Examine.LuceneEngine;
    
    namespace SBA.AZBar.UserControls
    {
        /// <summary>
        /// The data service used by the LuceneEngine in order for it to reindex all data
        /// </summary>
        public class MemberFinderDataService : Examine.LuceneEngine.ISimpleDataService
        {
            /// <summary>
            /// loads the data source into memory
            /// </summary>
            static MemberFinderDataService()
            {
                SqlCommand cmd = new SqlCommand();
    
                StringBuilder sql = new StringBuilder();
    
                sql.Append("SELECT * FROM Populate_Search");
    
                cmd.CommandText = sql.ToString();
    
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Membership"].ToString());
                cmd.Connection = con;
                con.Open();
    
                SqlDataReader reader = cmd.ExecuteReader();
                DataTable dt = new DataTable();
                dt.Load(reader);
                con.Close();
    
            }
    
            private static DataTable dt;
    
            /// <summary>
            /// Returns a list of type SimpleDataSet based on the Populate_Search view query
            /// </summary>
            /// <param name=indexType"></param>
            /// <returns></returns>
            public IEnumerable<SimpleDataSet> GetAllData(string indexType)
            {
                var data = new List<SimpleDataSet>();
    
                //open the datatable and iterate the rows
                foreach (DataRow row in dt.Rows)
                {
                    // add a new SimpleDataSet object to the list
    
                    data.Add(new SimpleDataSet()
                    {
                        // create the node definition, ensure that it is the same type as referenced in the config
                        NodeDefinition = new IndexedNode()
                        {
                            NodeId = (int)row["id"],
                            Type = "CustomData"
                        },
                        // add the data to the row
                        RowData = new Dictionary<stringstring>()
                        {
                            {"id", (string)row["id"]},
                            {"name_first", (string)row["name_first"]},
                            {"name_middle", (string)row["name_middle"]},
                            {"name_last", (string)row["name_last"]}
                        }
                    });
                }
    
                return data;
            }
    
    
        }
    }
  • Connie DeCinko 931 posts 1160 karma points
    Jun 24, 2011 @ 00:23
    Connie DeCinko
    0

    Bump!  Anyone?

     

  • eshan 12 posts 42 karma points
    Nov 06, 2012 @ 04:13
    eshan
    0

    Is this working??

Please Sign in or register to post replies

Write your reply to:

Draft