/** * Highlights the given field or all fields if null. */ @Override public void highlight(IRI property) { query.setHighlight(true); String field = (property != null) ? SearchFields.getPropertyField(property) : "*"; query.addHighlightField(field); query.setHighlightSimplePre(SearchFields.HIGHLIGHTER_PRE_TAG); query.setHighlightSimplePost(SearchFields.HIGHLIGHTER_POST_TAG); query.setHighlightSnippets(2); }
/** remove a field for highlighting * * @param f field name to not highlight * @return <i>true</i>, if removed, <br> <i>false</i>, otherwise */ public boolean removeHighlightField(String f) { boolean b = this.remove(HighlightParams.FIELDS, f); if (this.get(HighlightParams.FIELDS) == null) { this.setHighlight(false); } return b; }
HttpSolrServer server= new HttpSolrServer("http://localhost:8983/solr"); server.setParser(new XMLResponseParser()); Gson gson= new Gson(); SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery("*:*"); solrQuery.setHighlight(true); solrQuery.setHighlightRequireFieldMatch(true); QueryResponse response= server.query(solrQuery); SolrDocumentList docs = response.getResults(); String res= gson.toJson(docs); System.out.println(res);
public List<Question> searchQuestion(String keyword, int offset, int count, String hlPre, String hlPos) throws IOException, SolrServerException { List<Question> questionList = new ArrayList<>(); SolrQuery query = new SolrQuery(keyword); query.setRows(count); query.setStart(offset); query.setHighlight(true); query.setHighlightSimplePre(hlPre); query.setHighlightSimplePost(hlPos); query.set("hl.fl", QUESTION_TITLE_FIELD + "," + QUESTION_CONTENT_FIELD); QueryResponse response = client.query(query); for (Map.Entry<String, Map<String, List<String>>> entry : response.getHighlighting().entrySet()) { Question q = new Question(); q.setId(Integer.parseInt(entry.getKey())); if (entry.getValue().containsKey(QUESTION_CONTENT_FIELD)) { List<String> contentList = entry.getValue().get(QUESTION_CONTENT_FIELD); if (contentList.size() > 0) { q.setContent(contentList.get(0)); } } if (entry.getValue().containsKey(QUESTION_TITLE_FIELD)) { List<String> titleList = entry.getValue().get(QUESTION_TITLE_FIELD); if (titleList.size() > 0) { q.setTitle(titleList.get(0)); } } questionList.add(q); } return questionList; }
query.setHighlight(true); query.setHighlightSnippets(highlights.snippet); query.setHighlightFragsize(highlights.fragsize);
/** * Highlights the given field or all fields if null. */ @Override public void highlight(URI property) { query.setHighlight(true); String field = (property != null) ? SearchFields.getPropertyField(property) : "*"; query.addHighlightField(field); query.setHighlightSimplePre(SearchFields.HIGHLIGHTER_PRE_TAG); query.setHighlightSimplePost(SearchFields.HIGHLIGHTER_POST_TAG); query.setHighlightSnippets(2); }
if (!solrQuery.getHighlight()) { solrQuery.setHighlight(true);
/** remove a field for highlighting * * @param f field name to not highlight * @return <i>true</i>, if removed, <br> <i>false</i>, otherwise */ public boolean removeHighlightField(String f) { boolean b = this.remove(HighlightParams.FIELDS, f); if (this.get(HighlightParams.FIELDS) == null) { this.setHighlight(false); } return b; }
query.setHighlight(true); query.addHighlightField(highlights._field); query.setHighlightRequireFieldMatch(highlights.fieldMustMatch);
if (!solrQuery.getHighlight()) { solrQuery.setHighlight(true);
/** remove a field for highlighting * * @param f field name to not highlight * @return <i>true</i>, if removed, <br /> <i>false</i>, otherwise */ public boolean removeHighlightField(String f) { boolean b = this.remove(HighlightParams.FIELDS, f); if (this.get(HighlightParams.FIELDS) == null) { this.setHighlight(false); } return b; }
query.setHighlight(true); query.addHighlightField(this.content); query.setHighlightFragsize(100);
/** * Append highlighting parameters to {@link SolrQuery} * * @param solrQuery the target {@link SolrQuery} * @param query the source query. * @param domainType used for mapping fields to properties. Can be {@literal null}. */ protected void processHighlightOptions(SolrQuery solrQuery, HighlightQuery query, @Nullable Class<?> domainType) { 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(getMappedFieldName(field, domainType)); } for (FieldWithHighlightParameters fieldWithHighlightParameters : highlightOptions .getFieldsWithHighlightParameters()) { addPerFieldHighlightParameters(solrQuery, fieldWithHighlightParameters, domainType); } } for (HighlightParameter option : highlightOptions.getHighlightParameters()) { addOptionToSolrQuery(solrQuery, option); } if (highlightOptions.hasQuery()) { solrQuery.add(HighlightParams.Q, getQueryString(highlightOptions.getQuery(), domainType)); } } }
query.setHighlight(true); query.addHighlightField(this.content); query.setHighlightFragsize(18);
solrQuery.setHighlight(true); solrQuery.add(HighlightParams.USE_PHRASE_HIGHLIGHTER, Boolean.TRUE.toString()); for (DiscoverHitHighlightingField highlightingField : discoveryQuery.getHitHighlightingFields()) {
q.setHighlight(true); String field = (propertyURI != null) ? SearchFields.getPropertyField(propertyURI) : "*"; q.addHighlightField(field);
query.setQueryType(qt); query.setHighlight(highlight); if(facetFields == null || "".equals(facetFields)) { query.setFacet(false);
q.setHighlight(true); String field = (propertyURI != null) ? SearchFields.getPropertyField(propertyURI) : "*"; q.addHighlightField(field);
query.setHighlight(true);
solrQuery.setHighlight(true).setHighlightSnippets(1); Integer fragSize = systemConfig.getSearchHighlightFragmentSize(); if (fragSize != null) {