Skip to content

msigut/LuceneNet48Demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LuceneNet48Demo

A demo of using Apache Lucene.NET 4.8 for .NET Core 2+ environment.

What's inside:

// 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");
Original text: My friends are visiting Montréal's engineering institutions
->
Tokens from analyzers: friend visit montreal engin institut
_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() and Release()
  • 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:

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy