Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Merge pull request #2 from aaerofeev/7.6.0
Browse files Browse the repository at this point in the history
7.6.0 Support
  • Loading branch information
papahigh authored Oct 7, 2020
2 parents 2e5184e + d67798a commit 5e3d972
Show file tree
Hide file tree
Showing 35 changed files with 221 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: java
jdk: openjdk-12
jdk: openjdk-13
sudo: false
before_install: chmod +x gradlew

Expand Down
2 changes: 2 additions & 0 deletions README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ Each options array contains an option object that includes the suggested text an
}
--------------------------------------------------

Extension for go client github.com/olivere/elastic: https://github.com/aaerofeev/go-elasic-keyboard-layout

=== Suggester options
List of the supported suggester options is as follows:

Expand Down
17 changes: 14 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ buildscript {
}
}


plugins {
id 'java'
id 'com.github.hierynomus.license' version "0.15.0"
}

apply plugin: 'java'


configurations.all {
resolutionStrategy.dependencySubstitution {
substitute project(':rest-api-spec') with module ("org.elasticsearch:rest-api-spec:${versions.elasticsearch}")
}
}

apply plugin: 'jacoco'
apply plugin: "com.github.hierynomus.license"
apply plugin: 'elasticsearch.esplugin'
Expand All @@ -26,6 +35,8 @@ group = 'org.elasticsearch.plugin'
description = 'Elasticsearch plugin for keyboard layout suggestions.'
version = "${versions.elasticsearch}"



license {
header = rootProject.file("HEADER.txt")
ext.year = Calendar.getInstance().get(Calendar.YEAR)
Expand Down Expand Up @@ -57,8 +68,8 @@ checkstyleTest.enabled = true
dependencyLicenses.enabled = true
thirdPartyAudit.enabled = true

integTestCluster {
numNodes = 2
testClusters.integTest {
numberOfNodes = 2
}

dependencyLicenses {
Expand Down Expand Up @@ -93,7 +104,7 @@ dependencies {
compile "org.apache.lucene:lucene-analyzers-phonetic:${versions.lucene}"

testCompile "junit:junit:4.12"
testCompile "org.hamcrest:hamcrest-all:1.3"
testCompile "org.hamcrest:hamcrest:2.1"
testCompile "org.assertj:assertj-core:3.10.0"
testCompile "org.elasticsearch.test:framework:${versions.elasticsearch}"
}
Binary file not shown.
Binary file added dist/keyboard-layout-7.6.1.zip
Binary file not shown.
Binary file added dist/keyboard-layout-7.6.2.zip
Binary file not shown.
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3"

# Environment for elasticsearch 7.6.x
services:
# run tests
tests:
image: openjdk:13-oracle
volumes:
- ./:/code
environment:
- JAVA13_HOME=/usr/java/openjdk-13
working_dir: /code
command:
./gradlew check

# run assemble
assemble:
image: openjdk:13-oracle
volumes:
- ./:/code
environment:
- JAVA13_HOME=/usr/java/openjdk-13
working_dir: /code
command:
./gradlew assemble
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
29 changes: 12 additions & 17 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -175,14 +175,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
3 changes: 3 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

Expand Down
1 change: 0 additions & 1 deletion licenses/lucene-analyzers-phonetic-8.0.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions licenses/lucene-analyzers-phonetic-8.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e47cb4efd4e9e071e0563dd44f1759ea1e712ca7
5 changes: 5 additions & 0 deletions releases.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ Please find an appropriate release which corresponds to your elasticsearch versi
| 7.0.0 | 7.0.0 | https://github.com/papahigh/elasticsearch-keyboard-layout/raw/master/dist/keyboard-layout-7.0.0.zip
|==============================================

== Requirements

- adopt-openjdk 13.0.2

See elasticsearch repository for details
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
rootProject.name = 'Russian Keyboard Layout Suggestions'
include ':rest-api-spec'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,15 +24,18 @@

public class KeyboardAnalyzerProvider extends AbstractIndexAnalyzerProvider<WhitespaceAnalyzer> {

private static final WhitespaceAnalyzer INSTANCE = new WhitespaceAnalyzer();
private final WhitespaceAnalyzer analyzer;

public KeyboardAnalyzerProvider(IndexSettings indexSettings, Environment env,
String name, Settings settings) {
super(indexSettings, name, settings);

analyzer = new WhitespaceAnalyzer();
analyzer.setVersion(version);
}

@Override
public WhitespaceAnalyzer get() {
return INSTANCE;
return this.analyzer;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,7 +26,7 @@ public class KeyboardLayoutTokenizerFactory extends AbstractTokenizerFactory {

public KeyboardLayoutTokenizerFactory(IndexSettings indexSettings,
Environment env, String name, Settings settings) {
super(indexSettings, settings);
super(indexSettings, settings, name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,11 +25,15 @@
import org.apache.lucene.util.CharsRefBuilder;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.search.suggest.Suggest;
import org.elasticsearch.search.suggest.Suggester;
import org.elasticsearch.search.suggest.SuggestionSearchContext;
import org.elasticsearch.search.suggest.phrase.DirectCandidateGenerator;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;


Expand All @@ -41,12 +45,56 @@ private KeyboardLayoutSuggester() {
}

@Override
protected KeyboardLayoutSuggestion innerExecute(String name, KeyboardLayoutSuggestionContext context,
protected KeyboardLayoutSuggestion innerExecute(String name, KeyboardLayoutSuggestionContext suggestion,
IndexSearcher searcher, CharsRefBuilder spare) throws IOException {
KeyboardLayoutSuggestion accumulator = new KeyboardLayoutSuggestion(name, context.getSize());
SuggestionsGenerator generator = new SuggestionsGenerator(searcher.getIndexReader(), accumulator, context);
DirectCandidateGenerator.analyze(context.getAnalyzer(), context.getText(), context.getField(), generator, spare);
return accumulator;
KeyboardLayoutSuggestion response = new KeyboardLayoutSuggestion(name, suggestion.getSize());
SuggestionsGenerator generator = new SuggestionsGenerator(searcher.getIndexReader(), response, suggestion);
DirectCandidateGenerator.analyze(suggestion.getAnalyzer(), suggestion.getText(), suggestion.getField(), generator, spare);
return response;
}

@Override
protected Suggest.Suggestion<? extends Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option>> emptySuggestion(
String name, KeyboardLayoutSuggestionContext suggestion, CharsRefBuilder spare) throws IOException {

KeyboardLayoutSuggestion layoutSuggestion = new KeyboardLayoutSuggestion(name, suggestion.getSize());
List<Token> tokens = queryTerms(suggestion, spare);
for (Token token : tokens) {
Text key = new Text(new BytesArray(token.term.bytes()));
KeyboardLayoutSuggestion.Entry resultEntry = new KeyboardLayoutSuggestion.Entry(
key, token.startOffset, token.endOffset - token.startOffset);
layoutSuggestion.addTerm(resultEntry);
}
return layoutSuggestion;
}

private static List<Token> queryTerms(SuggestionSearchContext.SuggestionContext suggestion,
CharsRefBuilder spare) throws IOException {
final List<Token> result = new ArrayList<>();
final String field = suggestion.getField();
DirectCandidateGenerator.analyze(suggestion.getAnalyzer(), suggestion.getText(), field,
new DirectCandidateGenerator.TokenConsumer() {
@Override
public void nextToken() {
Term term = new Term(field, BytesRef.deepCopyOf(fillBytesRef(new BytesRefBuilder())));
result.add(new Token(term, offsetAttr.startOffset(), offsetAttr.endOffset()));
}
}, spare);
return result;
}

private static class Token {

public final Term term;
public final int startOffset;
public final int endOffset;

private Token(Term term, int startOffset, int endOffset) {
this.term = term;
this.startOffset = startOffset;
this.endOffset = endOffset;
}

}

static class SuggestionsGenerator extends DirectCandidateGenerator.TokenConsumer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Nikolay Papakha
* Copyright 2020 Nikolay Papakha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 5e3d972

Please sign in to comment.