Skip to content

Commit 19b7ca8

Browse files
committed
simplified GetHighlight text query
1 parent f88a35d commit 19b7ca8

File tree

4 files changed

+7
-14
lines changed

4 files changed

+7
-14
lines changed

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Umbraco Look (Alpha)
2-
Umbraco Examine Lucene indexer and searcher with support for text match highlighting and geospatial queries.
2+
Extends Umbraco Examine adding support for: text match highlighting, geospatial querying and tag faceting.
33

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

@@ -91,8 +91,7 @@ var lookQuery = new LookQuery()
9191

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

src/Our.Umbraco.Look.sln

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ EndProject
1313
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{453855DC-542E-404A-9378-D53153A59C8F}"
1414
ProjectSection(SolutionItems) = preProject
1515
..\build\Package.nuspec = ..\build\Package.nuspec
16-
..\build\Package.xml = ..\build\Package.xml
1716
EndProjectSection
1817
EndProject
1918
Global

src/Our.Umbraco.Look/Models/TextQuery.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@ public class TextQuery
1313
public float Fuzzyness { get; set; } = 0;
1414

1515
/// <summary>
16-
/// The max number of fragments to show, 0 = highlighting disabled
16+
/// When true (and SearchText provided), a hightlight extract containing the search text will be returned
1717
/// </summary>
18-
public int HighlightFragments { get; set; } = 0;
19-
20-
/// <summary>
21-
/// Text rendered between any highlight fragments
22-
/// </summary>
23-
public string HighlightSeparator { get; set; } = "...";
18+
public bool GetHighlight { get; set; } = false;
2419

2520
/// <summary>
2621
/// Flag to indicate whether the source text field should be returned

src/Our.Umbraco.Look/Services/LookSearchService.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public static LookResult Query(LookQuery lookQuery)
250250
}
251251

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

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

274274
return new HtmlString(highlight);
275275
};

0 commit comments

Comments
 (0)