Skip to content

Commit

Permalink
simplified GetHighlight text query
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendy committed Oct 27, 2018
1 parent f88a35d commit 19b7ca8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Umbraco Look (Alpha)
Umbraco Examine Lucene indexer and searcher with support for text match highlighting and geospatial queries.
Extends Umbraco Examine adding support for: text match highlighting, geospatial querying and tag faceting.

[The NuGet Package](https://www.nuget.org/packages/Our.Umbraco.Look) installs a single assembly _Our.Umbraco.Look.dll_ with dependencies on:

Expand Down Expand Up @@ -91,8 +91,7 @@ var lookQuery = new LookQuery()

TextQuery = new TextQuery() {
SearchText = "some text to search for",
HighlightFragments = 2, // highlight text containing the search term twice should be returned
HighlightSeparator = " ... ", // text to inject between any search term matches
GetHighlight = true, // return highlight extract from the text field containing the search text
GetText = true // raw text field should be returned (potentially a large document)
},

Expand Down
1 change: 0 additions & 1 deletion src/Our.Umbraco.Look.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{453855DC-542E-404A-9378-D53153A59C8F}"
ProjectSection(SolutionItems) = preProject
..\build\Package.nuspec = ..\build\Package.nuspec
..\build\Package.xml = ..\build\Package.xml
EndProjectSection
EndProject
Global
Expand Down
9 changes: 2 additions & 7 deletions src/Our.Umbraco.Look/Models/TextQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ public class TextQuery
public float Fuzzyness { get; set; } = 0;

/// <summary>
/// The max number of fragments to show, 0 = highlighting disabled
/// When true (and SearchText provided), a hightlight extract containing the search text will be returned
/// </summary>
public int HighlightFragments { get; set; } = 0;

/// <summary>
/// Text rendered between any highlight fragments
/// </summary>
public string HighlightSeparator { get; set; } = "...";
public bool GetHighlight { get; set; } = false;

/// <summary>
/// Flag to indicate whether the source text field should be returned
Expand Down
6 changes: 3 additions & 3 deletions src/Our.Umbraco.Look/Services/LookSearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static LookResult Query(LookQuery lookQuery)
}

// setup the getHightlight func if required
if (lookQuery.TextQuery.HighlightFragments > 0 && !string.IsNullOrWhiteSpace(lookQuery.TextQuery.SearchText))
if (lookQuery.TextQuery != null && lookQuery.TextQuery.GetHighlight && !string.IsNullOrWhiteSpace(lookQuery.TextQuery.SearchText))
{
var queryParser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, LookConstants.TextField, LookService.Analyzer);

Expand All @@ -268,8 +268,8 @@ public static LookResult Query(LookQuery lookQuery)
var highlight = highlighter.GetBestFragments(
tokenStream,
x,
lookQuery.TextQuery.HighlightFragments, // max number of fragments
lookQuery.TextQuery.HighlightSeparator); // fragment separator
1, // max number of fragments
"...");

return new HtmlString(highlight);
};
Expand Down

0 comments on commit 19b7ca8

Please sign in to comment.