c# - Lucene.Net when to reindex my datatbase -
I am implementing Lucene.Net in my ecommerce application (Asp.Net Mvc3, Sql Server 2008) There is a big database. Therefore indexing products are getting very heavy operation.
Now when I update, updating any product index for a particular product, then it should be updated accordingly.
In addition to this, I have also implemented bulk updates for this. Products through excel sheet are being added, updating or removing a large number of products through this operation. As most of the products are not unchanged, it may not be a good idea to reindex all the products and increase the load on the server as
.
For my code indexing products
foreach (var in products) {// Create a document object / object temp = p; Document document = new document (); Var Properties = p.GetType (). GetProperties (); Foreach (Property Properties in Property Properties) {// Our query populate the document with column name and value from var value = propertyInfo.GetValue (p, null); Doc.Add (new field (propertyInfo.Name, value == empty? "": Value.ToString (), field.store.Yes, field.index.nlised)); } // Write the document to the list index Author. Document (doc); }
Anyone knows the alternate solution for this. Is there any way of indexing without using any foreach or anything?
Use a loop, but only for updated products!
If you have a final revision timestamp in your database, then use it to fetch only the updated products from the last indexing job.
Another way is "indexing position" in the field in your database when the product is inserted or modified (bulk update or other way), this flat is set to 0. When indexing job runs, you can set this flag to 1 in the loop.
Then, your indexing job only needs to be flagged with the flag to set all the products to 0.
Do not forget that in Lucene you can not actually update an index: you have to delete the document, and add it again. So in Lucene, you need a field with a unique unique identifier, so that you can retrieve the document using this field (through a word query search), and then delete it.
Another tip: p. GetType (). GetProperties ()
will use the reflection and remove the process.
If all your products have the same type, then create a list of (code outside) PropertyInfo
(outside the loop) so that you only use the reflection once. Reuse it in the loop.
Comments
Post a Comment