Skip to content
Snippets Groups Projects
Commit fa4dac48 authored by uhensler's avatar uhensler
Browse files

OO-3971: Fix wrong search results if a taxonomy identifier contains blanks

parent de2fe096
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@ import org.olat.modules.qpool.QuestionItemFull;
import org.olat.modules.qpool.QuestionPoolModule;
import org.olat.modules.qpool.model.QItemDocument;
import org.olat.modules.qpool.model.QuestionItemImpl;
import org.olat.modules.taxonomy.TaxonomyLevel;
import org.olat.resource.OLATResource;
import org.olat.search.model.AbstractOlatDocument;
import org.olat.search.model.OlatDocument;
......@@ -183,7 +184,7 @@ public class QuestionItemDocumentFactory {
if(StringHelper.containsNonWhitespace(path)) {
for(StringTokenizer tokenizer = new StringTokenizer(path, "/"); tokenizer.hasMoreTokens(); ) {
String nextToken = tokenizer.nextToken();
document.add(new TextField(QItemDocument.TAXONOMIC_PATH_FIELD, nextToken, Field.Store.NO));
document.add(new TextField(QItemDocument.TAXONOMIC_IDENTIFIER_FIELD, nextToken, Field.Store.NO));
}
if(item instanceof QuestionItemImpl) {
Long key = ((QuestionItemImpl)item).getTaxonomyLevel().getKey();
......@@ -193,6 +194,12 @@ public class QuestionItemDocumentFactory {
document.add(field);
}
}
TaxonomyLevel taxonomyLevel = item.getTaxonomyLevel();
if (taxonomyLevel != null) {
String materializedPathKeys = taxonomyLevel.getMaterializedPathKeys().replaceAll(" ", "_").replaceAll("/", "_");
TextField field = new TextField(QItemDocument.TAXONOMIC_PATH_FIELD, materializedPathKeys, Field.Store.YES);
document.add(field);
}
}
return document;
}
......
......@@ -36,8 +36,8 @@ public class QItemDocument extends OlatDocument {
public static final String SHARE_FIELD = "share";
public static final String POOL_FIELD = "pool";
public static final String TAXONOMIC_FIELD = "taxonomyid";
public static final String TAXONOMIC_PATH_FIELD = "taxonomy";
public static final String TAXONOMIC_PATH_FIELD = "taxonomy"; // used in advanced search (subjects)
public static final String TAXONOMIC_IDENTIFIER_FIELD = "taxonomy"; // used in full text search field
public static final String IDENTIFIER_FIELD = "identifier";
public static final String MASTER_IDENTIFIER_FIELD = "master";
......
......@@ -22,8 +22,6 @@ package org.olat.modules.qpool.ui.metadata;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.olat.core.commons.services.license.LicenseModule;
import org.olat.core.commons.services.license.ui.LicenseSelectionConfig;
......@@ -434,21 +432,15 @@ public class ExtendedSearchController extends FormBasicController implements Ext
@Override
public FormItem createItem(String startValue) {
qpoolTaxonomyTreeBuilder.loadTaxonomyLevelsSelection(getIdentity(), false, allTaxonomyLevels);
return createItem(qpoolTaxonomyTreeBuilder.getTaxonomicPaths(),
return createItem(qpoolTaxonomyTreeBuilder.getTaxonomicKeyPaths(),
qpoolTaxonomyTreeBuilder.getSelectableValues(), startValue);
}
@Override
public List<String> getQueries(FormItem item) {
String val = getValue(item);
if(StringHelper.containsNonWhitespace(val)) {
String[] levels = val.substring(1).split("/");
return Stream.of(levels)
.map(level -> append(getDocAttribute(), ":(", level, ") "))
.collect(Collectors.toList());
}
return Collections.emptyList();
public String getValue(FormItem item) {
return super.getValue(item).replaceAll(" ", "_").replaceAll("/", "_") + "*";
}
}
public class LicenseQueryParameter extends SingleChoiceQueryParameter {
......
......@@ -59,6 +59,7 @@ public class QPoolTaxonomyTreeBuilder {
private String[] selectableKeys;
private String[] selectableValues;
private String[] taxonomicPaths;
private String[] taxonomicKeyPaths;
private List<TaxonomyLevel> treeTaxonomyLevels;
@Autowired
......@@ -125,6 +126,7 @@ public class QPoolTaxonomyTreeBuilder {
selectableKeys = new String[0];
selectableValues = new String[0];
taxonomicPaths = new String[0];
taxonomicKeyPaths = new String[0];
treeTaxonomyLevels = new ArrayList<>();
}
......@@ -145,6 +147,10 @@ public class QPoolTaxonomyTreeBuilder {
public String[] getTaxonomicPaths() {
return taxonomicPaths;
}
public String[] getTaxonomicKeyPaths() {
return taxonomicKeyPaths;
}
public List<TaxonomyLevel> getTreeTaxonomyLevels() {
return treeTaxonomyLevels;
......@@ -195,13 +201,15 @@ public class QPoolTaxonomyTreeBuilder {
selectableKeys = new String[selectableTaxonomyLevels.size()];
selectableValues = new String[selectableTaxonomyLevels.size()];
taxonomicPaths = new String[selectableTaxonomyLevels.size()];
taxonomicKeyPaths = new String[selectableTaxonomyLevels.size()];
for(int i=selectableTaxonomyLevels.size(); i-->0; ) {
TaxonomyLevel level = selectableTaxonomyLevels.get(i);
selectableKeys[i] = Long.toString(level.getKey());
selectableValues[i] = computeIntendention(level, new StringBuilder()).append(level.getDisplayName()).toString();
taxonomicPaths[i] = level.getMaterializedPathIdentifiers();
taxonomicKeyPaths[i] = level.getMaterializedPathKeys();
}
addEmptyEntry();
addEmptyEntry();
}
private StringBuilder computeIntendention(TaxonomyLevel level, StringBuilder intendation) {
......@@ -218,17 +226,21 @@ public class QPoolTaxonomyTreeBuilder {
String[] movedKeys = new String[selectableKeys.length + 1];
String[] movedValues = new String[selectableValues.length + 1];
String[] movedTaxonomicPaths = new String[taxonomicPaths.length + 1];
String[] movedTaxonomicKeyPaths = new String[taxonomicKeyPaths.length + 1];
movedKeys[0] = "-1";
movedValues[0] = "-";
movedTaxonomicPaths[0] = "/";
movedTaxonomicKeyPaths[0] = "/";
for (int i=selectableKeys.length; i-->0;) {
movedKeys[i+1] = selectableKeys[i];
movedValues[i+1] = selectableValues[i];
movedTaxonomicPaths[i+1] = taxonomicPaths[i];
movedTaxonomicKeyPaths[i+1] = taxonomicKeyPaths[i];
}
selectableKeys = movedKeys;
selectableValues = movedValues;
taxonomicPaths = movedTaxonomicPaths;
taxonomicKeyPaths = movedTaxonomicKeyPaths;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment