fix index

This commit is contained in:
_Bastler 2021-12-04 11:10:53 +01:00
parent 6109d25816
commit 8b20596398
2 changed files with 11 additions and 4 deletions

View File

@ -3,6 +3,7 @@
*/ */
package de.bstly.board; package de.bstly.board;
import org.apache.lucene.analysis.charfilter.HTMLStripCharFilterFactory;
import org.apache.lucene.analysis.core.LowerCaseFilterFactory; import org.apache.lucene.analysis.core.LowerCaseFilterFactory;
import org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilterFactory; import org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilterFactory;
import org.apache.lucene.analysis.snowball.SnowballPorterFilterFactory; import org.apache.lucene.analysis.snowball.SnowballPorterFilterFactory;
@ -26,11 +27,13 @@ public class LuceneConfig implements LuceneAnalysisConfigurer {
@Override @Override
public void configure(LuceneAnalysisConfigurationContext context) { public void configure(LuceneAnalysisConfigurationContext context) {
context.analyzer("english").custom().tokenizer(StandardTokenizerFactory.class) context.analyzer("english").custom().tokenizer(StandardTokenizerFactory.class)
.charFilter(HTMLStripCharFilterFactory.class)
.tokenFilter(LowerCaseFilterFactory.class) .tokenFilter(LowerCaseFilterFactory.class)
.tokenFilter(SnowballPorterFilterFactory.class).param("language", "English") .tokenFilter(SnowballPorterFilterFactory.class).param("language", "English")
.tokenFilter(ASCIIFoldingFilterFactory.class); .tokenFilter(ASCIIFoldingFilterFactory.class);
context.analyzer("german").custom().tokenizer(StandardTokenizerFactory.class) context.analyzer("german").custom().tokenizer(StandardTokenizerFactory.class)
.charFilter(HTMLStripCharFilterFactory.class)
.tokenFilter(LowerCaseFilterFactory.class) .tokenFilter(LowerCaseFilterFactory.class)
.tokenFilter(SnowballPorterFilterFactory.class).param("language", "German") .tokenFilter(SnowballPorterFilterFactory.class).param("language", "German")
.tokenFilter(ASCIIFoldingFilterFactory.class); .tokenFilter(ASCIIFoldingFilterFactory.class);

View File

@ -93,16 +93,20 @@ public class SearchManager implements SmartInitializingSingleton {
if (classes.contains(Entry.class)) { if (classes.contains(Entry.class)) {
return searchSession.search(classes) return searchSession.search(classes)
.where(f -> f.bool() .where(f -> f.bool()
.should(f.match().fields("title", "title_de").matching(search) .should(f.match().field("title").matching(search)
.boost(settingsManager.getGravity())) .boost(settingsManager.getGravity()))
.should(f.match().fields("text", "text_de").matching(search))) .should(f.match().field("title_de").matching(search)
.boost(settingsManager.getGravity()))
.should(f.match().field("text").matching(search))
.should(f.match().field("text_de").matching(search)))
.sort(f -> sortByDate .sort(f -> sortByDate
? (asc ? f.field("created").asc() : f.field("created").desc()) ? (asc ? f.field("created").asc() : f.field("created").desc())
: (asc ? f.score().asc() : f.score().desc())) : (asc ? f.score().asc() : f.score().desc()))
.fetch(page * size, size); .fetch(page * size, size);
} else { } else {
return searchSession.search(classes).where( return searchSession.search(classes)
f -> f.bool().should(f.match().fields("text", "text_de").matching(search))) .where(f -> f.bool().should(f.match().field("text").matching(search))
.should(f.match().field("text_de").matching(search)))
.sort(f -> sortByDate .sort(f -> sortByDate
? (asc ? f.field("created").asc() : f.field("created").desc()) ? (asc ? f.field("created").asc() : f.field("created").desc())
: (asc ? f.score().asc() : f.score().desc())) : (asc ? f.score().asc() : f.score().desc()))