A demo of using Apache Lucene.NET 4.8 for .NET Core 2+ environment.
What's inside:
- AliasMultiFieldQueryParser - Multifield query parser with alias support
// make alias for fields: "t" -> "title"; "s" -> "summary"
_queryParser = new AliasMultiFieldQueryParser(MATCH_LUCENE_VERSION, new[] { "title", "sumary" }, _analyzer,
new Dictionary<string, string>()
{
{ "t", "title" },
{ "s", "summary" }
});
// (query: title:term summary:cyborg)
result = search.Search("t:term s:cyborg");
- EnhEnglishAnalyzer - Enhanced English Lucene analyzer (based on article: Tuning Lucene to Get the Most Relevant Results and Search with Lucene.Net 4.8 (Part 2) - A Few Tricks and Tips)
Original text: My friends are visiting Montréal's engineering institutions
->
Tokens from analyzers: friend visit montreal engin institut
- MultiFieldAnalyzerWrapper - For assign multiple fields to Analyzer + one as default for all other fields
_analyzer = new MultiFieldAnalyzerWrapper(
defaultAnalyzer: new EnhEnglishAnalyzer(MATCH_LUCENE_VERSION, true),
new[]
{
(
// analyzer for fields: "genre", "year"
new[] { "genre", "year" },
Analyzer.NewAnonymous(createComponents: (fieldName, reader) =>
{
var source = new KeywordTokenizer(reader);
TokenStream result = new ASCIIFoldingFilter(source);
result = new LowerCaseFilter(MATCH_LUCENE_VERSION, result);
return new TokenStreamComponents(source, result);
})
)
});
- ForEachTermDocs - For get documents by Term, only selected fields to work with
// II. use term & selected fields
_writer.ForEachTermDocs(new Term("year", "1194"), new[] { "title" }, d =>
{
var title = d.GetField("title").GetStringValue();
// do something ...
});
- using SearcherManager +
MaybeRefreshBlocking()
,Acquire()
andRelease()
- using UpdateDocument() +
new Term(keyField, ...)
(based on article: Lucene .NET Update data) - using DeleteDocuments +
MaybeRefreshBlocking()
+new Term(keyField, ...)
(for solving issue: C# Lucene.Net IndexWriter.DeleteDocuments not working - to check Analyzer work use PrintTokens() method to log all tokens per
field
- use example data MovieDatabase +
int Id
(based on code: r15h1/lucenedemo)
Packages: