redis.clients.jedis.SortingParams Java Examples

The following examples show how to use redis.clients.jedis.SortingParams. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromSortOrderDesc() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sort");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get("order")).thenReturn("desc");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
  when(requestMock.getSchema()).thenReturn(schema);
  when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
  redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
  final Query query = redisQParser.parse();
  final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
  verify(jedisMock).sort(eq("simpleKey"), argument.capture());
  Assert.assertEquals(getSortingParamString(new SortingParams().desc()), getSortingParamString(argument.getValue()));
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #2
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromSortOrderAsc() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sort");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get("order")).thenReturn("asc");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
  when(requestMock.getSchema()).thenReturn(schema);
  when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
  redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
  final Query query = redisQParser.parse();
  final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
  verify(jedisMock).sort(eq("simpleKey"), argument.capture());
  Assert.assertEquals(getSortingParamString(new SortingParams().asc()), getSortingParamString(argument.getValue()));
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #3
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromSortAlgorithmAlpha() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sort");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get("algorithm")).thenReturn("alpha");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
  when(requestMock.getSchema()).thenReturn(schema);
  when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
  redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
  final Query query = redisQParser.parse();
  final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
  verify(jedisMock).sort(eq("simpleKey"), argument.capture());
  Assert.assertEquals(getSortingParamString(new SortingParams().alpha()), getSortingParamString(argument.getValue()));
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #4
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromSort() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sort");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
  when(requestMock.getSchema()).thenReturn(schema);
  when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
  redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
  final Query query = redisQParser.parse();
  final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
  verify(jedisMock).sort(eq("simpleKey"), argument.capture());
  Assert.assertEquals(getSortingParamString(new SortingParams()), getSortingParamString(argument.getValue()));
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #5
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnEmptyQueryOnEmptyResultOfSort() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sort");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(new ArrayList<String>());
  when(requestMock.getSchema()).thenReturn(schema);
  when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
  redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
  final Query query = redisQParser.parse();
  final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
  verify(jedisMock).sort(eq("simpleKey"), argument.capture());
  Assert.assertEquals(getSortingParamString(new SortingParams()), getSortingParamString(argument.getValue()));
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(0, terms.size());
}
 
Example #6
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromSortLimit() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sort");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get("limit")).thenReturn("100");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
  when(requestMock.getSchema()).thenReturn(schema);
  when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
  redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
  final Query query = redisQParser.parse();
  final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
  verify(jedisMock).sort(eq("simpleKey"), argument.capture());
  Assert.assertEquals(getSortingParamString(new SortingParams().limit(0, 100)),
      getSortingParamString(argument.getValue()));
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #7
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromSortOffset() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sort");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get("offset")).thenReturn("100");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
  when(requestMock.getSchema()).thenReturn(schema);
  when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
  redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
  final Query query = redisQParser.parse();
  final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
  verify(jedisMock).sort(eq("simpleKey"), argument.capture());
  Assert.assertEquals(getSortingParamString(new SortingParams().limit(100, 0)),
      getSortingParamString(argument.getValue()));
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #8
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromSortWithByClause() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sort");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get("by")).thenReturn("foo_*");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.sort(anyString(), any(SortingParams.class))).thenReturn(Arrays.asList("123", "321"));
  when(requestMock.getSchema()).thenReturn(schema);
  when(schema.getQueryAnalyzer()).thenReturn(new StandardAnalyzer());
  redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
  final Query query = redisQParser.parse();
  final ArgumentCaptor<SortingParams> argument = ArgumentCaptor.forClass(SortingParams.class);
  verify(jedisMock).sort(eq("simpleKey"), argument.capture());
  Assert.assertEquals(getSortingParamString(new SortingParams().by("foo_*")),
      getSortingParamString(argument.getValue()));
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #9
Source File: DefaultRedis.java    From craft-atom with MIT License 5 votes vote down vote up
private List<String> sort_offset_count_alpha_desc(Jedis j, String key, int offset, int count, boolean alpha, boolean desc) {
	SortingParams sp = new SortingParams();
	if (desc) {
		sp.desc();
	}
	if (alpha) { 
		sp.alpha() ;
	}
	sp.limit(offset, count);
	
	return j.sort(key, sp);
}
 
Example #10
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_alpha_desc(String key, boolean alpha, boolean desc) {
	SortingParams sp = new SortingParams();
	if (desc) {
		sp.desc();
	}
	if (alpha) { 
		sp.alpha() ;
	}

	t.sort(key, sp);
}
 
Example #11
Source File: DefaultRedis.java    From craft-atom with MIT License 5 votes vote down vote up
private List<String> sort_by_get(Jedis j, String key, String bypattern, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	
	return j.sort(key, sp);
}
 
Example #12
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_by_offset_count_get(String key, String bypattern, int offset, int count, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	sp.limit(offset, count);
	t.sort(key, sp);
}
 
Example #13
Source File: SortingCommandsTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void sortAlpha() {
  jedis.lpush("foo", "1");
  jedis.lpush("foo", "2");
  jedis.lpush("foo", "10");

  SortingParams sp = new SortingParams();
  sp.alpha();

  List<String> result = jedis.sort("foo", sp);

  List<String> expected = new ArrayList<String>();
  expected.add("1");
  expected.add("10");
  expected.add("2");

  assertEquals(expected, result);

  // Binary
  jedis.lpush(bfoo, b1);
  jedis.lpush(bfoo, b2);
  jedis.lpush(bfoo, b10);

  SortingParams bsp = new SortingParams();
  bsp.alpha();

  List<byte[]> bresult = jedis.sort(bfoo, bsp);

  List<byte[]> bexpected = new ArrayList<byte[]>();
  bexpected.add(b1);
  bexpected.add(b10);
  bexpected.add(b2);

  assertEquals(bexpected, bresult);
}
 
Example #14
Source File: DefaultRedis.java    From craft-atom with MIT License 5 votes vote down vote up
private List<String> sort_by_desc_get(Jedis j, String key, String bypattern, boolean desc, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	if (desc) {
		sp.desc();
	}
	
	return j.sort(key, sp);
}
 
Example #15
Source File: SortingCommandsTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void sortDesc() {
  jedis.lpush("foo", "3");
  jedis.lpush("foo", "2");
  jedis.lpush("foo", "1");

  SortingParams sp = new SortingParams();
  sp.desc();

  List<String> result = jedis.sort("foo", sp);

  List<String> expected = new ArrayList<String>();
  expected.add("3");
  expected.add("2");
  expected.add("1");

  assertEquals(expected, result);

  // Binary
  jedis.lpush(bfoo, b3);
  jedis.lpush(bfoo, b2);
  jedis.lpush(bfoo, b1);

  SortingParams bsp = new SortingParams();
  bsp.desc();

  List<byte[]> bresult = jedis.sort(bfoo, bsp);

  List<byte[]> bexpected = new ArrayList<byte[]>();
  bexpected.add(b3);
  bexpected.add(b2);
  bexpected.add(b1);

  assertEquals(bexpected, bresult);
}
 
Example #16
Source File: DefaultRedis.java    From craft-atom with MIT License 5 votes vote down vote up
private List<String> sort_by_alpha_desc_get(Jedis j, String key, String bypattern, boolean alpha, boolean desc, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	if (alpha) {
		sp.alpha();
	}
	if (desc) {
		sp.desc();
	}
	
	return j.sort(key, sp);
}
 
Example #17
Source File: JedisOperator.java    From smart-cache with Apache License 2.0 5 votes vote down vote up
public List<String> sort(final String key, final SortingParams sortingParameters) {
    return execute(new JedisExecutor<List<String>>() {
        @Override
        List<String> doInJedis(Jedis jedis) {
            return jedis.sort(key, sortingParameters);
        }
    });
}
 
Example #18
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_alpha_desc_destination(String key, boolean alpha, boolean desc, String destination) {
	SortingParams sp = new SortingParams();
	if (desc) {
		sp.desc();
	}
	if (alpha) {
		sp.alpha();
	}
	
	t.sort(key, sp, destination);
}
 
Example #19
Source File: DefaultRedis.java    From craft-atom with MIT License 5 votes vote down vote up
private List<String> sort_by_offset_count_get(Jedis j, String key, String bypattern, int offset, int count, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	sp.limit(offset, count);
	return j.sort(key, sp);
}
 
Example #20
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_offset_count_alpha_desc(String key, int offset, int count, boolean alpha, boolean desc) {
	SortingParams sp = new SortingParams();
	if (desc) {
		sp.desc();
	}
	if (alpha) { 
		sp.alpha() ;
	}
	sp.limit(offset, count);
	
	t.sort(key, sp);
}
 
Example #21
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_by_get(String key, String bypattern, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	
	t.sort(key, sp);
}
 
Example #22
Source File: DefaultRedis.java    From craft-atom with MIT License 5 votes vote down vote up
private List<String> sort_alpha_desc(Jedis j, String key, boolean alpha, boolean desc) {
	SortingParams sp = new SortingParams();
	if (desc) {
		sp.desc();
	}
	if (alpha) { 
		sp.alpha() ;
	}

	return j.sort(key, sp);
}
 
Example #23
Source File: DefaultRedis.java    From craft-atom with MIT License 5 votes vote down vote up
private List<String> sort_desc(Jedis j, String key, boolean desc) {
	SortingParams sp = new SortingParams();
	if (desc) {
		sp.desc();
	}
	
	return j.sort(key, sp);
}
 
Example #24
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_by_alpha_desc_destination_get(String key, String bypattern, boolean alpha, boolean desc, String destination, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	if (alpha) {
		sp.alpha();
	}
	if (desc) {
		sp.desc();
	}
	
	t.sort(key, sp, destination);
}
 
Example #25
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_desc(String key, boolean desc) {
	SortingParams sp = new SortingParams();
	if (desc) {
		sp.desc();
	}
	
	t.sort(key, sp);
}
 
Example #26
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_offset_count_alpha_desc_destination(String key, int offset, int count, boolean alpha, boolean desc, String destination) {
	SortingParams sp = new SortingParams();
	sp.limit(offset, count);
	if (desc) {
		sp.desc();
	}
	if (alpha) {
		sp.alpha();
	}
	t.sort(key, sp, destination);
}
 
Example #27
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_by_desc_get(String key, String bypattern, boolean desc, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	if (desc) {
		sp.desc();
	}
	
	t.sort(key, sp);
}
 
Example #28
Source File: JedisAdapter.java    From gameserver with Apache License 2.0 5 votes vote down vote up
@Override
public List<byte[]> sort(byte[] key, SortingParams sortingParameters) {
	redis.clients.jedis.Jedis delegate = pool.getResource();
	try {
		return delegate.sort(key, sortingParameters);
	} finally {
		pool.returnResource(delegate);
	}
}
 
Example #29
Source File: JedisAdapter.java    From gameserver with Apache License 2.0 5 votes vote down vote up
@Override
public Long sort(String key, SortingParams sortingParameters, String dstkey) {
	redis.clients.jedis.Jedis delegate = pool.getResource();
	try {
		return delegate.sort(key, sortingParameters, dstkey);
	} finally {
		pool.returnResource(delegate);
	}
}
 
Example #30
Source File: JedisAdapter.java    From gameserver with Apache License 2.0 5 votes vote down vote up
@Override
public Long sort(byte[] key, SortingParams sortingParameters, byte[] dstkey) {
	redis.clients.jedis.Jedis delegate = pool.getResource();
	try {
		return delegate.sort(key, sortingParameters, dstkey);
	} finally {
		pool.returnResource(delegate);
	}
}