mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-03 15:48:37 +02:00
Improve search syntax page (#1770)
Remove non-searchable fields from syntax site, do no translate field names, use field name for title if no translation is available, refactor syntax page to respect error states
This commit is contained in:
@@ -66,7 +66,7 @@ public class AnalyzerFactory {
|
||||
Analyzer defaultAnalyzer = create(options);
|
||||
|
||||
Map<String, Analyzer> analyzerMap = new HashMap<>();
|
||||
for (LuceneSearchableField field : type.getFields()) {
|
||||
for (LuceneSearchableField field : type.getAllFields()) {
|
||||
addFieldAnalyzer(analyzerMap, field);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ class LuceneSearchableField implements SearchableField {
|
||||
private final boolean highlighted;
|
||||
private final PointsConfig pointsConfig;
|
||||
private final Indexed.Analyzer analyzer;
|
||||
private final boolean searchable;
|
||||
|
||||
LuceneSearchableField(Field field, Indexed indexed) {
|
||||
this.name = name(field, indexed);
|
||||
@@ -52,6 +53,7 @@ class LuceneSearchableField implements SearchableField {
|
||||
this.highlighted = indexed.highlighted();
|
||||
this.pointsConfig = IndexableFields.pointConfig(field);
|
||||
this.analyzer = indexed.analyzer();
|
||||
this.searchable = indexed.type().isSearchable();
|
||||
}
|
||||
|
||||
Object value(Document document) {
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Value
|
||||
public class LuceneSearchableType implements SearchableType {
|
||||
@@ -48,7 +49,7 @@ public class LuceneSearchableType implements SearchableType {
|
||||
Map<String, Float> boosts;
|
||||
Map<String, PointsConfig> pointsConfig;
|
||||
TypeConverter typeConverter;
|
||||
|
||||
|
||||
public LuceneSearchableType(Class<?> type, IndexedType annotation, List<LuceneSearchableField> fields) {
|
||||
this.type = type;
|
||||
this.name = name(type, annotation);
|
||||
@@ -101,7 +102,16 @@ public class LuceneSearchableType implements SearchableType {
|
||||
return Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<LuceneSearchableField> getFields() {
|
||||
return Collections.unmodifiableCollection(
|
||||
fields.stream()
|
||||
.filter(LuceneSearchableField::isSearchable)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
public Collection<LuceneSearchableField> getAllFields() {
|
||||
return Collections.unmodifiableCollection(fields);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class QueryResultFactory {
|
||||
private Hit createHit(ScoreDoc scoreDoc) throws IOException, InvalidTokenOffsetsException {
|
||||
Document document = searcher.doc(scoreDoc.doc);
|
||||
Map<String, Hit.Field> fields = new HashMap<>();
|
||||
for (LuceneSearchableField field : searchableType.getFields()) {
|
||||
for (LuceneSearchableField field : searchableType.getAllFields()) {
|
||||
field(document, field).ifPresent(f -> fields.put(field.getName(), f));
|
||||
}
|
||||
return new Hit(document.get(FieldNames.ID), document.get(FieldNames.REPOSITORY), scoreDoc.score, fields);
|
||||
|
||||
Reference in New Issue
Block a user