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

Commit

Permalink
7.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
papahigh committed Sep 4, 2019
1 parent cdbbcd0 commit 5c6f2dd
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 14 deletions.
13 changes: 12 additions & 1 deletion 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 @@ -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.
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.3.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 3 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -125,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem http://www.apache.org/licenses/LICENSE-2.0
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
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.1.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6fac1ff799b86f872b67e7fad55120d338daa86f
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
Expand Up @@ -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
@@ -0,0 +1,76 @@
"Keyboard Layout Suggester [empty options]":
- do:
cluster.health:
wait_for_nodes: 2

- is_true: cluster_name
- is_false: timed_out
- gte: { number_of_nodes: 2 }
- gte: { number_of_data_nodes: 2 }

- do:
indices.create:
index: suggester_defaults
body:
settings:
number_of_shards: 2
number_of_replicas: 0
index:
analysis:
analyzer:
my_analyzer:
tokenizer: standard
mappings:
properties:
content:
type: text
analyzer: "my_analyzer"

- do:
bulk:
index: suggester_defaults
refresh: true
body:
- '{"index": {"_index": "suggester_defaults", "_id": "1"}}'
- '{ "content": "Кроссовки женские Nike MD Runner 2" }'
- '{"index": {"_index": "suggester_defaults", "_id": "2"}}'
- '{ "content": "Валенки мужские Nike MD Runner 2" }'
- '{"index": {"_index": "suggester_defaults", "_id": "3"}}'
- '{ "content": "Кроссовки для мальчиков Nike MD Runner 2." }'
- '{"index": {"_index": "suggester_defaults", "_id": "4"}}'
- '{ "content": "Кроссовки мужские Nike Runner 2 Mid Prem." }'

- do:
indices.refresh:
index: "_all"

- do:
search:
size: 0
index: suggester_defaults
body:
suggest:
text: 'Nike Кроссовки Runner 2'
keyboard_layout_default:
keyboard_layout:
field: content
language: russian

- length: { suggest.keyboard_layout_default: 4 }
- match: { suggest.keyboard_layout_default.0.text: 'Nike' }
- match: { suggest.keyboard_layout_default.0.offset: 0 }
- match: { suggest.keyboard_layout_default.0.length: 4 }
- length: { suggest.keyboard_layout_default.0.options: 0 }
- match: { suggest.keyboard_layout_default.1.text: 'Кроссовки' }
- match: { suggest.keyboard_layout_default.1.offset: 5 }
- match: { suggest.keyboard_layout_default.1.length: 9 }
- length: { suggest.keyboard_layout_default.1.options: 0 }
- match: { suggest.keyboard_layout_default.2.text: 'Runner' }
- match: { suggest.keyboard_layout_default.2.offset: 15 }
- match: { suggest.keyboard_layout_default.2.length: 6 }
- length: { suggest.keyboard_layout_default.2.options: 0 }
- match: { suggest.keyboard_layout_default.3.text: '2' }
- match: { suggest.keyboard_layout_default.3.offset: 22 }
- match: { suggest.keyboard_layout_default.3.length: 1 }
- length: { suggest.keyboard_layout_default.3.options: 0 }

4 changes: 2 additions & 2 deletions versions.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# main
elasticsearch = 7.0.0
lucene = 8.0.0
elasticsearch = 7.3.0
lucene = 8.1.0
commonscodec = 1.11

0 comments on commit 5c6f2dd

Please sign in to comment.