/// <summary> /// Add a list of properties to use in summary text/body to supplied SummarizerParameters object /// </summary> /// <param name="summaryParameters"></param> /// <param name="titleLinkProperties"></param> /// <param name="summaryProperties"></param> /// <param name="fuzzieness"></param> /// <param name="wildcard"></param> static void AddSummaryProperties(SummarizerParameters summaryParameters, string titleLinkProperties, string summaryProperties, double fuzzieness, bool wildcard) { var titleBoost = Config.Instance.GetSearchTitleBoost(); var titleSummary = GetProperties(titleLinkProperties, titleBoost, fuzzieness, wildcard); summaryParameters.TitleLinkProperties = titleSummary.Count > 0 ? titleSummary : new List <UmbracoProperty> { new UmbracoProperty("nodeName", titleBoost, fuzzieness, wildcard) }; var bodySummary = GetProperties(summaryProperties, 1.0, fuzzieness, wildcard); summaryParameters.BodySummaryProperties = bodySummary.Count > 0 ? bodySummary : new List <UmbracoProperty> { new UmbracoProperty(Config.Instance.GetLuceneFtField(), 1.0, fuzzieness, wildcard) }; }
private static Summarizer SetupSummariser(SummarizerParameters SumParams, int UseHighlighting) { // Create summarizer according to highlighting option Summarizer summarizer; if (UseHighlighting > 0) { summarizer = new Highlight(SumParams); } else { summarizer = new Plain(SumParams); } return(summarizer); }
private static SummarizerParameters SetupSummariserParameters(string SearchTerm, string TitleLinkProperties, string SummaryProperties, int SummaryLength, string Fuzzieness = "1.0", int Wildcard = 0) { //Setup summarizer parameters double fuzzy; if (string.IsNullOrEmpty(Fuzzieness) || !double.TryParse(Fuzzieness, out fuzzy)) { fuzzy = 1.0; } var wildcardBool = Wildcard > 0; var summaryParameters = new SummarizerParameters { SearchTerm = SearchTerm }; if (SummaryLength > 0) { summaryParameters.SummaryLength = SummaryLength; } AddSummaryProperties(summaryParameters, TitleLinkProperties, SummaryProperties, fuzzy, wildcardBool); return(summaryParameters); }
/// <summary> /// Main XSLT Helper Search function, the laundry list of parameters are documented more fully in FullTextSearch.xslt /// Basically this constructs a search object and a highlighter object from the parameters, then calls another /// function to return search results as XML. /// </summary> /// <param name="searchType">MultiRelevance, MultiAnd, etc.</param> /// <param name="searchTerm">The search terms as entered by user</param> /// <param name="titleProperties">A list of umbraco properties, comma separated, to be searched as the page title</param> /// <param name="bodyProperties">A list of umbraco properties, comma separated, to be searched as the page body</param> /// <param name="rootNodes">Return only results under these nodes, set to blank or -1 to search all nodes</param> /// <param name="titleLinkProperties">Umbraco properties, comma separated, to use in forming the (optionally highlighted) title</param> /// <param name="summaryProperties">Umbraco properties, comma separated, to use in forming the (optionally highlighted) summary text</param> /// <param name="useHighlighting">Enable context highlighting(note this can slow things down)</param> /// <param name="summaryLength">Number of characters in the summary text</param> /// <param name="pageNumber">Page number of results to return</param> /// <param name="pageLength">Number of results on each page, zero disables paging and returns all results</param> /// <param name="fuzzieness">Amount 0-1 to "fuzz" the search, return non exact matches</param> /// <param name="wildcard">Add wildcard to the end of search term. Doesn't work together with fuzzyness</param> /// <returns></returns> public static XPathNodeIterator Search(string searchType, string searchTerm, string titleProperties, string bodyProperties, string rootNodes, string titleLinkProperties, string summaryProperties, int useHighlighting, int summaryLength, int pageNumber = 0, int pageLength = 0, string fuzzieness = "1.0", int wildcard = 0) { // Measure time taken. This could be done more neatly, but this is more accurate var stopwatch = new Stopwatch(); stopwatch.Start(); // Check search terms were actually entered if (String.IsNullOrEmpty(searchTerm)) { return(ReturnError("NoTerms", "You must enter a search term")); } // Setup search parameters double fuzzy; if (String.IsNullOrEmpty(fuzzieness) || !Double.TryParse(fuzzieness, out fuzzy)) { fuzzy = 1.0; } var wildcardBool = wildcard > 0; var searchParameters = new SearchParameters(); var searchProperties = GetSearchProperties(titleProperties, bodyProperties, fuzzy, wildcardBool); if (searchProperties != null) { searchParameters.SearchProperties = searchProperties; } searchParameters.RootNodes = GetRootNotes(rootNodes); searchParameters.SearchTerm = searchTerm; //Setup summarizer parameters var summaryParameters = new SummarizerParameters { SearchTerm = searchTerm }; if (summaryLength > 0) { summaryParameters.SummaryLength = summaryLength; } AddSummaryProperties(summaryParameters, titleLinkProperties, summaryProperties, fuzzy, wildcardBool); // Create summarizer according to highlighting option Summarizer summarizer; if (useHighlighting > 0) { summarizer = new Highlight(summaryParameters); } else { summarizer = new Plain(summaryParameters); } //Finally create search object and pass ISearchResults to XML renderer var search = new Search(searchParameters); switch (searchType) { case "MultiAnd": return(ResultsAsXml(search.ResultsMultiAnd(), summarizer, pageNumber, pageLength, stopwatch)); case "SimpleOr": return(ResultsAsXml(search.ResultsSimpleOr(), summarizer, pageNumber, pageLength, stopwatch)); case "AsEntered": return(ResultsAsXml(search.ResultsAsEntered(), summarizer, pageNumber, pageLength, stopwatch)); default: return(ResultsAsXml(search.ResultsMultiRelevance(), summarizer, pageNumber, pageLength, stopwatch)); } }