void Start() { highlighter = GetComponent<Highlighter>(); if (highlighter == null) { highlighter = gameObject.AddComponent<Highlighter>(); } }
// Use this for initialization protected override void Awake() { if(instance != null) Destroy(instance.gameObject); instance = this; light.range = DISTANCE_FROM_SUBJECT*2; }
public Highlighter Construct(AddEditHighlighter data) { Color? background = null; Color? foreground = null; var highlighter = new Highlighter { Name = data.Name, Field = data.Field, Pattern = data.Pattern, Mode = data.Mode, Enabled = true }; if (data.OverrideBackgroundColour) { background = data.BackgroundColour; } if (data.OverrideForegroundColour) { foreground = data.ForegroundColour; } highlighter.Style = new HighlighterStyle { Background = background, Foreground = foreground }; return highlighter; }
public void HighlightShortStringUsingMockStringWriterWithRandomExceptions() { XmlFormatter x = new XmlFormatter(); Highlighter h = new Highlighter("cs", x); for (int i = 0; i < 10; i++) { h.Highlight("public void Foo() { int i = 5; }", new MockStringWriter(2)); } }
void Awake() { connectedRoads = new List<Road>(); roadMgr = FindObjectOfType<RoadManager>(); highlighter = gameObject.AddComponent<Highlighter>(); gameObject.name = string.Format("Node{0}", gameObject.GetInstanceID()); }
public void Setup(Unit actor, Path path, List<Unit> targetableUnits) { this.actor = actor; this.currentStage = CampaignManager.Instance.CurrentStage(); this.highlighter = currentStage.GetComponent<Highlighter>(); this.targetableUnits = targetableUnits; RecalculateHighlights(); }
public string GetHighlight(string value, string highlightField, Searcher searcher, string luceneRawQuery) { var query = GetQueryParser(highlightField).Parse(luceneRawQuery); var scorer = new QueryScorer(searcher.Rewrite(query)); var highlighter = new Highlighter(HighlightFormatter, scorer); var tokenStream = HighlightAnalyzer.TokenStream(highlightField, new StringReader(value)); string bestFragments = highlighter.GetBestFragments(tokenStream, value, MaxNumHighlights, Separator); return bestFragments; }
public void Activate() { _active = true; _highlighter = GetComponent<Highlighter>(); if (_highlighter == null) _highlighter = gameObject.AddComponent<Highlighter>(); _highlighter.SeeThroughOff(); Deselect(); }
// This method takes a search term and a text as a parameter, and displays the text // with the search term in bold. public static void RealHighlighter(string searchTerm, string text) { TermQuery query = new TermQuery(new Term("mainText", searchTerm)); Lucene.Net.Search.Highlight.IScorer scorer = new QueryScorer(query); Highlighter highlighter = new Highlighter(scorer); System.IO.StringReader reader = new System.IO.StringReader(text); TokenStream tokenStream = new SimpleAnalyzer().TokenStream("mainText", reader); String[] toBePrinted = highlighter.GetBestFragments(tokenStream, text, 5); // 5 is the maximum number of fragments that gets tested foreach (var word in toBePrinted) { Console.Write(word); } }
public void HighlightLongStringUsingMockStringWriterWithRandomExceptions() { StringBuilder sb = new StringBuilder(3000*20); for (int i = 0; i < 3000; i++) { sb.Append("public void Foo() { int i = 5; }"); } XmlFormatter x = new XmlFormatter(); Highlighter h = new Highlighter("cs", x); string s = sb.ToString(); h.Highlight(s, new MockStringWriter(2)); }
// TEST METHOD FOR HIGHLIGHTING. public static void Highlighter() { string textTest = "I am a man that follows hell."; TermQuery queryTest = new TermQuery(new Term("", "hell")); Lucene.Net.Search.Highlight.IScorer scorer = new QueryScorer(queryTest); Highlighter highlighter = new Highlighter(scorer); System.IO.StringReader reader = new System.IO.StringReader(textTest); TokenStream tokenStream = new SimpleAnalyzer().TokenStream("field", reader); String[] toBePrinted = highlighter.GetBestFragments(tokenStream, textTest, 1); // 1 is the maximum number of fragments that gets tested foreach (var word in toBePrinted) { Console.WriteLine(word); } }
// This method is printing out the message details given the index document. // NOTE: The field "mainText" must be stored in indexing level. Same goes for any // other field you want to search. private static void DisplayMessage(Document d, string searchTerm) { // THIS IS USED IN THE DATABASE INDEXic //Console.WriteLine("id: " + d.Get("id") + "\n" + "messageBox: " + d.Get("messageBox") + "\n" + "incoming: " + d.Get("incoming") + "\n" + "date: " + d.Get("date") + "\n" + "mainText: " + d.Get("mainText")); // THIS IS USED IN MY TEST FILES //Console.WriteLine("id: " + d.Get("id") + "\n" + "mainText: " + d.Get("mainText")); string text = d.Get("mainText"); TermQuery query = new TermQuery(new Term("mainText", searchTerm)); Lucene.Net.Search.Highlight.IScorer scorer = new QueryScorer(query); Highlighter highlighter = new Highlighter(scorer); System.IO.StringReader reader = new System.IO.StringReader(text); TokenStream tokenStream = new SimpleAnalyzer().TokenStream("mainText", reader); String[] toBePrinted = highlighter.GetBestFragments(tokenStream, text, 5); // 5 is the maximum number of fragments that gets tested foreach (var word in toBePrinted) { Console.Write(word); } Console.WriteLine("====================="); Console.ReadKey(); }
private void ApplySnippetInfo(XPathNavigator navigator, SnippetInfo snippetInfo, string input) { CodeHighlightMode highlightMode = this.Mode; CodeController codeController = CodeController.GetInstance("reference"); if (codeController == null) { return; } IList <SnippetItem> listItems = _codeRefProvider[snippetInfo]; if (listItems != null) { XmlWriter xmlWriter = navigator.InsertAfter(); int itemCount = listItems.Count; for (int i = 0; i < itemCount; i++) { SnippetItem snippet = listItems[i]; string codeLang = snippet.Language; if (highlightMode == CodeHighlightMode.None) { xmlWriter.WriteStartElement("code"); // start - code xmlWriter.WriteAttributeString("language", CodeController.GetCodeAttribute(codeLang)); xmlWriter.WriteString(snippet.Text); xmlWriter.WriteEndElement(); // end - code } else if (highlightMode == CodeHighlightMode.DirectIris) { Highlighter highlighter = codeController.ApplyLanguage( null, codeLang); codeController.BeginDirect(xmlWriter, codeLang); if (highlighter != null) { StringReader textReader = new StringReader(snippet.Text); highlighter.Highlight(textReader, xmlWriter); } else { xmlWriter.WriteString(snippet.Text); } codeController.EndDirect(xmlWriter, codeLang); } else if (highlightMode == CodeHighlightMode.IndirectIris) { xmlWriter.WriteStartElement("code"); // start - code xmlWriter.WriteAttributeString("language", CodeController.GetCodeAttribute(codeLang)); // <xsl:when test="@class='tgtSentence' or @class='srcSentence'"> xmlWriter.WriteStartElement("span"); xmlWriter.WriteAttributeString("name", "SandAssist"); xmlWriter.WriteAttributeString("class", "tgtSentence"); xmlWriter.WriteString(snippet.Language); xmlWriter.WriteEndElement(); xmlWriter.WriteString(snippet.Text); xmlWriter.WriteEndElement(); // end - code } else { Highlighter highlighter = codeController.ApplyLanguage( xmlWriter, snippet.Language); if (highlighter != null) { StringReader textReader = new StringReader( snippet.Text); highlighter.Highlight(textReader, xmlWriter); } else { xmlWriter.WriteString(snippet.Text); } } } xmlWriter.Close(); navigator.DeleteSelf(); } else { base.WriteMessage(MessageLevel.Warn, String.Format( "The snippet with identifier '{0}' is was found.", snippetInfo)); } }
public BenchmarkHighlighterAnonymousClass(SearchTravRetHighlightTask outerInstance, Highlighter highlighter) { this.outerInstance = outerInstance; this.highlighter = highlighter; }
private static List<LineSpan> BreakIntoSpans(Highlighter highlighter, LineSpan span) { var result = new List<LineSpan>(); if (highlighter.Intersects(span.Start, span.End)) { if (highlighter.StartOffset > span.Start) { result.Add(new LineSpan(span.Start, highlighter.StartOffset, span.TextColor, span.BackgroundColor, true)); } result.Add(new LineSpan(Math.Max(span.Start, highlighter.StartOffset), Math.Min(span.End, highlighter.EndOffset), highlighter.TextColor.HasValue ? highlighter.TextColor.Value : span.TextColor, highlighter.BackgroundColor.HasValue ? highlighter.BackgroundColor.Value : span.BackgroundColor, false)); if (highlighter.EndOffset < span.End) { result.Add(new LineSpan(highlighter.EndOffset, span.End, span.TextColor, span.BackgroundColor, true)); } } else result.Add(span); return result; }
ProgressMonitor(IProgressMonitor monitor, char[] text, Highlighter highlighter) { this.monitor = monitor; this.text = text; this.highlighter = highlighter; }
// private void Awake() { h = GetComponent<Highlighter>(); if (h == null) h = gameObject.AddComponent<Highlighter>(); }
public HexDump() { SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true); _selectionHighlighter = AddHighlighter(SystemColors.HighlightText, SystemColors.Highlight); }
/// <summary> /// Searches the index. /// </summary> /// <param name="totalHits">The total hits.</param> /// <param name="forumId">The forum identifier.</param> /// <param name="userId">The user identifier.</param> /// <param name="searchQuery">The search query.</param> /// <param name="searchField">The search field.</param> /// <param name="pageIndex">Index of the page.</param> /// <param name="pageSize">Size of the page.</param> /// <returns> /// Returns the Search results /// </returns> private List <SearchMessage> SearchIndex( out int totalHits, int forumId, int userId, string searchQuery, string searchField = "", int pageIndex = 1, int pageSize = 1000) { if (string.IsNullOrEmpty(searchQuery.Replace("*", string.Empty).Replace("?", string.Empty))) { totalHits = 0; return(new List <SearchMessage>()); } // Insert forum access here var userAccessList = this.GetRepository <vaccess>().Get(v => v.UserID == userId); // filter forum if (forumId > 0) { userAccessList = userAccessList.FindAll(v => v.ForumID == forumId); } using (var searcher = new IndexSearcher(Directory, true)) { var hitsLimit = this.Get <YafBoardSettings>().ReturnSearchMax; var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30); var formatter = new SimpleHTMLFormatter( "<mark>", "</mark>"); var fragmenter = new SimpleFragmenter(hitsLimit); QueryScorer scorer; // search by single field if (!string.IsNullOrEmpty(searchField)) { var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, searchField, analyzer); var query = this.ParseQuery(searchQuery, parser); scorer = new QueryScorer(query); var hits = searcher.Search(query, hitsLimit).ScoreDocs; totalHits = hits.Length; var highlighter = new Highlighter(formatter, scorer) { TextFragmenter = fragmenter }; var results = this.MapSearchToDataList( highlighter, analyzer, searcher, hits, pageIndex, pageSize, userAccessList); analyzer.Close(); searcher.Dispose(); return(results); } else { var parser = new MultiFieldQueryParser( Lucene.Net.Util.Version.LUCENE_30, new[] { "Message", "Topic", "Author" }, analyzer); var query = this.ParseQuery(searchQuery, parser); scorer = new QueryScorer(query); var hits = searcher.Search(query, null, hitsLimit, Sort.INDEXORDER).ScoreDocs; totalHits = hits.Length; var highlighter = new Highlighter(formatter, scorer) { TextFragmenter = fragmenter }; var results = this.MapSearchToDataList( highlighter, analyzer, searcher, hits, pageIndex, pageSize, userAccessList); analyzer.Close(); searcher.Dispose(); return(results); } } }
public void TestQueryScorerHits() { Analyzer analyzer = new SimpleAnalyzer(); QueryParser qp = new QueryParser(TEST_VERSION, FIELD_NAME, analyzer); query = qp.Parse("\"very long\""); searcher = new IndexSearcher(ramDir, true); TopDocs hits = searcher.Search(query, 10); QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(scorer); for (int i = 0; i < hits.ScoreDocs.Length; i++) { Document doc = searcher.Doc(hits.ScoreDocs[i].Doc); String storedField = doc.Get(FIELD_NAME); TokenStream stream = TokenSources.GetAnyTokenStream(searcher.IndexReader, hits.ScoreDocs[i].Doc, FIELD_NAME, doc, analyzer); IFragmenter fragmenter = new SimpleSpanFragmenter(scorer); highlighter.TextFragmenter = fragmenter; String fragment = highlighter.GetBestFragment(stream, storedField); Console.WriteLine(fragment); } }
/// <summary> /// Main searching method /// </summary> /// <param name="lookQuery"></param> /// <returns>an IEnumerableWithTotal</returns> public static IEnumerableWithTotal <LookMatch> Query(LookQuery lookQuery) { IEnumerableWithTotal <LookMatch> lookMatches = null; // prepare return value if (lookQuery == null) { LogHelper.Warn(typeof(LookService), "Supplied search query was null"); } else { var searchProvider = LookService.Searcher; var searchCriteria = searchProvider.CreateSearchCriteria(); var query = searchCriteria.Field(string.Empty, string.Empty); // Text if (!string.IsNullOrWhiteSpace(lookQuery.TextQuery.SearchText)) { if (lookQuery.TextQuery.Fuzzyness > 0) { query.And().Field(LookService.TextField, lookQuery.TextQuery.SearchText.Fuzzy(lookQuery.TextQuery.Fuzzyness)); } else { query.And().Field(LookService.TextField, lookQuery.TextQuery.SearchText); } } // Tags if (lookQuery.TagQuery != null) { var allTags = new List <string>(); var anyTags = new List <string>(); if (lookQuery.TagQuery.AllTags != null) { allTags.AddRange(lookQuery.TagQuery.AllTags); allTags.RemoveAll(x => string.IsNullOrWhiteSpace(x)); } if (lookQuery.TagQuery.AnyTags != null) { anyTags.AddRange(lookQuery.TagQuery.AnyTags); anyTags.RemoveAll(x => string.IsNullOrWhiteSpace(x)); } if (allTags.Any()) { query.And().GroupedAnd(allTags.Select(x => LookService.TagsField), allTags.ToArray()); } if (anyTags.Any()) { query.And().GroupedOr(allTags.Select(x => LookService.TagsField), anyTags.ToArray()); } } // TODO: Date // TODO: Name // Nodes if (lookQuery.NodeQuery != null) { if (lookQuery.NodeQuery.TypeAliases != null) { var typeAliases = new List <string>(); typeAliases.AddRange(lookQuery.NodeQuery.TypeAliases); typeAliases.RemoveAll(x => string.IsNullOrWhiteSpace(x)); if (typeAliases.Any()) { query.And().GroupedOr(typeAliases.Select(x => UmbracoContentIndexer.NodeTypeAliasFieldName), typeAliases.ToArray()); } } if (lookQuery.NodeQuery.ExcludeIds != null) { foreach (var excudeId in lookQuery.NodeQuery.ExcludeIds.Distinct()) { query.Not().Id(excudeId); } } } try { searchCriteria = query.Compile(); } catch (Exception exception) { LogHelper.WarnWithException(typeof(LookService), "Could not compile the Examine query", exception); } if (searchCriteria != null && searchCriteria is LuceneSearchCriteria) { Sort sort = null; Filter filter = null; Func <int, double?> getDistance = x => null; Func <string, IHtmlString> getHighlight = null; TopDocs topDocs = null; switch (lookQuery.SortOn) { case SortOn.Date: // newest -> oldest sort = new Sort(new SortField(LuceneIndexer.SortedFieldNamePrefix + LookService.DateField, SortField.LONG, true)); break; case SortOn.Name: // a -> z sort = new Sort(new SortField(LuceneIndexer.SortedFieldNamePrefix + LookService.NameField, SortField.STRING)); break; } if (lookQuery.LocationQuery != null && lookQuery.LocationQuery.Location != null) { double maxDistance = LookService.MaxDistance; if (lookQuery.LocationQuery.MaxDistance != null) { maxDistance = Math.Min(lookQuery.LocationQuery.MaxDistance.GetMiles(), maxDistance); } var distanceQueryBuilder = new DistanceQueryBuilder( lookQuery.LocationQuery.Location.Latitude, lookQuery.LocationQuery.Location.Longitude, maxDistance, LookService.LocationField + "_Latitude", LookService.LocationField + "_Longitude", CartesianTierPlotter.DefaltFieldPrefix, true); // update filter filter = distanceQueryBuilder.Filter; if (lookQuery.SortOn == SortOn.Distance) { // update sort sort = new Sort( new SortField( LookService.DistanceField, new DistanceFieldComparatorSource(distanceQueryBuilder.DistanceFilter))); } // raw data for the getDistance func var distances = distanceQueryBuilder.DistanceFilter.Distances; // update getDistance func getDistance = new Func <int, double?>(x => { if (distances.ContainsKey(x)) { return(distances[x]); } return(null); }); } var indexSearcher = new IndexSearcher(((LuceneIndexer)LookService.Indexer).GetLuceneDirectory(), false); var luceneSearchCriteria = (LuceneSearchCriteria)searchCriteria; // Do the Lucene search topDocs = indexSearcher.Search( luceneSearchCriteria.Query, // the query build by Examine filter ?? new QueryWrapperFilter(luceneSearchCriteria.Query), LookService.MaxLuceneResults, sort ?? new Sort(SortField.FIELD_SCORE)); if (topDocs.TotalHits > 0) { // setup the highlighing func if required if (lookQuery.TextQuery.HighlightFragments > 0 && !string.IsNullOrWhiteSpace(lookQuery.TextQuery.SearchText)) { var version = Lucene.Net.Util.Version.LUCENE_29; Analyzer analyzer = new StandardAnalyzer(version); var queryParser = new QueryParser(version, LookService.TextField, analyzer); var queryScorer = new QueryScorer(queryParser .Parse(lookQuery.TextQuery.SearchText) .Rewrite(indexSearcher.GetIndexReader())); Highlighter highlighter = new Highlighter(new SimpleHTMLFormatter("<strong>", "</strong>"), queryScorer); // update the func so it does real highlighting work getHighlight = (x) => { var tokenStream = analyzer.TokenStream(LookService.TextField, new StringReader(x)); var highlight = highlighter.GetBestFragments( tokenStream, x, lookQuery.TextQuery.HighlightFragments, // max number of fragments lookQuery.TextQuery.HighlightSeparator); // fragment separator return(new HtmlString(highlight)); }; } lookMatches = new EnumerableWithTotal <LookMatch>( LookSearchService.GetLookMatches( lookQuery, indexSearcher, topDocs, getHighlight, getDistance), topDocs.TotalHits); } } } return(lookMatches ?? new EnumerableWithTotal <LookMatch>(Enumerable.Empty <LookMatch>(), 0)); }
/// <summary> /// Gets the highlighted text. /// </summary> /// <param name="highlighter">The highlighter.</param> /// <param name="analyzer">The analyzer.</param> /// <param name="field">The field.</param> /// <param name="fieldContent">Content of the field.</param> /// <returns> /// Returns the highlighted text. /// </returns> private string GetHighlight(Highlighter highlighter, Analyzer analyzer, string field, string fieldContent) { var stream = analyzer.TokenStream(field, new StringReader(fieldContent)); return(highlighter.GetBestFragments(stream, fieldContent, 20, ".")); }
/// <summary> /// Does the search and stores the information about the results. /// </summary> private void search() { DateTime start = DateTime.Now; // create the searcher // index is placed in "index" subdirectory string indexDirectory = Server.MapPath("~/App_Data/index"); //var analyzer = new StandardAnalyzer(Version.LUCENE_30); var analyzer = new Lucene.Net.Analysis.PanGu.PanGuAnalyzer(); IndexSearcher searcher = new IndexSearcher(FSDirectory.Open(indexDirectory)); // parse the query, "text" is the default field to search var parser = new QueryParser(Version.LUCENE_30, "name", analyzer); parser.AllowLeadingWildcard = true; Query query = parser.Parse(this.Query); // create the result DataTable this.Results.Columns.Add("title", typeof(string)); this.Results.Columns.Add("sample", typeof(string)); this.Results.Columns.Add("path", typeof(string)); this.Results.Columns.Add("url", typeof(string)); // search TopDocs hits = searcher.Search(query, 200); this.total = hits.TotalHits; // create highlighter IFormatter formatter = new SimpleHTMLFormatter("<span style=\"font-weight:bold;\">", "</span>"); SimpleFragmenter fragmenter = new SimpleFragmenter(80); QueryScorer scorer = new QueryScorer(query); Highlighter highlighter = new Highlighter(formatter, scorer); highlighter.TextFragmenter = fragmenter; // initialize startAt this.startAt = InitStartAt(); // how many items we should show - less than defined at the end of the results int resultsCount = Math.Min(total, this.maxResults + this.startAt); for (int i = startAt; i < resultsCount; i++) { // get the document from index Document doc = searcher.Doc(hits.ScoreDocs[i].Doc); TokenStream stream = analyzer.TokenStream("", new StringReader(doc.Get("name"))); String sample = highlighter.GetBestFragments(stream, doc.Get("name"), 2, "..."); String path = doc.Get("path"); // create a new row with the result data DataRow row = this.Results.NewRow(); row["title"] = doc.Get("name"); //row["path"] = "api/" + path; //row["url"] = "www.dotlucene.net/documentation/api/" + path; //row["sample"] = sample; this.Results.Rows.Add(row); } searcher.Dispose(); // result information this.duration = DateTime.Now - start; this.fromItem = startAt + 1; this.toItem = Math.Min(startAt + maxResults, total); }
public virtual async Task <SearchResult> SearchAsync(string term, int?filterByCategory = null, int languageId = -1, PostType?postType = null, SearchPlace searchPlace = SearchPlace.Anywhere, SearchResultSortType orderBy = SearchResultSortType.Score, int maxResult = 1000, bool exactSearch = false) { var result = new SearchResult(); term = term.Trim(); //replace multiple spaces with a single space RegexOptions options = RegexOptions.None; Regex regex = new Regex("[ ]{2,}", options); term = regex.Replace(term, " "); if (string.IsNullOrWhiteSpace(term)) { return(result); } var watch = new System.Diagnostics.Stopwatch(); watch.Start(); try { await Task.Run(() => { using (var directory = FSDirectory.Open(new DirectoryInfo(_indexFilesPath))) { using (var searcher = new IndexSearcher(directory, readOnly: true)) { var searchInFields = new List <string>(); if (searchPlace == SearchPlace.Anywhere) { searchInFields.AddRange(new string[] { "Title", "Description", "Keywords", "Tags" }); } else { if (searchPlace.HasFlagFast(SearchPlace.Title)) { searchInFields.Add("Title"); } if (searchPlace.HasFlagFast(SearchPlace.Description)) { searchInFields.Add("Description"); } if (searchPlace.HasFlagFast(SearchPlace.Keywords)) { searchInFields.Add("Keywords"); } if (searchPlace.HasFlagFast(SearchPlace.Tags)) { searchInFields.Add("Tags"); } } BooleanFilter filter = null; if (languageId > -1 || filterByCategory != null || postType != null) { filter = new BooleanFilter(); if (languageId > -1) { filter.Add(new FilterClause( new QueryWrapperFilter(new TermQuery(new Term("LanguageId", languageId.ToString()))), Occur.MUST)); } if (filterByCategory != null) { filter.Add(new FilterClause( new QueryWrapperFilter(new TermQuery(new Term("Categories", filterByCategory.Value.ToString()))), Occur.MUST)); } if (postType != null) { filter.Add(new FilterClause( new QueryWrapperFilter(new TermQuery(new Term("PostType", postType.Value.ToString()))), Occur.MUST)); } } var currentSettings = _settingService.LoadSetting <SiteSettings>(); if (!currentSettings.EnableBlog) { //Filter Blog Posts if Blog is disabled if (filter == null) { filter = new BooleanFilter(); } filter.Add(new FilterClause( new QueryWrapperFilter(new TermQuery(new Term("PostType", PostType.BlogPost.ToString()))), Occur.MUST_NOT)); } Sort sort = new Sort(SortField.FIELD_SCORE); switch (orderBy) { case SearchResultSortType.NumberOfVisits: sort = new Sort(new SortField("NumberOfVisit", SortField.INT, true)); break; case SearchResultSortType.PublishDate: sort = new Sort(new SortField("PublishDate", SortField.LONG, true)); break; case SearchResultSortType.LastUpDate: sort = new Sort(new SortField("LastUpDate", SortField.LONG, true)); break; } var analyzer = new StandardAnalyzer(Version); var parser = new MultiFieldQueryParser(Version, searchInFields.ToArray(), analyzer); QueryScorer scorer = null; var hits = new List <ScoreDoc>(); Query query = null; if (exactSearch) { query = ParseQuery(term, parser); hits.AddRange(searcher.Search(query, filter, maxResult, sort).ScoreDocs); } else { query = ParseQuery($"(\"{term}\")", parser); hits.AddRange(searcher.Search(query, filter, maxResult, sort).ScoreDocs); query = ParseQuery($"({term.Replace(" ", "*")})", parser); hits.AddRange(searcher.Search(query, filter, maxResult, sort).ScoreDocs); query = ParseQuery($"(+{term.Trim().Replace(" ", " +")})", parser); hits.AddRange(searcher.Search(query, filter, maxResult, sort).ScoreDocs); query = ParseQuery(term, parser); hits.AddRange(searcher.Search(query, filter, maxResult, sort).ScoreDocs); } scorer = new QueryScorer(query); if (hits.Count == 0) { term = SearchByPartialWords(term); query = ParseQuery(term, parser); scorer = new QueryScorer(query); hits.AddRange(searcher.Search(query, filter, maxResult, sort).ScoreDocs); } var formatter = new SimpleHTMLFormatter( "<span class='badge badge-warning'>", "</span>"); var fragmenter = new SimpleFragmenter(300); var highlighter = new Highlighter(formatter, scorer) { TextFragmenter = fragmenter }; foreach (var scoreDoc in hits) { var doc = searcher.Doc(scoreDoc.Doc); result.Documents.Add(new SearchResultDocument() { DocumentId = int.Parse(doc.Get("ID")), LanguageId = int.Parse(doc.Get("LanguageId")), LanguageIsoCode = doc.Get("LanguageCode"), Score = scoreDoc.Score, DocumentTitle = GetHighlight("Title", highlighter, analyzer, doc.Get("Title"), false), DocumentBody = GetHighlight("Description", highlighter, analyzer, doc.Get("Description"), true), DocumentKeywords = doc.Get("Keywords"), DocumentTags = doc.Get("Tags"), }); } result.Documents = result.Documents.DistinctBy(p => new { p.DocumentId }) .ToList(); analyzer.Close(); //SuggestSimilar using (var spellDirectory = FSDirectory.Open(new DirectoryInfo(_spellFilesPath))) { using (var spellChecker = new SpellChecker.Net.Search.Spell.SpellChecker(spellDirectory)) { result.SuggestSimilar.AddRange(spellChecker.SuggestSimilar(term, 10, null, null, true)); } } } } }); } catch (Exception ex) { result.Error = ex; result.HasError = true; } watch.Stop(); result.ElapsedMilliseconds = watch.ElapsedMilliseconds; _eventPublisher.Publish(new SearchEvent(term, filterByCategory, languageId, postType, searchPlace, maxResult, result)); return(result); }
void Update() { if (!_PopupMode) { if (_CurrentObject != null) { Highlighter.UnHighLight(_CurrentObject); _CurrentObject = null; } if (_CurrentUnit != null) { Highlighter.UnHighLight(_CurrentUnit); _CurrentUnit = null; } if (Input.GetKeyDown("z")) { Settings.ZoneRod.SetActive(true); } if (Input.GetKeyUp("z") && _ZoneStartPoint == null) { Settings.ZoneRod.SetActive(false); } if (!EventSystem.current.IsPointerOverGameObject()) //Изучить. Непонятно что это, но работает { _CameraRay = _Camera.ScreenPointToRay(Input.mousePosition); //создаем луч, идущий из камеры через координаты мышки _IsHit = Physics.Raycast(_CameraRay, out _Hit, 1000, mask); if (_IsHit) { if (_Hit.transform.tag == "Brick") { if ((_BuildingMode) && (_Hit.transform.gameObject != _CurrentObject)) { _PhantomBuilding.Hide(); _PhantomBuilding.Show(_Hit.transform.position); } _CurrentObject = _Hit.transform.gameObject; Highlighter.HighLight(_CurrentObject); if (Settings.ZoneRod.activeInHierarchy) { Settings.ZoneRod.transform.SetParent(_CurrentObject.transform, false); } } if (_Hit.transform.tag == "Unit") { _CurrentUnit = _Hit.transform.gameObject; Highlighter.HighLight(_CurrentUnit); } } if (Input.GetMouseButtonDown(0)) { if (PickedObject != null) { Highlighter.UnPick(PickedObject); } if (_IsHit) { if (_Hit.transform.tag == "Brick" && _BuildingMode) { new ProcessManager.Building(_PhantomBuilding); //Building _b = new Building(_BuildingSelectionDD.value, _PhantomBuilding.Rotation, _PhantomBuilding.MasterObject.transform.position); //_PhantomBuilding.Destroy(); //Brick_intreraction_script.AddBuilding(_b); _PhantomBuilding = null; _BuildingMode = false; } else { if (Settings.ZoneRod.activeInHierarchy) //В режиме выбора зоны { if (_ZoneStartPoint == null) //Стартовая точка не задана { _ZoneStartPoint = Instantiate(Settings.ZoneRod); _ZoneStartPoint.transform.SetParent(_CurrentObject.transform, false); } else //Стартовая точка задана { //_ZoneEndPoint = Settings.ZoneRod; Пока написана херня для теста _ZoneEndPoint = Instantiate(Settings.ZoneRod); _ZoneEndPoint.transform.SetParent(_CurrentObject.transform, false); Settings.ZoneRod.SetActive(false); Links.Interface.SwitchToZoneMenu(0); } } PickedObject = _Hit.transform.gameObject; PickedObject.BroadcastMessage("Click"); Highlighter.Pick(PickedObject); _Normal = _Hit.normal; Log.Notice(scr + scrm, "Picked Object : " + PickedObject.name); } } else { PickedObject = null; Settings.ZoneRod.SetActive(false); Destroy(_ZoneStartPoint); } } } if (Input.GetKeyDown("a")) { if (PickedObject != null && PickedObject.tag == "Unit") { if (_ActorUnit != null) { Highlighter.UnPick(_ActorUnit); } _ActorUnit = PickedObject; PickedObject = null; Highlighter.BrightPick(_ActorUnit); } else { if (_ActorUnit != null) { Highlighter.UnPick(_ActorUnit); } _ActorUnit = null; } } if (Input.GetKeyDown("r")) { if (_PhantomBuilding != null) { _PhantomBuilding.Rotate(); } } if (Input.GetMouseButton(1) && _ActorUnit != null) { Log.Notice(scr, "Walking"); if ((_IsHit) && (_Hit.normal == Vector3.up)) { //_Normal.x = Mathf.RoundToInt(_Hit.point.x); //_Normal.z = Mathf.RoundToInt(_Hit.point.z); //_Normal.y = _Hit.point.y; Log.Notice(scr, "Waybuilder call"); //_ActorUnit.GetComponent<RouteBuilder>().Build(_Normal); _ActorUnit.GetComponent <Unit>().GoTo(_Hit.point); } } if (Input.GetMouseButton(1))//Massive reject { _BuildingMode = false; if (_PhantomBuilding != null) { _PhantomBuilding.Destroy(); _PhantomBuilding = null; } CancelZoneCreation(); } if (PickedObject != null && PickedObject.tag == "Unit" && Input.GetKey("l")) { PickedObject.GetComponent <RouteBuilder>().LogRoute(); } if (Input.GetKey("o")) { if (!(PickedObject == null || PickedObject.tag == "Unit")) { CreateUnit(PickedObject.transform.position); Highlighter.UnPick(PickedObject); PickedObject = null; } else { Log.Notice(scr, "There is no picked cube"); } } } else // Popup is open { } }
public void TestConstantScoreMultiTermQuery() { numHighlights = 0; query = new WildcardQuery(new Term(FIELD_NAME, "ken*")); ((WildcardQuery) query).RewriteMethod = MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE; searcher = new IndexSearcher(ramDir, true); // can't rewrite ConstantScore if you want to highlight it - // it rewrites to ConstantScoreQuery which cannot be highlighted // query = unReWrittenQuery.Rewrite(reader); Console.WriteLine("Searching for: " + query.ToString(FIELD_NAME)); hits = searcher.Search(query, null, 1000); for (int i = 0; i < hits.TotalHits; i++) { String text = searcher.Doc(hits.ScoreDocs[i].Doc).Get(HighlighterTest.FIELD_NAME); int maxNumFragmentsRequired = 2; String fragmentSeparator = "..."; QueryScorer scorer = null; TokenStream tokenStream = null; tokenStream = analyzer.TokenStream(FIELD_NAME, new StringReader(text)); scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); highlighter.TextFragmenter = new SimpleFragmenter(20); String result = highlighter.GetBestFragments(tokenStream, text, maxNumFragmentsRequired, fragmentSeparator); Console.WriteLine("\t" + result); } Assert.IsTrue(numHighlights == 5, "Failed to find correct number of highlights " + numHighlights + " found"); // try null field hits = searcher.Search(query, null, 1000); numHighlights = 0; for (int i = 0; i < hits.TotalHits; i++) { String text = searcher.Doc(hits.ScoreDocs[i].Doc).Get(HighlighterTest.FIELD_NAME); int maxNumFragmentsRequired = 2; String fragmentSeparator = "..."; QueryScorer scorer = null; TokenStream tokenStream = null; tokenStream = analyzer.TokenStream(HighlighterTest.FIELD_NAME, new StringReader(text)); scorer = new QueryScorer(query, null); Highlighter highlighter = new Highlighter(this, scorer); highlighter.TextFragmenter = new SimpleFragmenter(20); String result = highlighter.GetBestFragments(tokenStream, text, maxNumFragmentsRequired, fragmentSeparator); Console.WriteLine("\t" + result); } Assert.IsTrue(numHighlights == 5, "Failed to find correct number of highlights " + numHighlights + " found"); // try default field hits = searcher.Search(query, null, 1000); numHighlights = 0; for (int i = 0; i < hits.TotalHits; i++) { String text = searcher.Doc(hits.ScoreDocs[i].Doc).Get(HighlighterTest.FIELD_NAME); int maxNumFragmentsRequired = 2; String fragmentSeparator = "..."; QueryScorer scorer = null; TokenStream tokenStream = null; tokenStream = analyzer.TokenStream(HighlighterTest.FIELD_NAME, new StringReader(text)); scorer = new QueryScorer(query, "random_field", HighlighterTest.FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); highlighter.TextFragmenter = new SimpleFragmenter(20); String result = highlighter.GetBestFragments(tokenStream, text, maxNumFragmentsRequired, fragmentSeparator); Console.WriteLine("\t" + result); } Assert.IsTrue(numHighlights == 5, "Failed to find correct number of highlights " + numHighlights + " found"); }
/// <summary> /// Sets the highlighter to be used. /// </summary> public void setHighlighter(Highlighter @h) { }
public void TestOffByOne() { var helper = new TestHighlightRunner(); helper.TestAction = () => { TermQuery query = new TermQuery(new Term("data", "help")); Highlighter hg = new Highlighter(new SimpleHTMLFormatter(), new QueryTermScorer(query)); hg.TextFragmenter = new NullFragmenter(); String match = null; match = hg.GetBestFragment(analyzer, "data", "help me [54-65]"); Assert.AreEqual(match, "<B>help</B> me [54-65]"); }; helper.Start(); }
private void ApplyCodes(XmlDocument document, string key) { CodeHighlightMode highlightMode = this.Mode; CodeController codeController = CodeController.GetInstance("reference"); if (codeController == null) { return; } XPathNavigator docNavigator = document.CreateNavigator(); XPathNodeIterator iterator = docNavigator.Select(_codeSelector); XPathNavigator navigator = null; XPathNavigator[] arrNavigator = BuildComponentUtilities.ConvertNodeIteratorToArray(iterator); if (arrNavigator == null || arrNavigator.Length == 0) { return; } int tabSize = this.TabSize; int itemCount = arrNavigator.Length; for (int i = 0; i < itemCount; i++) { navigator = arrNavigator[i]; if (navigator == null) // not likely! { continue; } string codeText = navigator.Value; if (String.IsNullOrEmpty(codeText)) { this.WriteMessage(MessageLevel.Warn, "CodeHighlightComponent: source code is null/empty."); continue; } StringBuilder inputText = CodeFormatter.StripLeadingSpaces( codeText, tabSize); if (inputText == null || inputText.Length == 0) { continue; } string codeLang = navigator.GetAttribute("language", String.Empty); if (String.IsNullOrEmpty(codeLang)) { codeLang = navigator.GetAttribute("lang", String.Empty); } if (String.IsNullOrEmpty(codeLang)) { navigator.SetValue(inputText.ToString()); continue; } XmlWriter xmlWriter = navigator.InsertAfter(); if (highlightMode == CodeHighlightMode.None) { xmlWriter.WriteString(inputText.ToString()); } else if (highlightMode == CodeHighlightMode.DirectIris) { Highlighter highlighter = codeController.ApplyLanguage( null, codeLang); codeController.BeginDirect(xmlWriter, codeLang); if (highlighter != null) { StringReader textReader = new StringReader( inputText.ToString()); highlighter.Highlight(textReader, xmlWriter); } else { xmlWriter.WriteString(inputText.ToString()); } codeController.EndDirect(xmlWriter, codeLang); } else if (highlightMode == CodeHighlightMode.IndirectIris) { xmlWriter.WriteStartElement("code"); // start - code xmlWriter.WriteAttributeString("language", codeLang); // <xsl:when test="@class='tgtSentence' or @class='srcSentence'"> xmlWriter.WriteStartElement("span"); xmlWriter.WriteAttributeString("name", "SandAssist"); xmlWriter.WriteAttributeString("class", "tgtSentence"); xmlWriter.WriteString(codeLang); xmlWriter.WriteEndElement(); xmlWriter.WriteString(inputText.ToString()); xmlWriter.WriteEndElement(); // end - code } else { xmlWriter.WriteStartElement("code"); // start - code Highlighter highlighter = codeController.ApplyLanguage( xmlWriter, codeLang); if (highlighter != null) { StringReader textReader = new StringReader( inputText.ToString()); highlighter.Highlight(textReader, xmlWriter); } else { xmlWriter.WriteString(inputText.ToString()); } xmlWriter.WriteEndElement(); // end - code } xmlWriter.Close(); navigator.DeleteSelf(); } }
/// <summary> /// Maps the search document to data. /// </summary> /// <param name="highlighter">The highlighter.</param> /// <param name="analyzer">The analyzer.</param> /// <param name="doc">The document.</param> /// <param name="userAccessList">The user access list.</param> /// <returns> /// Returns the Search Message /// </returns> private SearchMessage MapSearchDocumentToData( Highlighter highlighter, Analyzer analyzer, Document doc, List <vaccess> userAccessList) { var forumId = doc.Get("ForumId").ToType <int>(); if (!userAccessList.Any() || !userAccessList.Exists(v => v.ForumID == forumId && v.ReadAccess)) { return(null); } var flags = doc.Get("Flags").ToType <int>(); var formattedMessage = this.Get <IFormatMessage>().FormatMessage(doc.Get("Message"), new MessageFlags(flags), true); var message = formattedMessage; try { message = this.GetHighlight(highlighter, analyzer, "Message", message); } catch (Exception) { // Ignore message = formattedMessage; } finally { if (message.IsNotSet()) { message = formattedMessage; } } string topic; try { topic = this.GetHighlight(highlighter, analyzer, "Topic", doc.Get("Topic")); } catch (Exception) { topic = doc.Get("Topic"); } return(new SearchMessage { MessageId = doc.Get("MessageId").ToType <int>(), Message = message, Flags = flags, Posted = doc.Get("Posted").ToType <DateTime>().ToString( "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture), UserName = doc.Get("Author"), UserId = doc.Get("UserId").ToType <int>(), TopicId = doc.Get("TopicId").ToType <int>(), Topic = topic.IsSet() ? topic : doc.Get("Topic"), ForumId = doc.Get("ForumId").ToType <int>(), Description = doc.Get("Description"), TopicUrl = YafBuildLink.GetLink( ForumPages.posts, "t={0}", doc.Get("TopicId").ToType <int>()), MessageUrl = YafBuildLink.GetLink( ForumPages.posts, "m={0}#post{0}", doc.Get("MessageId").ToType <int>()), ForumUrl = YafBuildLink.GetLink( ForumPages.forum, "f={0}", doc.Get("ForumId").ToType <int>()), UserDisplayName = doc.Get("AuthorDisplay"), ForumName = doc.Get("ForumName"), UserStyle = doc.Get("AuthorStyle") }); }
public void TestNumericRangeQuery() { // doesn't currently highlight, but make sure it doesn't cause exception either query = NumericRangeQuery.NewIntRange(NUMERIC_FIELD_NAME, 2, 6, true, true); searcher = new IndexSearcher(ramDir, true); hits = searcher.Search(query, 100); int maxNumFragmentsRequired = 2; QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); for (int i = 0; i < hits.TotalHits; i++) { String text = searcher.Doc(hits.ScoreDocs[i].Doc).Get(NUMERIC_FIELD_NAME); TokenStream tokenStream = analyzer.TokenStream(FIELD_NAME, new StringReader(text)); highlighter.TextFragmenter = new SimpleFragmenter(40); String result = highlighter.GetBestFragments(tokenStream, text, maxNumFragmentsRequired, "..."); //Console.WriteLine("\t" + result); } }
private void ApplyMultiSnippetInfo(XPathNavigator navigator, SnippetInfo[] arrayInfo, string input) { CodeHighlightMode highlightMode = this.Mode; CodeController codeController = CodeController.GetInstance("reference"); if (codeController == null) { return; } IList <SnippetItem> listItems = null; int infoCount = arrayInfo.Length; Dictionary <string, List <SnippetItem> > dicLangItems = new Dictionary <string, List <SnippetItem> >(); // We group the various snippets by the languages... for (int i = 0; i < infoCount; i++) { SnippetInfo snippetInfo = arrayInfo[i]; listItems = _codeRefProvider[snippetInfo]; if (listItems != null) { int itemCount = listItems.Count; for (int j = 0; j < itemCount; j++) { SnippetItem snippet = listItems[j]; List <SnippetItem> list; if (!dicLangItems.TryGetValue(snippet.Language, out list)) { list = new List <SnippetItem>(); dicLangItems.Add(snippet.Language, list); } list.Add(snippet); } } } XmlWriter xmlWriter = navigator.InsertAfter(); foreach (KeyValuePair <string, List <SnippetItem> > pair in dicLangItems) { listItems = pair.Value; int itemCount = listItems.Count; string codeLang = pair.Key; if (highlightMode == CodeHighlightMode.None) { xmlWriter.WriteStartElement("code"); // start - code xmlWriter.WriteAttributeString("language", CodeController.GetCodeAttribute(codeLang)); for (int j = 0; j < itemCount; j++) { if (j > 0) { xmlWriter.WriteStartElement("pre"); xmlWriter.WriteString(_codeRefSeparator); xmlWriter.WriteEndElement(); } xmlWriter.WriteString(listItems[j].Text); } xmlWriter.WriteEndElement(); // end - code } else if (highlightMode == CodeHighlightMode.DirectIris) { Highlighter highlighter = codeController.ApplyLanguage( null, codeLang); codeController.BeginDirect(xmlWriter, codeLang); if (highlighter != null) { for (int j = 0; j < itemCount; j++) { if (j > 0) { xmlWriter.WriteStartElement("pre"); xmlWriter.WriteString(_codeRefSeparator); xmlWriter.WriteEndElement(); } StringReader textReader = new StringReader( listItems[j].Text); highlighter.Highlight(textReader, xmlWriter); } } else { for (int j = 0; j < itemCount; j++) { if (j > 0) { xmlWriter.WriteStartElement("pre"); xmlWriter.WriteString(_codeRefSeparator); xmlWriter.WriteEndElement(); } xmlWriter.WriteString(listItems[j].Text); } } codeController.EndDirect(xmlWriter, codeLang); } else if (highlightMode == CodeHighlightMode.IndirectIris) { xmlWriter.WriteStartElement("code"); // start - code xmlWriter.WriteAttributeString("language", CodeController.GetCodeAttribute(codeLang)); // <xsl:when test="@class='tgtSentence' or @class='srcSentence'"> xmlWriter.WriteStartElement("span"); xmlWriter.WriteAttributeString("name", "SandAssist"); xmlWriter.WriteAttributeString("class", "tgtSentence"); xmlWriter.WriteString(codeLang); xmlWriter.WriteEndElement(); for (int j = 0; j < itemCount; j++) { if (j > 0) { xmlWriter.WriteString(_codeRefSeparator); } xmlWriter.WriteStartElement("span"); xmlWriter.WriteAttributeString("name", "SandAssist"); xmlWriter.WriteAttributeString("class", "srcSentence"); xmlWriter.WriteValue(codeController.Count); xmlWriter.WriteEndElement(); codeController.Register(listItems[j]); } xmlWriter.WriteEndElement(); // end - code } else { Highlighter highlighter = codeController.ApplyLanguage( xmlWriter, codeLang); if (highlighter != null) { for (int j = 0; j < listItems.Count; j++) { if (j > 0) { xmlWriter.WriteString(_codeRefSeparator); } StringReader textReader = new StringReader( listItems[j].Text); highlighter.Highlight(textReader, xmlWriter); } } else { for (int j = 0; j < listItems.Count; j++) { if (j > 0) { xmlWriter.WriteString(_codeRefSeparator); } xmlWriter.WriteString(listItems[j].Text); } } } } xmlWriter.Close(); navigator.DeleteSelf(); }
public void TestSimpleQueryScorerPhraseHighlighting2() { DoSearching("\"text piece long\"~5"); int maxNumFragmentsRequired = 2; var scorer = new QueryScorer(query, FIELD_NAME); var highlighter = new Highlighter(this, scorer); highlighter.TextFragmenter = new SimpleFragmenter(40); for (int i = 0; i < hits.TotalHits; i++) { var text = searcher.Doc(hits.ScoreDocs[i].Doc).Get(FIELD_NAME); var tokenStream = analyzer.TokenStream(FIELD_NAME, new StringReader(text)); var result = highlighter.GetBestFragments(tokenStream, text, maxNumFragmentsRequired, "..."); Console.WriteLine("\t" + result); } Assert.IsTrue(numHighlights == 6, "Failed to find correct number of highlights " + numHighlights + " found"); }
public Highlighter AddHighlighter(Color? textColor, Color? backgroundColor) { var result = new Highlighter(this, textColor, backgroundColor); _highlighters.Insert(0, result); return result; }
public void TestSimpleSpanFragmenter() { DoSearching("\"piece of text that is very long\""); int maxNumFragmentsRequired = 2; QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); for (int i = 0; i < hits.TotalHits; i++) { String text = searcher.Doc(hits.ScoreDocs[i].Doc).Get(FIELD_NAME); TokenStream tokenStream = analyzer.TokenStream(FIELD_NAME, new StringReader(text)); highlighter.TextFragmenter = new SimpleSpanFragmenter(scorer, 5); String result = highlighter.GetBestFragments(tokenStream, text, maxNumFragmentsRequired, "..."); Console.WriteLine("\t" + result); } DoSearching("\"been shot\""); maxNumFragmentsRequired = 2; scorer = new QueryScorer(query, FIELD_NAME); highlighter = new Highlighter(this, scorer); for (int i = 0; i < hits.TotalHits; i++) { String text = searcher.Doc(hits.ScoreDocs[i].Doc).Get(FIELD_NAME); TokenStream tokenStream = analyzer.TokenStream(FIELD_NAME, new StringReader(text)); highlighter.TextFragmenter = new SimpleSpanFragmenter(scorer, 20); String result = highlighter.GetBestFragments(tokenStream, text, maxNumFragmentsRequired, "..."); Console.WriteLine("\t" + result); } }
public ActionResult ViewPaste(string type, string url, string password) { Models.Paste paste = db.Pastes.Where(p => p.Url == url).FirstOrDefault(); if (paste != null) { ViewBag.Title = ((string.IsNullOrEmpty(paste.Title)) ? string.Empty : paste.Title + " - ") + Config.Title + " Paste"; ViewBag.Description = "Paste your code or text easily and securely. Set an expiration, set a password, or leave it open for the world to see."; // Increment Views paste.Views += 1; db.Entry(paste).State = EntityState.Modified; db.SaveChanges(); // Check Expiration if (PasteHelper.CheckExpiration(paste)) { db.Pastes.Remove(paste); db.SaveChanges(); return Redirect(Url.SubRouteUrl("error", "Error.Http404")); } PasteViewModel model = new PasteViewModel(); model.Url = url; model.Content = paste.Content; model.Title = paste.Title; model.Syntax = paste.Syntax; model.DatePosted = paste.DatePosted; byte[] data = Encoding.UTF8.GetBytes(paste.Content); // The paste has a password set if (!string.IsNullOrEmpty(paste.HashedPassword)) { string hash = string.Empty; if (!string.IsNullOrEmpty(password)) { byte[] passBytes = Helpers.SHA384.Hash(paste.Key, password); hash = passBytes.ToHex(); // We need to convert old pastes to the new password scheme if (paste.Transfers.ToList().Exists(t => t.Type == TransferTypes.ASCIIPassword)) { hash = Encoding.ASCII.GetString(passBytes); // Remove the transfer types paste.Transfers.Clear(); db.Entry(paste).State = EntityState.Modified; db.SaveChanges(); } } if (string.IsNullOrEmpty(password) || hash != paste.HashedPassword) { PasswordViewModel passModel = new PasswordViewModel(); passModel.Url = url; passModel.Type = type; // Redirect them to the password request page return View("~/Areas/Paste/Views/Paste/PasswordNeeded.cshtml", passModel); } data = Convert.FromBase64String(paste.Content); // Now we decrypt the content byte[] ivBytes = Encoding.Unicode.GetBytes(paste.IV); byte[] keyBytes = AES.CreateKey(password, ivBytes, paste.KeySize); data = AES.Decrypt(data, keyBytes, ivBytes); model.Content = Encoding.Unicode.GetString(data); } if (type.ToLower() == "full" || type.ToLower() == "simple") { // Transform content into HTML if (!Highlighter.Lexers.ToList().Exists(l => l.Aliases.Contains(model.Syntax))) { model.Syntax = "text"; } Highlighter highlighter = new Highlighter(); // Add a space in front of the content due to bug with pygment (No idea why yet) model.Content = highlighter.HighlightToHtml(" " + model.Content, model.Syntax, Config.PasteConfig.SyntaxVisualStyle, generateInlineStyles: true, fragment: true); } switch (type.ToLower()) { case "full": return View("~/Areas/Paste/Views/Paste/Full.cshtml", model); case "simple": return View("~/Areas/Paste/Views/Paste/Simple.cshtml", model); case "raw": return Content(model.Content, "text/plain"); case "download": //Create File var cd = new System.Net.Mime.ContentDisposition { FileName = url, Inline = true }; Response.AppendHeader("Content-Disposition", cd.ToString()); return File(data, "application/octet-stream"); default: return View("~/Areas/Paste/Views/Paste/Full.cshtml", model); } } return Redirect(Url.SubRouteUrl("error", "Error.Http404")); }
public void TestPosTermStdTerm() { DoSearching("y \"x y z\""); int maxNumFragmentsRequired = 2; QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); for (int i = 0; i < hits.TotalHits; i++) { String text = searcher.Doc(hits.ScoreDocs[i].Doc).Get(FIELD_NAME); TokenStream tokenStream = analyzer.TokenStream(FIELD_NAME, new StringReader(text)); highlighter.TextFragmenter = new SimpleFragmenter(40); String result = highlighter.GetBestFragments(tokenStream, text, maxNumFragmentsRequired, "..."); Console.WriteLine("\t" + result); Assert.IsTrue(numHighlights == 4, "Failed to find correct number of highlights " + numHighlights + " found"); } }
public ArrayList DataToList(DataSet ds,string keyWords,bool isHighlight) { ArrayList result = new ArrayList(); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { Model.DDocInfo doc = new TMM.Model.DDocInfo(); doc.Title = row["Title"].ToString(); doc.Description = row["Description"].ToString(); doc.DocType = row["DocType"].ToString(); doc.DocId = int.Parse( row["DocumentId"].ToString() ); doc.UserId = int.Parse( row["UserId"].ToString()); doc.CreateTime = DateTime.Parse( row["CreateTime"].ToString()); doc.UpCount = int.Parse(row["UpCount"].ToString()); doc.ViewCount = int.Parse(row["ViewCount"].ToString()); if (isHighlight) { SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter("<font color=\"red\">", "</font>"); Highlighter titleHighlighter; Highlighter contentHighlighter; if (titleAnalyzerName.Equals("PanGuSegment", StringComparison.CurrentCultureIgnoreCase)) { titleHighlighter = new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer()); } else if (titleAnalyzerName.Equals("EnglishAnalyzer", StringComparison.CurrentCultureIgnoreCase)) { titleHighlighter = new Highlighter(simpleHTMLFormatter, new Hubble.Core.Analysis.EnglishAnalyzer()); } else { titleHighlighter = new Highlighter(simpleHTMLFormatter, new Hubble.Core.Analysis.SimpleAnalyzer()); } if (descAnalyzerName.Equals("PanGuSegment", StringComparison.CurrentCultureIgnoreCase)) { contentHighlighter = new Highlighter(simpleHTMLFormatter, new PanGuAnalyzer()); } else if (descAnalyzerName.Equals("EnglishAnalyzer", StringComparison.CurrentCultureIgnoreCase)) { contentHighlighter = new Highlighter(simpleHTMLFormatter, new Hubble.Core.Analysis.EnglishAnalyzer()); } else { contentHighlighter = new Highlighter(simpleHTMLFormatter, new Hubble.Core.Analysis.SimpleAnalyzer()); } titleHighlighter.FragmentSize = 50; contentHighlighter.FragmentSize = 50; doc.SearchSummary = contentHighlighter.GetBestFragment(keyWords, doc.Description); string titleHighlight = titleHighlighter.GetBestFragment(keyWords, doc.Title); if (!string.IsNullOrEmpty(titleHighlight)) { doc.Title = titleHighlight; } } result.Add(doc); } return result; }
public void TestSimpleQueryTermScorerHighlighter() { DoSearching("Kennedy"); Highlighter highlighter = new Highlighter(new QueryTermScorer(query)); highlighter.TextFragmenter = new SimpleFragmenter(40); int maxNumFragmentsRequired = 2; for (int i = 0; i < hits.TotalHits; i++) { String text = searcher.Doc(hits.ScoreDocs[i].Doc).Get(FIELD_NAME); TokenStream tokenStream = analyzer.TokenStream(FIELD_NAME, new StringReader(text)); String result = highlighter.GetBestFragments(tokenStream, text, maxNumFragmentsRequired, "..."); Console.WriteLine("\t" + result); } // Not sure we can assert anything here - just running to check we dont // throw any exceptions }
void Awake() { if (m_connections != null) m_connections = new List<Connection>(); m_visuals = gameObject.GetComponentInChildren<Highlighter>(); }
protected override BenchmarkHighlighter GetBenchmarkHighlighter(Query q) { m_highlighter = new Highlighter(new SimpleHTMLFormatter(), new QueryScorer(q)); m_highlighter.MaxDocCharsToAnalyze = m_maxDocCharsToAnalyze; return(new BenchmarkHighlighterAnonymousClass(this, m_highlighter)); }
// protected void Awake() { h = GetComponent<Highlighter>(); if (h == null) { h = gameObject.AddComponent<Highlighter>(); } }
public void Initialize(DalamudPluginInterface pluginInterface) { // Initializing plugin, hooking into chat. this.pluginInterface = pluginInterface; Configuration = pluginInterface.GetPluginConfig() as ChatExtenderPluginConfiguration ?? new ChatExtenderPluginConfiguration(); tab_ind = UintCol(255, 50, 70, 50); tab_ind_text = UintCol(255, 150, 150, 150); tab_norm = UintCol(255, 50, 50, 50); tab_norm_text = UintCol(255, 150, 150, 150); tab_sel = UintCol(255, 90, 90, 90); tab_sel_text = UintCol(255, 250, 255, 255); try { rTr = Configuration.RTr.ToString(); } catch (Exception) { PluginLog.LogError("Failed to Load right Translate Surround!"); } try { lTr = Configuration.LTr.ToString(); } catch (Exception) { PluginLog.LogError("Failed to Load left Translate Surround!"); } try { chanColour = Configuration.ChanColour.ToArray(); } catch (Exception) { PluginLog.LogError("No ChanColour to load!"); } try { logColour = Configuration.LogColour.ToArray(); } catch (Exception) { PluginLog.LogError("No LogColour to load!"); } try { injectChat = Configuration.Inject; } catch (Exception) { PluginLog.LogError("Failed to Load Inject Status!"); injectChat = false; } try { translator = Configuration.Translator; } catch (Exception) { PluginLog.LogError("Failed to Load Translator Choice!"); translator = 1; } try { yandex = Configuration.YandexKey.ToString(); } catch (Exception) { PluginLog.LogError("Failed to Load Yandex Key!"); yandex = ""; } try { chatWindow = Configuration.Extender; } catch (Exception) { PluginLog.LogError("Failed to Load Extender Choice!"); chatWindow = false; } try { alpha = Configuration.Alpha; } catch (Exception) { PluginLog.LogError("Failed to Load Alpha!"); alpha = 0.2f; } try { no_move = Configuration.NoMove; } catch (Exception) { PluginLog.LogError("Failed to Load NoMove Config!"); no_move = false; } try { no_resize = Configuration.NoResize; } catch (Exception) { PluginLog.LogError("Failed to Load NoMove Config!"); no_resize = false; } try { no_mouse = Configuration.NoMouse; } catch (Exception) { PluginLog.LogError("Failed to Load NoMouse Config!"); no_mouse = false; } try { high = Configuration.High; tempHigh = String.Join(",", high.highlights); } catch (Exception) { PluginLog.LogError("Failed to Load Highlighter"); high = new Highlighter(); } try { if (high.highlights.Length < 1) { high = new Highlighter(); } } catch (Exception) { PluginLog.LogError("Failed to Load Highlighter"); high = new Highlighter(); } try { no_mouse2 = Configuration.NoMouse2; } catch (Exception) { PluginLog.LogError("Failed to Load NoMouse2 Config!"); no_mouse2 = false; } try { no_scrollbar = Configuration.NoScrollBar; } catch (Exception) { PluginLog.LogError("Failed to Load ScrollBar Config!"); no_scrollbar = false; } try { if (Configuration.Space_Hor.HasValue) { space_hor = Configuration.Space_Hor.Value; } } catch (Exception) { PluginLog.LogError("Failed to Load Horizontal Spacing!"); space_hor = 4; } try { if (Configuration.Space_Ver.HasValue) { space_ver = Configuration.Space_Ver.Value; } } catch (Exception) { PluginLog.LogError("Failed to Load Vertical Spacing!"); space_ver = 0; } try { if (Configuration.TimeColour.Z > 0) { timeColour = Configuration.TimeColour; } else { timeColour = new Num.Vector4(255, 255, 255, 255); } } catch (Exception) { PluginLog.LogError("Failed to Load Time Colour!"); timeColour = new Num.Vector4(255, 255, 255, 255); } try { if (Configuration.NameColour.Z > 0) { nameColour = Configuration.NameColour; } else { nameColour = new Num.Vector4(255, 255, 255, 255); } } catch (Exception) { PluginLog.LogError("Failed to Load Name Colour!"); nameColour = new Num.Vector4(255, 255, 255, 255); } //TODO: try/catch this? if (Configuration.Items == null) { //Serilog.Log.Information("Null DynTab List"); items.Add(new DynTab("XXX", new List <ChatText>(), true)); } else { //Serilog.Log.Information("Not Null DynTab List"); if (Configuration.Items.Count == 0) { //Serilog.Log.Information("Empty DynTab List"); items.Add(new DynTab("YYY", new List <ChatText>(), true)); } else { //Serilog.Log.Information("Normal DynTab List"); items = Configuration.Items.ToList(); } } if (items[0].Config.Length == 3) { foreach (TabBase item in items) { bool[] temp = { false, false, false, false, false, false, false, false, false, false }; temp[0] = item.Config[0]; temp[1] = item.Config[1]; temp[2] = item.Config[2]; item.Config = temp; } } if (items[0].Filter == null) { foreach (TabBase item in items) { item.Filter = ""; item.FilterOn = false; } } try { if (Configuration.Items[0].Logs.Length < Channels.Length) { int l = 0; List <TabBase> templist = new List <TabBase>(); foreach (TabBase items in Configuration.Items) { TabBase temp = new TabBase(); temp.AutoScroll = items.AutoScroll; temp.Chat = items.Chat; temp.Config = items.Config; temp.Enabled = items.Enabled; temp.Scroll = items.Scroll; temp.Title = items.Title; int i = 0; foreach (bool set in items.Logs) { //PluginLog.Log(i.ToString()); temp.Logs[i] = set; i++; } //PluginLog.Log("bool length:" + temp.Logs.Length.ToString()); templist.Add(temp); l++; } items = templist; Num.Vector4[] logColour_temp = { new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255) }; int j = 0; foreach (Num.Vector4 vec in logColour) { logColour_temp[j] = vec; j++; } logColour = logColour_temp; Num.Vector4[] chanColour_temp = { new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255), new Num.Vector4(255, 255, 255, 255) }; int k = 0; foreach (Num.Vector4 vec in chanColour) { chanColour_temp[k] = vec; k++; } chanColour = chanColour_temp; } } catch (Exception) { PluginLog.Log("Fresh install, no log to fix!"); } //Adding in Chans try { if (Configuration.Items[0].Chans.Length < Channels.Length) { int l = 0; List <TabBase> templist = new List <TabBase>(); foreach (TabBase items in Configuration.Items) { TabBase temp = new TabBase(); temp.AutoScroll = items.AutoScroll; temp.Chat = items.Chat; temp.Config = items.Config; temp.Enabled = items.Enabled; temp.Scroll = items.Scroll; temp.Title = items.Title; temp.Logs = items.Logs.ToArray(); temp.Chans = new bool[] { true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true }; templist.Add(temp); l++; } items = templist; } } catch (Exception) { PluginLog.Log("Fresh install, no Chans to fix!"); } try { if (Configuration.Chan.Length > 30) { Chan = Configuration.Chan.ToArray(); } } catch (Exception) { PluginLog.Log("No Chan list to load"); } SaveConfig(); TransY.Make("https://translate.yandex.net/api/v1.5/tr.json/translate", Configuration.YandexKey); // Set up command handlers this.pluginInterface.CommandManager.AddHandler("/cht", new CommandInfo(OnTranslateCommand) { HelpMessage = "Open config with '/cht c', and the extender with '/cht w'" }); this.pluginInterface.Framework.Gui.Chat.OnChatMessage += Chat_OnChatMessage; this.pluginInterface.UiBuilder.OnBuildUi += ChatUI; this.pluginInterface.UiBuilder.OnOpenConfigUi += Chat_ConfigWindow; //ImGui.GetIO().Fonts.Build(); }