Lucene .net + equivalent of SpanMultiTermQueryWrapper<MultiTermQuery> in C# - lucene.net

I need to convert the following Java code to C# but I couldn't find the equivalent of "SpanMultiTermQueryWrapper". Could you please help?
FuzzyQuery firstNameQuery = new FuzzyQuery(new Term("text", firstName), 2);
FuzzyQuery lastNameQuery = new FuzzyQuery(new Term("text", lastName), 2);
SpanQuery[] clauses = new SpanQuery[] {
new SpanMultiTermQueryWrapper<MultiTermQuery>(firstNameQuery),
new SpanMultiTermQueryWrapper<MultiTermQuery>(lastNameQuery)
};
SpanNearQuery spanNearQuery = new SpanNearQuery(clauses, 3, false);

SpanMultiTermQueryWrapper and MultiTermQuery are both available on Lucene.Net 4.8.0-beta00004.
If you need support in earlier versions of Lucene.Net, you can probably just grab the source code from the above links and any dependencies and drop them into a library for your applications.

Related

PiranhaCMS Localization

I'm new to this CMS library. I'm using .NET 5 and doing the localization. I write some code to change the culture like:
CultureInfo ci = new(culture);
CultureInfo.DefaultThreadCurrentCulture = ci;
CultureInfo.DefaultThreadCurrentUICulture = ci;
It worked when I use my resources files "resources.en-US.resx" or "resources.vi-VN.resx" (I set new supported CultureInfo "en-US" and "vi-VN") but when I change resources files in Piranha.Manager.Localization from "General.vi.resx" to "General.vi-VN.resx"(for matching the culture format) it did not work anymore.
And if I set new supported CultureInfo to "en" and "vi" (for matching with resources files in Piranha.Manager.Localization) it still not works.
services.Configure<RequestLocalizationOptions>(
opt =>
{
var supportedCultres = new List<CultureInfo>
{
new CultureInfo("en"),
new CultureInfo("vi")
};
opt.DefaultRequestCulture = new RequestCulture("en");
opt.SupportedCultures = supportedCultres;
opt.SupportedUICultures = supportedCultres;
});
I don't know what I'm doing is right way to setup localization for piranha or not? I can't find any tutorial for that.
Can you help me for localization for PiranhaCMS?
I really appreciate that.
Best Regard

iTextSharp and Hyphenation

In earlier versions of iTextSharp, I have incorporated hyphenation in the following way (example is for German hyphenation):
HyphenationAuto autoDE = new HyphenationAuto("de", "DR", 3, 3);
BaseFont.AddToResourceSearch(RuntimePath + "itext-hyph-xml.dll");
chunk = new Chunk(text).SetHyphenation(autoDE);
In recent versions of iText, this is no longer possible as the function
BaseFont.AddToResourceSearch()
has been removed from iText. Now how to replace this statement?
When inspecting the 2nd ed. of the iText IN ACTION manual, the statement need not be replaced at all, apparently. When doing so, however, no hyphenation takes place (and no errors occur). I also have taken a newer version of
itext-hyph-xml.dll
and re-referenced it. Same result, no hyphenation. This file resides on the same path as iTextSharp.dll, and I have included the path in the CLASSPATH environment variable. Nothing helps. I'm stuck, please help.
Calling iTextSharp.text.io.StreamUtil.AddToResourceSearch() works for me:
var content = #"
Allein ist besser als mit Schlechten im Verein: mit Guten im Verein, ist besser als allein.
";
var table = new PdfPTable(1);
// make sure .dll is in correct /bin directory
StreamUtil.AddToResourceSearch("itext-hyph-xml.dll");
using (var stream = new MemoryStream())
{
using (var document = new Document(PageSize.A8.Rotate()))
{
PdfWriter.GetInstance(document, stream);
document.Open();
var chunk = new Chunk(content)
.SetHyphenation(new HyphenationAuto("de", "DR", 3, 3));
table.AddCell(new Phrase(chunk));
document.Add(table);
}
File.WriteAllBytes(OUT_FILE, stream.ToArray());
}
Tested with iTextSharp 5.5.11 and itext-hyph-xml 2.0.0.0. Output PDF:

Unity 5.3 and .NET | AppendText & CreateText

Even though I have already changed the API Compatibility Level from .NET 2.0 Subset to .NET 2.0 in Edit->Project Settings->Player under Optimizations, upon upgrading to Unity 5.3.0 I am still getting the following two error messages:
`System.IO.File' does not contain a definition for `AppendText'
`System.IO.File' does not contain a definition for `CreateText'
They refer to the following code snippets:
using(StreamWriter writer = File.CreateText(saveFilePath))
{
string sLine = "time;joint;pos_x;pos_y;poz_z";
writer.WriteLine(sLine);
}
using(StreamWriter writer = File.AppendText(saveFilePath))
{
string sLine = string.Format("{0:F3};{1};{2:F3};{3:F3};{4:F3}", Time.time, (int)joint, jointPos.x, jointPos.y, jointPos.z);
writer.WriteLine(sLine);
}
How do I resolve this?
Are you tried this case?
using (var f = new StreamWriter("file path", true))
{
f.WriteLine("appended text");
f.Flush();
}

Why are definitions missing ? Lucene.Net 3.0.3 - Fast Vector Highlighter

As a newbie to Lucene.Net/Lucene and to C# I was able to put some lines of code and have a search running.
Now I want to get a snippet of the found area back. I have found below code but Visual Studio keeps telling me that a) "Searcher does contain a definition of getIndexReader" and b) "ScoreDoc does not contain a definition of doc" -and I don't get the point where the problem is!
Is there anybody out there who can help.
I am using Lucene.Net 3.0.3 and Lucene Contrib 3.0.3 on Visual Studio 2010 Express.
See the code I have below.
Thanks for your help!
RC
IndexReader indexReader = IndexReader.Open(directory, true);
Searcher indexSearch = new IndexSearcher(indexReader);
var queryParser = new QueryParser(Version.LUCENE_30, "text", analyzer);
var query = queryParser.Parse("\"system AKZ\"~10");
Console.WriteLine("Searching for: " + query);
TopDocs hits = indexSearch.Search(query,500);
/// Highlighter
FastVectorHighlighter fvHighlighter = new FastVectorHighlighter(true, true);
for (int i = 0; i < hits.ScoreDocs.Length; i++)
{
string bestfragment fvHighlighter.GetBestFragment(fvHighlighter.GetFieldQuery(query),indexSearch.getIndexReader(), hits.ScoreDocs[i].doc, "text", 20);
MessageBox.Show(bestfragment);
}
Console.WriteLine("Results Found: " + hits.TotalHits);
I would pull out something like ILSpy to examine what methods actually are available.
This is just a problem with the case of the method names. It's GetIndexReader() for example not getIndexReader(). You are probably basing this on docs for the Java implementation.
in Lucene.net this method's name is IndexReader.

How to execute the code generated by codeDom?

I just generated the .cs file using codeDom. Can someone explain how do I execute it?
The code below will allow you to compile the code using the codedom and then you can show the user if the code compiled correctly or not. It even creates a DLL as well.
Thanks
Alex
// Store provider from the method into a object, Default is CSharpCodeProvider**
CodeDomProvider provider = this.GetCurrentProvider();
// Configure a CompilerParameters that links System.dll**
String[] referenceAssemblies = { "System.dll", "System.Data.Linq.dll", "System.Web.dll","System.XML.dll","System.ComponentModel.DataAnnotations.dll", "System.Data.dll", _mvcLocation };
CompilerParameters cp = new CompilerParameters(referenceAssemblies, this.fileLocation + this.fileName + ".dll", false);
// Generate an executable rather than a DLL file.**
cp.GenerateExecutable = true;
// Invoke compilation.**
CompilerResults _results = provider.CompileAssemblyFromFile(cp, this.fileLocation + this.fileName + "." + this.extention);
It's not quite that simple. See here for a primer. Basically the CodeDom supports scenarios such as code generation and dynamic compilation. So .cs files created with the CodeDom are not executables in the usual sense.