org.apache.solr.search.QueryParsing Java Examples

The following examples show how to use org.apache.solr.search.QueryParsing. 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 shouldAddTermsFromRedisOnLrangeCommandInvalidMinAndMaxFallsBackToDefault()
    throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("lrange");
  when(localParamsMock.get("min")).thenReturn("-foo");
  when(localParamsMock.get("min")).thenReturn("-bar");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.lrange(anyString(), anyLong(), anyLong())).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();
  verify(jedisMock).lrange("simpleKey", 0, -1);
  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 shouldAddTermsFromRedisOnHgetCommand() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("hget");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get("field")).thenReturn("f1");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.hget(anyString(), anyString())).thenReturn("123");
  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();
  verify(jedisMock).hget("simpleKey", "f1");
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(1, 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 shouldAddMultipleTermsFromRedisOnSrandmemberCommandWithExplicitCount() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("srandmember");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get("count")).thenReturn("2");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.srandmember(anyString(), anyInt())).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();
  verify(jedisMock).srandmember("simpleKey", 2);
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #4
Source File: DefaultQuerqyDismaxQParserWithCommonRulesTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
public void testPrefixWithNoCharLeftForWildcard() {
    String q = "p";

    SolrQueryRequest req = req("q", q,
          DisMaxParams.QF, "f1 f2",
          DisMaxParams.MM, "2",
          QueryParsing.OP, "AND",
          "defType", "querqy",
          "debugQuery", "on"
          );
    
    assertQ("Prefix with no char left for wildcard fails",
            req,
            "//result[@name='response' and @numFound='1']"

      );

    

    req.close();
}
 
Example #5
Source File: DefaultQuerqyDismaxQParserWithCommonRulesTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatRuleMatchingIsCaseInsensitive() {
    String q = "T1 T2";

    SolrQueryRequest req = req("q", q,
          DisMaxParams.QF, "f1 f2 f3",
          DisMaxParams.MM, "1",
          QueryParsing.OP, "OR",
          "defType", "querqy",
          "debugQuery", "on"
          );

    assertQ("Rule matching seems to be case sensitive",
          req,
          "//str[@name='parsedquery'][not(contains(.,'t2'))]",
          "//str[@name='parsedquery'][not(contains(.,'T2'))]"
    );

    req.close();
}
 
Example #6
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromRedisOnZrevrangebyscoreCommandWithCustomRange() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("zrevrangebyscore");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get("min")).thenReturn("1");
  when(localParamsMock.get("max")).thenReturn("100");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.zrevrangeByScoreWithScores(anyString(), anyString(), anyString()))
      .thenReturn(new HashSet<>(Arrays.asList(new Tuple("123", (double) 1.0f), new Tuple("321", (double) 1.0f))));
  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();
  verify(jedisMock).zrevrangeByScoreWithScores("simpleKey", "100", "1");
  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 shouldAddTermsFromRedisOnLrangeCommandCustomMax() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("lrange");
  when(localParamsMock.get("max")).thenReturn("1");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.lrange(anyString(), anyLong(), anyLong())).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();
  verify(jedisMock).lrange("simpleKey", 0, 1);
  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 shouldReturnEmptyQueryOnEmptyListOfSinter() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sinter");
  when(localParamsMock.get("key")).thenReturn("key1");
  when(localParamsMock.get("key1")).thenReturn("key2");
  when(localParamsMock.getParameterNamesIterator()).thenReturn(Arrays.asList("command", "key", "key1").iterator());
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.sinter(anyString(), anyString())).thenReturn(new HashSet<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();
  verify(jedisMock).sinter("key1", "key2");
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(0, terms.size());
}
 
Example #9
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnEmptyQueryOnEmptyListOfMget() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("mget");
  when(localParamsMock.get("key")).thenReturn("key1");
  when(localParamsMock.get("key1")).thenReturn("key2");
  when(localParamsMock.getParameterNamesIterator()).thenReturn(Arrays.asList("command", "key", "key1").iterator());
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.mget(anyString(), anyString())).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();
  verify(jedisMock).mget("key1", "key2");
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(0, terms.size());
}
 
Example #10
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromRedisOnSdiffCommand() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sdiff");
  when(localParamsMock.get("key")).thenReturn("key1");
  when(localParamsMock.get("key1")).thenReturn("key2");
  when(localParamsMock.getParameterNamesIterator()).thenReturn(Arrays.asList("command", "key", "key1").iterator());
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.sdiff(anyString(), anyString())).thenReturn(new HashSet<>(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();
  verify(jedisMock).sdiff("key1", "key2");
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #11
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnEmptyQueryOnEmptyListOfSdiff() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sdiff");
  when(localParamsMock.get("key")).thenReturn("key1");
  when(localParamsMock.get("key1")).thenReturn("key2");
  when(localParamsMock.getParameterNamesIterator()).thenReturn(Arrays.asList("command", "key", "key1").iterator());
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.sdiff(anyString(), anyString())).thenReturn(new HashSet<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();
  verify(jedisMock).sdiff("key1", "key2");
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(0, terms.size());
}
 
Example #12
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromRedisOnSunionCommand() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sunion");
  when(localParamsMock.get("key")).thenReturn("key1");
  when(localParamsMock.get("key1")).thenReturn("key2");
  when(localParamsMock.getParameterNamesIterator()).thenReturn(Arrays.asList("command", "key", "key1").iterator());
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.sunion(anyString(), anyString())).thenReturn(new HashSet<>(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();
  verify(jedisMock).sunion("key1", "key2");
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #13
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldDeflateGzipAndParseJsonTermsFromRedisOnGetCommand() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("get");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get("compression")).thenReturn("gzip");
  when(localParamsMock.get("serialization")).thenReturn("json");

  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.get(any(byte[].class))).thenReturn(Compressor.compressGzip("[100,200,300]".getBytes()));
  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();
  verify(jedisMock).get("simpleKey".getBytes());
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(3, terms.size());
}
 
Example #14
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromRedisOnZrevrangeCommandWithDefaultParams() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("zrevrange");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.zrevrangeWithScores(anyString(), anyLong(), anyLong()))
      .thenReturn(new HashSet<>(Arrays.asList(new Tuple("123", (double) 1.0f), new Tuple("321", (double) 1.0f))));
  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();
  verify(jedisMock).zrevrangeWithScores("simpleKey", 0, -1);
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #15
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromRedisOnSinterCommand() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sinter");
  when(localParamsMock.get("key")).thenReturn("key1");
  when(localParamsMock.get("key1")).thenReturn("key2");
  when(localParamsMock.getParameterNamesIterator()).thenReturn(Arrays.asList("command", "key", "key1").iterator());
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.sinter(anyString(), anyString())).thenReturn(new HashSet<>(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();
  verify(jedisMock).sinter("key1", "key2");
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #16
Source File: NeedsScoresTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryDoesNotContainPhraseQueryBoostIfScoresAreNotNeeded() {
    String q = "qup s";

    SolrQueryRequest req = req("q", q,
            DisMaxParams.QF, "f1 f2",
            DisMaxParams.PF, "f1",
            QueryParsing.OP, "OR",
            NEEDS_SCORES, "false",
            "defType", "querqy",
            "debugQuery", "true"
    );

    assertQ("PhraseQuery must not be added",
            req,
            "//result[@name='response'][@numFound='2']",
            "//str[@name='parsedquery'][not(contains(.,'PhraseQuery'))]");
    req.close();
}
 
Example #17
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromRedisOnMgetCommand() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("mget");
  when(localParamsMock.get("key")).thenReturn("key1");
  when(localParamsMock.get("key1")).thenReturn("key2");
  when(localParamsMock.getParameterNamesIterator()).thenReturn(Arrays.asList("command", "key", "key1").iterator());
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.mget(anyString(), anyString())).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();
  verify(jedisMock).mget("key1", "key2");
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #18
Source File: DocumentFrequencyCorrectionTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
public void testDfGetsCorrectedForBoostUp() throws Exception {

   String q = "a c";

   SolrQueryRequest req = req("q", q,
         DisMaxParams.QF, "f1 f2",
         QueryParsing.OP, "OR",
         DisMaxParams.TIE, "0.1",
         "defType", "querqy",
         "debugQuery", "true"
         );
   assertQ("wrong df",
         req,
         "//str[@name='2'][contains(.,'7 = n, number of documents containing term')]",
         "//str[@name='2'][not(contains(.,'1 = n, number of documents containing term'))]",
         "//str[@name='7'][contains(.,'10 = n, number of documents containing term')]",
         "//str[@name='7'][not(contains(.,'4 = n, number of documents containing term'))]");

   req.close();
}
 
Example #19
Source File: SolrTermQueryCacheFieldPreloadTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
public void testSearchingForNonExistentTermThatWasPreloadedForDifferentField() throws Exception {

    String q = "a";
    SolrQueryRequest req = req(
             
             CommonParams.Q, q,
             DisMaxParams.QF, "f1 f3",
             DisMaxParams.MM, "100%",
             QueryParsing.OP, "AND",
             "defType", "querqy",
             "debugQuery", "true"
             );
     

    assertQ("Partial preload went wrong",
             req,
             "//result[@name='response'][@numFound='1']"
            );

    req.close();

}
 
Example #20
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnEmptyQueryOnEmptyListOfHget() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("hget");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get("field")).thenReturn("f1");
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(jedisMock.hget(anyString(), anyString())).thenReturn(null);
  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();
  verify(jedisMock).hget("simpleKey", "f1");
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(0, terms.size());
}
 
Example #21
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 #22
Source File: AbstractFacetTreeBuilder.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@Override
public void initialiseParameters(SolrParams localParams) throws SyntaxError {
	getLogger().trace("Initialising parameters...");
	if (localParams == null) {
		throw new SyntaxError("Missing facet tree parameters");
	}
	
	// Initialise the node field - REQUIRED
	nodeField = localParams.get(FacetTreeParameters.NODE_FIELD_PARAM);
	if (StringUtils.isBlank(nodeField)) {
		// Not specified in localParams - use the key value instead
		nodeField = localParams.get(QueryParsing.V);
		
		// If still blank, we have a problem
		if (StringUtils.isBlank(nodeField)) {
			throw new SyntaxError("No node field defined in " + localParams);
		}
	}

	//  Initialise the optional fields
	labelField = localParams.get(FacetTreeParameters.LABEL_FIELD_PARAM, null);
}
 
Example #23
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 #24
Source File: SolrTermQueryCacheVsDocumentFrequencyCorrectionTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
public void testCacheVsDocumentFrequencyCorrection() {
    // The rules contain an UP rule that never matches. Make
    // sure this doesn't cause an Exception in the DocumentFrequencyCorrection
    String q = "a";

    SolrQueryRequest req = req("q", q,
          DisMaxParams.QF, "f1 f2",
          QueryParsing.OP, "OR",
          DisMaxParams.TIE, "0.1",
          "defType", "querqy",
          "debugQuery", "true"
          );
    assertQ("Two results expected",
            req,
            "//result[@name='response'][@numFound='2']");

    req.close();
}
 
Example #25
Source File: TestRedisQParser.java    From solr-redis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAddTermsFromSortLimitAndOffset() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("sort");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get("offset")).thenReturn("100");
  when(localParamsMock.get("limit")).thenReturn("1000");
  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, 1000)),
      getSortingParamString(argument.getValue()));
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  final Set<Term> terms = extractTerms(searcher, query);
  Assert.assertEquals(2, terms.size());
}
 
Example #26
Source File: MainQueryBoostTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatNegBoostIsGradedIfBoostSimilarityIsOff() {
    String q = "qdown1 qdown2";

    SolrQueryRequest req = req("q", q,
            DisMaxParams.QF, "f1",
            QueryParsing.OP, "OR",
            QBOOST_SIMILARITY_SCORE, SIMILARITY_SCORE_OFF,
            "defType", "querqy",
            "debugQuery", "true"
    );

    assertQ("graded down failed with qboost.similarityScore=off",
            req,
            "//result[@name='response'][@numFound='2']",
            "//doc[1]/str[@name='id'][contains(.,'5')]",
            "//doc[2]/str[@name='id'][contains(.,'4')]",
            "//str[@name='5'][contains(.,'0.2 = AdditiveBoostFunction(-0.2,query(+f1:d2,def=0.0)=0.0)')]",
            "//str[@name='5'][contains(.,'0.05 = AdditiveBoostFunction(-0.1,query(+f1:d1,def=0.0)=1.0)')]",
            "//str[@name='4'][contains(.,'0.1 = AdditiveBoostFunction(-0.2,query(+f1:d2,def=0.0)=1.0)')]",
            "//str[@name='4'][contains(.,'0.1 = AdditiveBoostFunction(-0.1,query(+f1:d1,def=0.0)=0.0)')]"
    );
    req.close();
}
 
Example #27
Source File: MainQueryBoostTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatNegBoostIsGradedIfSimilarityIsDfc() {
    String q = "qdown1 qdown2";

    SolrQueryRequest req = req("q", q,
            DisMaxParams.QF, "f1",
            QueryParsing.OP, "OR",
            USER_QUERY_SIMILARITY_SCORE, SIMILARITY_SCORE_DFC,
            "defType", "querqy",
            "debugQuery", "true"
    );

    assertQ("graded down failed with uq.similarityScore=off",
            req,
            "//result[@name='response'][@numFound='2']",
            "//doc[1]/str[@name='id'][contains(.,'5')]",
            "//doc[2]/str[@name='id'][contains(.,'4')]",
            "//str[@name='5'][contains(.,'0.2 = AdditiveBoostFunction(-0.2,query(+f1:d2,def=0.0)=0.0)')]",
            "//str[@name='5'][contains(.,'AdditiveBoostFunction(-0.1,query(+f1:d1,def=0.0)')]",
            "//str[@name='5'][not(contains(.,'AdditiveBoostFunction(-0.1,query(+f1:d1,def=0.0)=0.0'))]",
            "//str[@name='4'][contains(.,'AdditiveBoostFunction(-0.2,query(+f1:d2,def=0.0)')]",
            "//str[@name='4'][not(contains(.,'AdditiveBoostFunction(-0.2,query(+f1:d2,def=0.0)=0.0'))]",
            "//str[@name='4'][contains(.,'0.1 = AdditiveBoostFunction(-0.1,query(+f1:d1,def=0.0)=0.0)')]"
    );
    req.close();
}
 
Example #28
Source File: MainQueryBoostTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatNegBoostIsGradedIfSimilarityIsOn() {
    String q = "qdown1 qdown2";

    SolrQueryRequest req = req("q", q,
            DisMaxParams.QF, "f1",
            QueryParsing.OP, "OR",
            USER_QUERY_SIMILARITY_SCORE, SIMILARITY_SCORE_ON,
            "defType", "querqy",
            "debugQuery", "true"
    );

    assertQ("graded down failed with uq.similarityScore=off",
            req,
            "//result[@name='response'][@numFound='2']",
            "//doc[1]/str[@name='id'][contains(.,'5')]",
            "//doc[2]/str[@name='id'][contains(.,'4')]",
            "//str[@name='5'][contains(.,'0.2 = AdditiveBoostFunction(-0.2,query(+f1:d2,def=0.0)=0.0)')]",
            "//str[@name='5'][contains(.,'AdditiveBoostFunction(-0.1,query(+f1:d1,def=0.0)')]",
            "//str[@name='5'][not(contains(.,'AdditiveBoostFunction(-0.1,query(+f1:d1,def=0.0)=0.0'))]",
            "//str[@name='4'][contains(.,'AdditiveBoostFunction(-0.2,query(+f1:d2,def=0.0)')]",
            "//str[@name='4'][not(contains(.,'AdditiveBoostFunction(-0.2,query(+f1:d2,def=0.0)=0.0'))]",
            "//str[@name='4'][contains(.,'0.1 = AdditiveBoostFunction(-0.1,query(+f1:d1,def=0.0)=0.0)')]"
    );
    req.close();
}
 
Example #29
Source File: MainQueryBoostTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatNegBoostIsGradedIfSimilarityIsOff() {
    String q = "qdown1 qdown2";

    SolrQueryRequest req = req("q", q,
            DisMaxParams.QF, "f1",
            QueryParsing.OP, "OR",
            USER_QUERY_SIMILARITY_SCORE, SIMILARITY_SCORE_OFF,
            "defType", "querqy",
            "debugQuery", "true"
    );

    assertQ("graded down failed with uq.similarityScore=off",
            req,
            "//result[@name='response'][@numFound='2']",
            "//doc[1]/str[@name='id'][contains(.,'5')]",
            "//doc[2]/str[@name='id'][contains(.,'4')]",
            "//str[@name='5'][contains(.,'0.2 = AdditiveBoostFunction(-0.2,query(+f1:d2,def=0.0)=0.0)')]",
            "//str[@name='5'][contains(.,'AdditiveBoostFunction(-0.1,query(+f1:d1,def=0.0)')]",
            "//str[@name='5'][not(contains(.,'AdditiveBoostFunction(-0.1,query(+f1:d1,def=0.0)=0.0'))]",
            "//str[@name='4'][contains(.,'AdditiveBoostFunction(-0.2,query(+f1:d2,def=0.0)')]",
            "//str[@name='4'][not(contains(.,'AdditiveBoostFunction(-0.2,query(+f1:d2,def=0.0)=0.0'))]",
            "//str[@name='4'][contains(.,'AdditiveBoostFunction(-0.1,query(+f1:d1,def=0.0)=0.0)')]"
    );
    req.close();
}
 
Example #30
Source File: MainQueryBoostTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
    public void testThatNegBoostIsAppliedIfSimilarityIsDFC() {
        String q = "m u100";
//        m =>
//        DOWN(200000): d

        SolrQueryRequest req = req("q", q,
                DisMaxParams.QF, "f1^10 f2^2",
                QueryParsing.OP, "OR",
                USER_QUERY_SIMILARITY_SCORE, SIMILARITY_SCORE_DFC,
                USER_QUERY_BOOST, "80.0",
                QBOOST_NEG_WEIGHT, "3",
                "defType", "querqy",
                "debugQuery", "true"
        );

        assertQ("qboost.negWeight failed with uq.similarityScore=dfc",
                req,
                "//result[@name='response'][@numFound='2']",
                "//str[1][@name='2'][contains(.,'idf')]",
                "//str[1][@name='2'][contains(.,'600000.0 = FunctionQuery')]", // qboost.negWeight=3*DOWN(200000) added

                "//str[2][@name='3'][contains(.,'idf')]",
                "//str[2][@name='3'][not(contains(.,'60000.0 = FunctionQuery'))]");
        req.close();
    }