Skip to content

Commit

Permalink
Merge pull request #188 from scireum/dhe/fix-prefixsearchableentity
Browse files Browse the repository at this point in the history
Allows to recalculate the searchPrefixes field
  • Loading branch information
andyHa authored Oct 16, 2018
2 parents 91cb832 + 4cf3fc7 commit d9c520f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<properties>
<sirius.kernel>12.0-rc26</sirius.kernel>
<sirius.web>19.0-rc23</sirius.web>
<sirius.db>5.0-rc33</sirius.db>
<sirius.db>5.0-rc38</sirius.db>
</properties>

<dependencies>
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/sirius/biz/mongo/PrefixSearchableEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sirius.db.mixing.Mapping;
import sirius.db.mixing.annotations.BeforeSave;
import sirius.db.mixing.annotations.Index;
import sirius.db.mixing.annotations.Transient;
import sirius.db.mixing.types.NestedList;
import sirius.db.mixing.types.StringList;
import sirius.db.mixing.types.StringListMap;
Expand Down Expand Up @@ -39,9 +40,12 @@ public abstract class PrefixSearchableEntity extends MongoEntity {
@NoJournal
private final StringList searchPrefixes = new StringList();

@Transient
private boolean forceUpdateSearchPrefixes;

@BeforeSave
protected void updateSearchField() {
if (!isNew() && !isAnyMappingChanged()) {
if (!isNew() && !forceUpdateSearchPrefixes && !isAnyMappingChanged()) {
return;
}

Expand Down Expand Up @@ -110,4 +114,11 @@ private void appendSingleToken(String subToken) {
public StringList getSearchPrefixes() {
return searchPrefixes;
}

/**
* Forces the search prefixes to be recalculated on the next {@link BeforeSave} event.
*/
public void forceUpdateOfSearchPrefixes() {
this.forceUpdateSearchPrefixes = true;
}
}

0 comments on commit d9c520f

Please sign in to comment.