Custom Examine/Lucene Index With Ability To Insert & Update Individual Entries
I'm looking for pointers/links to articles or documents on how to create a custom index that let gives me the ability to insert and update individual entries/records.
/// <summary>
/// Updates an entry in the search index that is related to the post provided by the parameter.
/// </summary>
/// <param name="post"></param>
private void UpdateIndex(Post post)
{
var examineNode = post.ToSimpleDataSet().RowData.ToExamineXml(post.Id, "CustomData");
ExamineManager.Instance.IndexProviderCollection["CustomIndexer"].ReIndexNode(examineNode, "CustomData");
}
And in the post class the method like:
using Examine.LuceneEngine;
/// <summary>
///
/// </summary>
/// <returns></returns>
public SimpleDataSet ToSimpleDataSet()
{
var data = new SimpleDataSet()
{
//create the node definition, ensure that it is the same type as referenced in the config
NodeDefinition = new IndexedNode()
{
NodeId = this.Id,
Type = "CustomData"
},
//add the data to the row
RowData = new Dictionary<string, string>()
{
{"id", this.Id.ToString(CultureInfo.InvariantCulture)},
{"title", this.Title},
{"body", StringUtil.RemoveHtmlTags(HttpUtility.HtmlDecode(this.Body))},
{"tags", String.Join(",", this.PostTags.Select(x => x.TagId.ToString(CultureInfo.InvariantCulture)).ToArray())},
{"topicId", this.Topic.Id.ToString(CultureInfo.InvariantCulture)},
{"topicViews", this.Topic.Views.ToString(CultureInfo.InvariantCulture)},
{"topicTotalLikes", this.Topic.DeepLikeCount.ToString(CultureInfo.InvariantCulture)},
{"topicTotalReplies", this.Topic.DeepReplyCount .ToString(CultureInfo.InvariantCulture)},
{"topicDateUpdated", this.Topic.DateCreated.ToString(CultureInfo.InvariantCulture)},
{"isActive", this.IsActive.ToString(CultureInfo.InvariantCulture)}
}
};
return data;
}
See the using statement as well. For insert it will be the initial mass insert see the demo in examine source on how to implement custom indexer.
This is old code it may be in v7 some namespaces may have changed
So if a "mass insert" is my only option, everytime some new node (or row in the db) is created I would have to rerun that import? Is't there something like this:
Custom Examine/Lucene Index With Ability To Insert & Update Individual Entries
I'm looking for pointers/links to articles or documents on how to create a custom index that let gives me the ability to insert and update individual entries/records.
Lee,
In service somewhere you could have method
And in the post class the method like:
See the using statement as well. For insert it will be the initial mass insert see the demo in examine source on how to implement custom indexer.
This is old code it may be in v7 some namespaces may have changed
Regards
Ismail
Hi!
Thanks for great pointers!
So if a "mass insert" is my only option, everytime some new node (or row in the db) is created I would have to rerun that import? Is't there something like this:
Same question when something is deleted or hidden? How would I remove it?
? =D
Forgot to ask, do you have to still create the XML based indexer and searcher?
hi i have an issue regarding the image. the image change when i save and publish. what should i do?
is working on a reply...