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

support Fulltext Indexing by Entity's status #138

Closed
lmtoo opened this issue Feb 24, 2020 · 11 comments
Closed

support Fulltext Indexing by Entity's status #138

lmtoo opened this issue Feb 24, 2020 · 11 comments

Comments

@lmtoo
Copy link

lmtoo commented Feb 24, 2020

Hi @paulcwarren , I have a problem , fulltext by entity's status, this entity already make association with content, but by this framework fulltext right after the content set. Is a avaliable provide a trigger to entity's content Indexing ?

@paulcwarren
Copy link
Owner

So, rather than automatically fulltext index content immediately after it is set, you want to delay fulltext indexing until some later time of your choosing? i.e. when an entity's status changes from "under review" to "approved" for example?

Is that right?

I'm guessing your entity is being routed around some sort of workflow?

@lmtoo
Copy link
Author

lmtoo commented Feb 25, 2020

yes, that right

@paulcwarren
Copy link
Owner

paulcwarren commented Mar 20, 2020

Hi @lmtoo I was thinking about this request and I have a proposal that I wanted to run past you.

Atm the fulltext indexing capability isn't a (spring) service yet. The indexing logic for both Elasticsearch and SolrSearch (if I recall you are using elastic) are implemented directly in afterSetContent store event handlers. Not very useful for other consumers. I would be more than happy. In fact, I think it is a better design anyway, to refactor that logic into a Elastic and Solr implementation of a FulltextIndexingService and have the existing store event handlers use that service instead of implement it themselves. This would provide you with a service you could autowire into your own code.

On the other hand I don't think there is much point in Spring Content having some sort of customizable fulltext triggering f/w; i.e. the logic that detects change in entity "status" and calls the fulltext indexing service. There are plenty of good trigger mechanisms in spring (aop, data rest event handlers, ...) and jpa (listeners) so I think the best alternative here is for you to implement that piece yourself using one of these existing frameworks. Otherwise, we would just be re-inventing the wheel to some extent and probably not really doing it justice. I would personally recommend using spring aop but you could use any. A spring aop solution might look something like this:-

@Aspect
public class IndexingAspect {
 
   @Autowired
    private MyEntityRepository repo;

   @Autowired
    private MyEntityStore store;

   @Autowired
   private FulltextIndexingService ftiService;

   @Around("execution(* my.CrudRepository.save(..))") 
   public void index(JoinPoint point) {

       MyEntity entityBeingSaved = (MyEntity)point.getArgs()[0];
       Status entityBeingSavedStatus = entityBeingSaved.getStatus();
       MyEntity existingEntity = repo.findById(entityBeingSaved.getId())
       Status existingStatus = existingEntity.getStatus();
       
       MyEntity savedEntity = point.proceed();

       if (entityBeingSavedStatus != existingStatus) {
          ftiService.index(savedEntity, store.getContent(savedEntity));
       
   }
}

Does this sound reasonable to you?

@lmtoo
Copy link
Author

lmtoo commented Mar 20, 2020

FulltextIndexingService is well, I can't wait to use this new feature

@paulcwarren
Copy link
Owner

Fixed in this commit.

I added brief documentation here. It should work as shown above.

I will cut 1.0.0.M8 for you tomorrow.

@lmtoo
Copy link
Author

lmtoo commented Apr 4, 2020

Hi @paulcwarren , I have seen this new feature just now ,but I can't close fulltextIndex right after the content set event through config.

@paulcwarren
Copy link
Owner

Hi @lmtoo sorry to hear that.

I added this test.

It was green in this build so I wanted to check my understanding of the issue. How does your case differ from the test?

@lmtoo
Copy link
Author

lmtoo commented Apr 8, 2020

Hi, @paulcwarren I'm sorry. I mean disable automatically fulltext index by configration application.properties. so I can index by
invoking IndexService method.

@paulcwarren
Copy link
Owner

I see. I had wondered if you wanted to do that. I should have asked. Make sense. I will see what we can do. Should be easy I think.

@paulcwarren
Copy link
Owner

@lmtoo do you use spring boot? spring boot offers much better support for properties and conditional beans than regular spring. We don't have a spring boot starter for elasticsearch but we should have one so I am thinking of implementing the new enable/disable property in a new spring-content-elasticsearch-boot-starter. would that work for you? or do you not use spring boot?

@paulcwarren
Copy link
Owner

Hi @lmtoo. This commit added a spring-content-elasticsearch-boot-starter that includes a spring.content.elasticsearch.autoindex property allowing you to disable auto indexing and is available in the latest 1.0.0.M10-SNAPSHOT.

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