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:
Sebastian Sdorra
2021-08-16 13:17:25 +02:00
committed by GitHub
parent 8330f8fddd
commit d1ea249539
8 changed files with 223 additions and 136 deletions

View File

@@ -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);
}

View File

@@ -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) {

View File

@@ -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);
}
}

View File

@@ -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);