Exemple #1
0
            private void WriteDocumentToIndex(object doc, IndexWriter indexWriter, Analyzer analyzer)
            {
                float boost;
                var   fields = GetFields(doc, out boost).ToList();

                string reduceKeyAsString = ExtractReduceKey(ViewGenerator, doc);

                reduceKeyField.SetValue(reduceKeyAsString);

                luceneDoc.GetFields().Clear();
                luceneDoc.Boost = boost;
                luceneDoc.Add(reduceKeyField);
                foreach (var field in fields)
                {
                    luceneDoc.Add(field);
                }

                if (Level == 2)
                {
                    batchers.ApplyAndIgnoreAllErrors(
                        exception =>
                    {
                        logIndexing.WarnException(
                            string.Format("Error when executed OnIndexEntryCreated trigger for index '{0}', key: '{1}'",
                                          name, reduceKeyAsString),
                            exception);
                        Context.AddError(name, reduceKeyAsString, exception.Message);
                    },
                        trigger => trigger.OnIndexEntryCreated(reduceKeyAsString, luceneDoc));
                }

                parent.LogIndexedDocument(reduceKeyAsString, luceneDoc);

                parent.AddDocumentToIndex(indexWriter, luceneDoc, analyzer);
            }
Exemple #2
0
            private void WriteDocumentToIndex(object doc, RavenIndexWriter indexWriter, Analyzer analyzer, Stopwatch convertToLuceneDocumentDuration, Stopwatch addDocumentDutation)
            {
                string reduceKeyAsString;

                using (StopwatchScope.For(convertToLuceneDocumentDuration))
                {
                    float boost;
                    try
                    {
                        var fields = GetFields(doc, out boost);

                        reduceKeyAsString = ExtractReduceKey(ViewGenerator, doc);
                        reduceKeyField.SetValue(reduceKeyAsString);
                        reduceValueField.SetValue(ToJsonDocument(doc).ToString(Formatting.None));

                        luceneDoc.GetFields().Clear();
                        luceneDoc.Boost = boost;
                        luceneDoc.Add(reduceKeyField);
                        luceneDoc.Add(reduceValueField);

                        foreach (var field in fields)
                        {
                            luceneDoc.Add(field);
                        }
                    }
                    catch (Exception e)
                    {
                        Context.AddError(indexId,
                                         parent.PublicName,
                                         TryGetDocKey(doc),
                                         e,
                                         "Reduce"
                                         );
                        logIndexing.WarnException("Could not get fields to during reduce for " + parent.PublicName, e);
                        return;
                    }
                }
                batchers.ApplyAndIgnoreAllErrors(
                    exception =>
                {
                    logIndexing.WarnException(
                        string.Format("Error when executed OnIndexEntryCreated trigger for index '{0}', key: '{1}'",
                                      indexId, reduceKeyAsString),
                        exception);
                    Context.AddError(indexId, parent.PublicName, reduceKeyAsString, exception, "OnIndexEntryCreated Trigger");
                },
                    trigger => trigger.OnIndexEntryCreated(reduceKeyAsString, luceneDoc));

                parent.LogIndexedDocument(reduceKeyAsString, luceneDoc);

                using (StopwatchScope.For(addDocumentDutation))
                {
                    parent.AddDocumentToIndex(indexWriter, luceneDoc, analyzer);
                }
            }