Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstaction of LuceneIndex.cs #351

Closed
croban opened this issue Oct 18, 2023 · 5 comments
Closed

Abstaction of LuceneIndex.cs #351

croban opened this issue Oct 18, 2023 · 5 comments

Comments

@croban
Copy link

croban commented Oct 18, 2023

Problem: overriding AddDocument Method

This code is used to access and set the private field _latestGen in a derived class.

var result = IndexWriter.UpdateDocuments(new Term(ExamineFieldNames.ItemIdFieldName, valueSet.Id), doc);

Type baseType = typeof(LuceneIndex);
FieldInfo privateFieldInfo = baseType.GetField("_latestGen", BindingFlags.Instance | BindingFlags.NonPublic);
if (privateFieldInfo != null)
{
    privateFieldInfo.SetValue(this, result);
}

Resolve Solution

Option 1: Making the Private Field Protected Abstract or Virtual

Should _latestGen be made a protected abstract field?

_latestGen = IndexWriter.UpdateDocument(new Term(ExamineFieldNames.ItemIdFieldName, valueSet.Id), doc);

should be at least:

protected abstract IndexWriter LatestGen { get; set; }

Option 2: Making the Method Virtual

Should the WaitForChanges method be made virtual?

public void WaitForChanges()

should be at least:

public virtual void WaitForChanges()
{
    if(mycustomupdatelatestGen) {
            base.WaitForChanges();
            return;
    }
    base.WaitForChanges();
}
@Shazwazza
Copy link
Owner

I need to understand why this is being done in the first place?

@croban
Copy link
Author

croban commented Oct 19, 2023

I want to create Block Index (BlockJoin) therefore I must use UpdateDocuments Method and I have to change
IndexWriter.UpdateDocument to IndexWriter.UpdateDocuments inside my override void AddDocument method.
Do you have maybe another solution for this?

@Shazwazza
Copy link
Owner

Really sorry for the long delay here. I can't fields or properties mutable read/write since that is dangerous and can easily result in folks making mistakes that are hard to debug.

An easy solution is to add a virtual method:

protected virtual long? UpdateLuceneDocument(Term term, Document doc)

Then you can override this, update the document as you wish and return your custom lastestGen value.

I'll get this done and ship a new version shortly.

@Shazwazza
Copy link
Owner

Will be shipped with 3.2.1 today.

@Shazwazza
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants