private IndexRecord GetIndexRecord(object obj, GxContentInfo contentInfo) { IndexRecord ir = null; GxFile file = obj as GxFile; GxSilentTrnSdt silent = obj as GxSilentTrnSdt; string str = obj as string; if (file != null && contentInfo != null) { ir = new IndexRecord(); ir.Uri = file.GetAbsoluteName(); ir.Content = DocumentHandler.GetText(file.GetAbsoluteName(), Path.GetExtension(file.GetAbsoluteName())); ir.Entity = contentInfo.Entity == null?file.GetType().ToString() : contentInfo.Entity; ir.Title = contentInfo.Title == null?file.GetName() : contentInfo.Title; ir.Viewer = contentInfo.Viewer == null?file.GetName() : contentInfo.Viewer; ir.Keys = contentInfo.Keys == null || contentInfo.Keys.Count == 0 ? new List <string>() : contentInfo.Keys; } else if (silent != null) { IGxSilentTrn bc = (silent).getTransaction(); GxContentInfo info = bc.GetContentInfo(); if (info != null) { ir = new IndexRecord(); ir.Uri = info.Id; ir.Content = bc.ToString(); ir.Entity = contentInfo.Entity == null ? info.Entity : contentInfo.Entity; ir.Title = contentInfo.Title == null ? info.Title : contentInfo.Title; ir.Viewer = contentInfo.Viewer == null ? info.Viewer : contentInfo.Viewer; ir.Keys = contentInfo.Keys == null || contentInfo.Keys.Count == 0 ? info.Keys : contentInfo.Keys; } } else if (str != null && contentInfo != null) { ir = new IndexRecord(); ir.Uri = contentInfo.Id == null ? string.Empty : contentInfo.Id; ir.Content = str; ir.Entity = contentInfo.Entity == null ? String.Empty : contentInfo.Entity; ir.Title = contentInfo.Title == null ? String.Empty : contentInfo.Title; ir.Viewer = contentInfo.Viewer == null ? String.Empty : contentInfo.Viewer; ir.Keys = contentInfo.Keys == null || contentInfo.Keys.Count == 0 ? new List <string>() : contentInfo.Keys; } return(ir); }
public bool DownloadPrivate(string storageobjectfullname, GxFile localFile, GXBaseCollection <SdtMessages_Message> messages) { try { ValidProvider(); string destFileName; if (Path.IsPathRooted(localFile.GetAbsoluteName())) { destFileName = localFile.GetAbsoluteName(); } else { destFileName = Path.Combine(GxContext.StaticPhysicalPath(), localFile.Source); } provider.Download(storageobjectfullname, destFileName, GxFileType.Private); return(true); } catch (Exception ex) { StorageMessages(ex, messages); return(false); } }
public static string HtmlPreview(Object obj, string query, string textType, string preTag, string postTag, int fragmentSize, int maxNumFragments) { string text; GxSilentTrnSdt silent = obj as GxSilentTrnSdt; GxFile file = obj as GxFile; if (silent != null) { text = (silent).Transaction.ToString(); } else if (file != null) { text = DocumentHandler.GetText(file.GetAbsoluteName(), System.IO.Path.GetExtension(file.GetAbsoluteName())); } else if (textType.ToLower().StartsWith("htm")) { text = new NTidyHTMLHandler().GetTextFromString(obj.ToString()); } else { text = obj.ToString(); } if (!string.IsNullOrEmpty(query) && !string.IsNullOrEmpty(text)) { if (qp == null) { qp = new QueryParser(Lucene.Net.Util.Version.LUCENE_24, IndexRecord.CONTENTFIELD, Indexer.CreateAnalyzer()); qp.DefaultOperator = QueryParser.Operator.AND; qp.MultiTermRewriteMethod = MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE; } Query unReWrittenQuery = qp.Parse(query); Query q = unReWrittenQuery; try { if (reader == null) { reader = Indexer.Reader; } if (!queries.TryGetValue(query, out q)) { q = unReWrittenQuery.Rewrite(reader);//required to expand search terms (for the usage of highlighting with wildcards) if (queries.Count == int.MaxValue) { queries.Clear(); } queries[query] = q; } } catch (Exception ex) { GXLogging.Error(log, "HTMLPreview error", ex); } QueryScorer scorer = new QueryScorer(q); SimpleHTMLFormatter formatter = new SimpleHTMLFormatter(preTag, postTag); Highlighter highlighter = new Highlighter(formatter, scorer); IFragmenter fragmenter = new SimpleFragmenter(fragmentSize); highlighter.TextFragmenter = fragmenter; TokenStream tokenStream = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_24).TokenStream("Content", new StringReader(text)); String result = highlighter.GetBestFragments(tokenStream, text, maxNumFragments, "..."); return(result); } else { return(text); } }