Package org.springframework.data.solr.core.query

Examples of org.springframework.data.solr.core.query.HighlightOptions$HighlightParameter


    options.setFacetPrefix(replacePlaceholders(queryMethod.getFacetPrefix(), parameterAccessor));
    return options;
  }

  private HighlightOptions extractHighlightOptions(SolrQueryMethod queryMethod, SolrParameterAccessor accessor) {
    HighlightOptions options = new HighlightOptions();
    if (queryMethod.hasHighlightFields()) {
      options.addFields(queryMethod.getHighlightFieldNames());
    }
    Integer fragsize = queryMethod.getHighlightFragsize();
    if (fragsize != null) {
      options.setFragsize(fragsize);
    }
    Integer snipplets = queryMethod.getHighlighSnipplets();
    if (snipplets != null) {
      options.setNrSnipplets(snipplets);
    }
    String queryString = queryMethod.getHighlightQuery();
    if (queryString != null) {
      options.setQuery(createQueryFromString(queryString, accessor));
    }
    appendHighlightFormatOptions(options, solrQueryMethod);
    return options;
  }
View Full Code Here


   * @param solrQuery
   * @param query
   */
  protected void processHighlightOptions(SolrQuery solrQuery, HighlightQuery query) {
    if (query.hasHighlightOptions()) {
      HighlightOptions highlightOptions = query.getHighlightOptions();
      solrQuery.setHighlight(true);
      if (!highlightOptions.hasFields()) {
        solrQuery.addHighlightField(HighlightOptions.ALL_FIELDS.getName());
      } else {
        for (Field field : highlightOptions.getFields()) {
          solrQuery.addHighlightField(field.getName());
        }
        for (FieldWithHighlightParameters fieldWithHighlightParameters : highlightOptions
            .getFieldsWithHighlightParameters()) {
          addPerFieldHighlightParameters(solrQuery, fieldWithHighlightParameters);
        }
      }
      for (HighlightParameter option : highlightOptions.getHighlightParameters()) {
        addOptionToSolrQuery(solrQuery, option);
      }
      if (highlightOptions.hasQuery()) {
        solrQuery.add(HighlightParams.Q, getQueryString(highlightOptions.getQuery()));
      }
    }
  }
View Full Code Here

        new Object[] { new PageRequest(0, 10) });

    Mockito.verify(solrOperationsMock, Mockito.times(1)).queryForHighlightPage(captor.capture(),
        (Class<ProductBean>) Matchers.any());

    HighlightOptions capturedOptions = captor.getValue().getHighlightOptions();
    Assert.assertNotNull(capturedOptions);
    Assert.assertEquals("<b>", capturedOptions.getSimplePrefix());
    Assert.assertEquals("</b>", capturedOptions.getSimplePostfix());
    Assert.assertEquals("name", capturedOptions.getFields().get(0).getName());
    Assert.assertEquals("description", capturedOptions.getFields().get(1).getName());
    Assert.assertEquals("simple", capturedOptions.getFormatter());
    Assert.assertEquals(Integer.valueOf(10), capturedOptions.getFragsize());
    Assert.assertEquals(Integer.valueOf(20), capturedOptions.getNrSnipplets());
    Assert
        .assertEquals("name:with", ((SimpleStringCriteria) capturedOptions.getQuery().getCriteria()).getQueryString());
  }
View Full Code Here

        .execute(new Object[] { "spring", new PageRequest(0, 10) });

    Mockito.verify(solrOperationsMock, Mockito.times(1)).queryForHighlightPage(captor.capture(),
        (Class<ProductBean>) Matchers.any());

    HighlightOptions capturedOptions = captor.getValue().getHighlightOptions();
    Assert.assertEquals("name:*spring*",
        ((SimpleStringCriteria) capturedOptions.getQuery().getCriteria()).getQueryString());
  }
View Full Code Here

        new Object[] { new PageRequest(0, 10) });

    Mockito.verify(solrOperationsMock, Mockito.times(1)).queryForHighlightPage(captor.capture(),
        (Class<ProductBean>) Matchers.any());

    HighlightOptions capturedOptions = captor.getValue().getHighlightOptions();
    Assert.assertNotNull(capturedOptions);
    Assert.assertNull(capturedOptions.getSimplePrefix());
    Assert.assertNull(capturedOptions.getSimplePrefix());
    Assert.assertNull(capturedOptions.getSimplePostfix());
    Assert.assertEquals("postingshighlighter", capturedOptions.getFormatter());
    Assert.assertEquals("{pre}", capturedOptions.getHighlightParameterValue(HighlightParams.TAG_PRE));
    Assert.assertEquals("{post}", capturedOptions.getHighlightParameterValue(HighlightParams.TAG_POST));
  }
View Full Code Here

    createQueryForMethod("findAndApplyHighlighting", Pageable.class).execute(new Object[] { new PageRequest(0, 10) });

    Mockito.verify(solrOperationsMock, Mockito.times(1)).queryForHighlightPage(captor.capture(),
        (Class<ProductBean>) Matchers.any());

    HighlightOptions capturedOptions = captor.getValue().getHighlightOptions();
    Assert.assertNotNull(capturedOptions);
  }
View Full Code Here

    solrTemplate.saveBeans(Arrays.asList(belkin, apple));
    solrTemplate.commit();

    SimpleHighlightQuery query = new SimpleHighlightQuery(new SimpleStringCriteria("name:with"));
    query.setHighlightOptions(new HighlightOptions());

    HighlightPage<ExampleSolrBean> page = solrTemplate.queryForHighlightPage(query, ExampleSolrBean.class);
    Assert.assertEquals(2, page.getHighlighted().size());

    Assert.assertEquals("name", page.getHighlighted().get(0).getHighlights().get(0).getField().getName());
View Full Code Here

  }

  @Test
  public void testConstructSolrQueryWithEmptyHighlightOption() {
    SimpleHighlightQuery query = new SimpleHighlightQuery(new SimpleStringCriteria("field_1:value_1"));
    query.setHighlightOptions(new HighlightOptions());

    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertTrue(solrQuery.getHighlight());
    Assert.assertArrayEquals(new String[] { Criteria.WILDCARD }, solrQuery.getHighlightFields());
  }
View Full Code Here

  }

  @Test
  public void testConstructSolrQueryWithHighlightOptionHavingFields() {
    SimpleHighlightQuery query = new SimpleHighlightQuery(new SimpleStringCriteria("field_1:value_1"));
    HighlightOptions options = new HighlightOptions();
    options.addField("field_2", "field_3");
    query.setHighlightOptions(options);

    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertArrayEquals(new String[] { "field_2", "field_3" }, solrQuery.getHighlightFields());
  }
View Full Code Here

  }

  @Test
  public void testConstructSorlQueryWithHighlightOptionFragsize() {
    SimpleHighlightQuery query = new SimpleHighlightQuery(new SimpleStringCriteria("field_1:value_1"));
    HighlightOptions options = new HighlightOptions();
    options.setFragsize(10);
    query.setHighlightOptions(options);

    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
    Assert.assertEquals(options.getFragsize().intValue(), solrQuery.getHighlightFragsize());
  }
View Full Code Here

TOP

Related Classes of org.springframework.data.solr.core.query.HighlightOptions$HighlightParameter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.