This project supports the automatic completion
of the word.
Also, you can include points in the word. (like as related contents points for the Instagram)
Each step was tested 10 times. (10k words, 100k words, 100k fixed length words)
You can checkout the Autocomplete benchmark project for details and review/run the benchmarks yourself.
The average response rate is as follows :
1 Environments : Local(macbook), 2.5 GHz Intel Core i7, 16GB 1600 MHz DDR32 10k words: https://github.com/first20hours/google-10000-english
3 100k words: https://gist.github.com/h3xx/1976236
Add the following dependency in pom.xml (Java 8 maven artifact)
<dependency>
<groupId>com.github.okihouse</groupId>
<artifactId>autocomplete</artifactId>
<version>1.0.1</version>
</dependency>
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Bean(name = {"autocompleteKeyRepository", "keyRepository"})
public AutocompleteKeyRepository keyRepository() {
AutocompleteKeyRepository keyRepository = new AutocompleteKeyServiceImpl(stringRedisTemplate);
return keyRepository;
}
@Bean(name = {"autocompleteRepository"})
public AutocompleteRepository autocompleteRepository(AutocompleteKeyRepository autocompleteKeyRepository) {
AutocompleteRepository autocompleteRepository = new AutocompleteServiceImpl(stringRedisTemplate, autocompleteKeyRepository);
return autocompleteRepository;
}
@Autowired
private AutocompleteRepository autocompleteRepository;
@Test
public void autocomplete() throws Exception {
String apple = "apple";
// step1. clear a "apple"
autocompleteRepository.clear(apple);
// step2. Add a "apple"
autocompleteRepository.add(apple);
// step3. Get auto-complete words with prefix "a"
List<AutocompleteData> autocompletes = autocompleteRepository.complete("a");
Assert.assertNotNull(autocompletes);
Assert.assertTrue(autocompletes.size() == 1);
AutocompleteData autocompleteData = autocompletes.get(0);
Assert.assertTrue(autocompleteData.getValue().equals(apple));
Assert.assertTrue(autocompleteData.getScore() == 1);
}
This project depend on spring-boot
and spring-boot-redis
(Prerequisites)
- Java 1.8
- Spring boot 1.2.8+ (spring-boot-starter-redis)
- Redis 2.4+
- There are many places to repair.
- All contributions are welcome.
- Please use the GitHub issue tracker if you have any ideas or bugs to report.