-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: n-gram analyzer added * chore: code cleaning * chore: code cleaning
- Loading branch information
Showing
6 changed files
with
56 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
opal-search/src/main/java/org/obiba/opal/search/service/impl/VariablesAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2024 OBiBa. All rights reserved. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the GNU Public License v3.0. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.obiba.opal.search.service.impl; | ||
|
||
import org.apache.lucene.analysis.*; | ||
import org.apache.lucene.analysis.ngram.NGramTokenFilter; | ||
import org.apache.lucene.analysis.standard.StandardAnalyzer; | ||
import org.apache.lucene.analysis.standard.StandardTokenizer; | ||
|
||
public class VariablesAnalyzer extends Analyzer { | ||
|
||
private final int minGram; | ||
private final int maxGram; | ||
|
||
public VariablesAnalyzer(int minGram, int maxGram) { | ||
this.minGram = minGram; | ||
this.maxGram = maxGram; | ||
} | ||
@Override | ||
protected TokenStreamComponents createComponents(String fieldName) { | ||
final StandardTokenizer src = new StandardTokenizer(); | ||
src.setMaxTokenLength(StandardAnalyzer.DEFAULT_MAX_TOKEN_LENGTH); | ||
TokenStream tok = new LowerCaseFilter(src); | ||
tok = new StopFilter(tok, CharArraySet.EMPTY_SET); | ||
tok = new NGramTokenFilter(tok, minGram, maxGram, true); | ||
return new TokenStreamComponents( | ||
r -> { | ||
src.setMaxTokenLength(StandardAnalyzer.DEFAULT_MAX_TOKEN_LENGTH); | ||
src.setReader(r); | ||
}, | ||
tok); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters