List of usage examples for org.apache.solr.common.params HighlightParams HIGHLIGHT
String HIGHLIGHT
To view the source code for org.apache.solr.common.params HighlightParams HIGHLIGHT.
Click Source Link
From source file:com.tsgrp.solr.handler.NYPhilSearchHandler.java
License:Mozilla Public License
/** * @see org.apache.solr.handler.component.SearchHandler#handleRequestBody(org.apache.solr.request.SolrQueryRequest, * org.apache.solr.request.SolrQueryResponse) *//*from w w w . j a va2 s .c o m*/ @Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception, ParseException, InstantiationException, IllegalAccessException { SolrParams requestParams = req.getParams(); NamedList<Object> params = requestParams.toNamedList(); //for now lets echo the handler and all the params for debugging purposes //params.add( CommonParams.HEADER_ECHO_HANDLER, Boolean.TRUE ); //params.add( CommonParams.HEADER_ECHO_PARAMS, CommonParams.EchoParamStyle.ALL ); String rows = (String) params.get(CommonParams.ROWS); if (rows == null || rows.trim().length() < 1) { //setup items per page, default to 10 items params.add(CommonParams.ROWS, 10); rows = "10"; } //enable faceting and only return facets with at least 1 item params.add(FacetParams.FACET, Boolean.TRUE); params.add(FacetParams.FACET_MINCOUNT, 1); //defult ordering to index order (alphabetical) params.add(FacetParams.FACET_SORT, FacetParams.FACET_SORT_INDEX); //only return a maximum of 10 facet values params.add(FacetParams.FACET_LIMIT, 10); //always add facets unless they are explicitly not requested String addFacets = (String) params.get(PARAM_GENERATE_FACETS); boolean generateFacets = (addFacets == null) ? true : addFacets.equalsIgnoreCase("true"); //enable highlighting params.add(HighlightParams.HIGHLIGHT, Boolean.TRUE); //remove the query if provided, always want to use our translated query String originalQuery = (String) params.remove(CommonParams.Q); if (logger.isDebugEnabled()) { logger.debug("Original query: " + originalQuery); } //setup sorting params String sortColumn = (String) params.get(PARAM_SORT_COLUMN); String sortOrder = (String) params.get(PARAM_SORT_ORDER); if (sortColumn != null && sortOrder != null) { params.add(CommonParams.SORT, sortColumn + " " + sortOrder); } //get date fields String sDateFrom = (String) params.get(PARAM_DATE_FROM); String sDateTo = (String) params.get(PARAM_DATE_TO); Date dateFrom = null; Date dateTo = null; if (sDateFrom != null && sDateTo != null) { dateFrom = DATE_FORMAT_PARAM.parse(sDateFrom); dateTo = DATE_FORMAT_PARAM.parse(sDateTo); } String keywords = (String) params.get(PARAM_KEYWORDS); if (keywords == null || keywords.trim().length() < 1) { //query everything since nothing was provided keywords = "*"; } //always use the extended dismax parser params.add("defType", ExtendedDismaxQParserPlugin.NAME); //the keywords sent in are the query since we're in DISMAX mode params.add(CommonParams.Q, keywords); String pageIndex = (String) params.get(PARAM_PAGE_INDEX); String resultsPerPage = (String) params.get(PARAM_RESULTS_PER_PAGE); if (resultsPerPage == null || resultsPerPage.trim().length() < 0) { resultsPerPage = "10"; } if (pageIndex == null || pageIndex.trim().length() < 1) { pageIndex = "1"; } //figure out the skip count, use the (pageIndex - 1) * resultsPerPage //ie pageIndex = 3, 10 results per page, we'll set start to (3-1)*10 = 20 int start = (Integer.parseInt(pageIndex) - 1) * Integer.parseInt(resultsPerPage); params.add(CommonParams.START, start); String doctype = (String) params.get(PARAM_DOCTYPE); if (doctype == null || doctype.trim().length() < 1) { doctype = ""; } String facetQuery = (String) params.get(PARAM_FACET_QUERY); if (facetQuery != null && facetQuery.trim().length() > 0) { //facetQuery is pre formatted and correct, just add it as a filter query params.add(CommonParams.FQ, facetQuery); } String suggestedQuery = (String) params.get(PARAM_SUGGESTED_QUERY); if (suggestedQuery != null && suggestedQuery.trim().length() > 0) { //suggestedQuery is pre formatted and correct, just add it as a filter query params.add(CommonParams.FQ, suggestedQuery); } //base fields params.add(DisMaxParams.QF, "nyp:DocumentType"); params.add(DisMaxParams.QF, "nyp:Notes"); //program fields params.add(DisMaxParams.QF, "npp:ProgramID"); params.add(DisMaxParams.QF, "npp:Season"); params.add(DisMaxParams.QF, "npp:OrchestraCode"); params.add(DisMaxParams.QF, "npp:OrchestraName"); params.add(DisMaxParams.QF, "npp:LocationName"); params.add(DisMaxParams.QF, "npp:VenueName"); params.add(DisMaxParams.QF, "npp:EventTypeName"); params.add(DisMaxParams.QF, "npp:SubEventName"); params.add(DisMaxParams.QF, "npp:ConductorName"); params.add(DisMaxParams.QF, "npp:SoloistsNames"); params.add(DisMaxParams.QF, "npp:SoloistsInstrumentName"); params.add(DisMaxParams.QF, "npp:WorksComposerNames"); params.add(DisMaxParams.QF, "npp:WorksTitle"); params.add(DisMaxParams.QF, "npp:WorksShortTitle"); params.add(DisMaxParams.QF, "npp:WorksConductorNames"); //printedMusic fields params.add(DisMaxParams.QF, "npm:LibraryID"); params.add(DisMaxParams.QF, "npm:ShortTitle"); params.add(DisMaxParams.QF, "npm:ComposerName"); params.add(DisMaxParams.QF, "npm:PublisherName"); params.add(DisMaxParams.QF, "npm:ComposerNameTitle"); params.add(DisMaxParams.QF, "npm:ScoreMarkingArtist"); params.add(DisMaxParams.QF, "npm:ScoreEditionTypeDesc"); params.add(DisMaxParams.QF, "npm:ScoreNotes"); //part fields params.add(DisMaxParams.QF, "npm:PartTypeDesc"); params.add(DisMaxParams.QF, "npm:PartMarkingArtist"); params.add(DisMaxParams.QF, "npm:UsedByArtistName"); //businessRecord fields params.add(DisMaxParams.QF, "npb:BoxNumber"); params.add(DisMaxParams.QF, "npb:RecordGroup"); params.add(DisMaxParams.QF, "npb:Series"); params.add(DisMaxParams.QF, "npb:SubSeries"); params.add(DisMaxParams.QF, "npb:Folder"); params.add(DisMaxParams.QF, "npb:Names"); params.add(DisMaxParams.QF, "npb:Subject"); params.add(DisMaxParams.QF, "npb:Abstract"); //visual fields params.add(DisMaxParams.QF, "npv:ID"); params.add(DisMaxParams.QF, "npv:BoxNumber"); params.add(DisMaxParams.QF, "npv:PhilharmonicSource"); params.add(DisMaxParams.QF, "npv:OutsideSource"); params.add(DisMaxParams.QF, "npv:Photographer"); params.add(DisMaxParams.QF, "npv:CopyrightHolder"); params.add(DisMaxParams.QF, "npv:PlaceOfImage"); params.add(DisMaxParams.QF, "npv:PersonalNames"); params.add(DisMaxParams.QF, "npv:CorporateNames"); params.add(DisMaxParams.QF, "npv:Event"); params.add(DisMaxParams.QF, "npv:ImageType"); params.add(DisMaxParams.QF, "npv:LocationName"); params.add(DisMaxParams.QF, "npv:VenueName"); //audio fields params.add(DisMaxParams.QF, "npa:ProgramID"); params.add(DisMaxParams.QF, "npa:Location"); params.add(DisMaxParams.QF, "npa:EventTypeName"); params.add(DisMaxParams.QF, "npa:ConductorName"); params.add(DisMaxParams.QF, "npa:SoloistsAndInstruments"); params.add(DisMaxParams.QF, "npa:ComposerWork"); params.add(DisMaxParams.QF, "npa:OrchestraName"); params.add(DisMaxParams.QF, "npa:IntermissionFeature"); params.add(DisMaxParams.QF, "npa:LocationName"); params.add(DisMaxParams.QF, "npa:VenueName"); params.add(DisMaxParams.QF, "npa:SubEventName"); params.add(DisMaxParams.QF, "npa:URLLocation"); params.add(DisMaxParams.QF, "npa:IntermissionGuests"); params.add(DisMaxParams.QF, "npa:Announcer"); //video fields params.add(DisMaxParams.QF, "npx:ProgramID"); params.add(DisMaxParams.QF, "npx:Location"); params.add(DisMaxParams.QF, "npx:EventTypeName"); params.add(DisMaxParams.QF, "npx:ConductorName"); params.add(DisMaxParams.QF, "npx:SoloistsAndInstruments"); params.add(DisMaxParams.QF, "npx:ComposerNameWork"); params.add(DisMaxParams.QF, "npx:OrchestraName"); params.add(DisMaxParams.QF, "npx:IntermissionFeature"); params.add(DisMaxParams.QF, "npx:LocationName"); params.add(DisMaxParams.QF, "npx:VenueName"); params.add(DisMaxParams.QF, "npx:SubEventName"); params.add(DisMaxParams.QF, "npx:IntermissionGuests"); params.add(DisMaxParams.QF, "npx:Announcer"); params.add(DisMaxParams.QF, "npt:tagged"); //add in all the restrictions that can be applied to a document type count in the same filter query //this includes all DATE range queries //if a date query does not exist, the TYPE is queried so all results are shown //restriction is applied to business records so only the web publishable items are shown StringBuffer filterTypesCountsQuery = new StringBuffer(); if (dateFrom != null && dateTo != null) { //program date query filterTypesCountsQuery.append("(npp\\:Date:[" + solrField.toExternal(dateFrom) + " TO " + solrField.toExternal(dateTo) + "])"); //printedMusic (scores) and parts have no date range, so just or in the type so those results come back filterTypesCountsQuery.append(" OR (nyp\\:DocumentType:Printed Music)"); filterTypesCountsQuery.append(" OR (nyp\\:DocumentType:Part)"); //business record range AND web publishable restriction filterTypesCountsQuery .append(" OR (nyp\\:WebPublishable:true AND ((npb\\:DateFrom:[" + solrField.toExternal(dateFrom) + " TO *] AND npb\\:DateTo:[* TO " + solrField.toExternal(dateTo) + "])"); filterTypesCountsQuery.append(" OR (npb\\:DateFrom:[* TO " + solrField.toExternal(dateFrom) + "] AND npb\\:DateTo:[* TO " + solrField.toExternal(dateTo) + "] AND npb\\:DateTo:[" + solrField.toExternal(dateFrom) + " TO *])"); filterTypesCountsQuery.append(" OR (npb\\:DateFrom:[" + solrField.toExternal(dateFrom) + " TO *] AND npb\\:DateTo:[" + solrField.toExternal(dateTo) + " TO *] AND npb\\:DateFrom:[* TO " + solrField.toExternal(dateFrom) + "])))"); //visual filterTypesCountsQuery.append(" OR ((npv\\:DateFrom:[" + solrField.toExternal(dateFrom) + " TO *] AND npv\\:DateTo:[* TO " + solrField.toExternal(dateTo) + "])"); filterTypesCountsQuery.append(" OR (npv\\:DateFrom:[* TO " + solrField.toExternal(dateFrom) + "] AND npv\\:DateTo:[* TO " + solrField.toExternal(dateTo) + "] AND npv\\:DateTo:[" + solrField.toExternal(dateFrom) + " TO *])"); filterTypesCountsQuery.append(" OR (npv\\:DateFrom:[" + solrField.toExternal(dateFrom) + " TO *] AND npv\\:DateTo:[" + solrField.toExternal(dateTo) + " TO *] AND npv\\:DateFrom:[* TO " + solrField.toExternal(dateFrom) + "]))"); //audio filterTypesCountsQuery.append(" OR (npa\\:Date:[" + solrField.toExternal(dateFrom) + " TO " + solrField.toExternal(dateTo) + "])"); //video filterTypesCountsQuery.append(" OR (npx\\:Date:[" + solrField.toExternal(dateFrom) + " TO " + solrField.toExternal(dateTo) + "])"); } else { //no date queries, just perform query based on type restrictions filterTypesCountsQuery.append( "(nyp\\:DocumentType:Program) OR (nyp\\:DocumentType:Printed Music) OR (nyp\\:DocumentType:Part) OR (nyp\\:DocumentType:Business Record AND nyp\\:WebPublishable:true)"); filterTypesCountsQuery.append( " OR (nyp\\:DocumentType:Visual) OR (nyp\\:DocumentType:Audio) OR (nyp\\:DocumentType:Video)"); } params.add(CommonParams.FQ, filterTypesCountsQuery); //default facet for document type that will always return the counts regardless of filter queries applied params.add(FacetParams.FACET_FIELD, "{!ex=test}nyp:DocumentType_facet"); //allow this facet to always display all values, even when there are 0 results for the type params.add("f.nyp:DocumentType_facet.facet.mincount", 0); if (doctype.equalsIgnoreCase("program")) { //set the document type restriction params.add(CommonParams.FQ, "{!tag=test}nyp\\:DocumentType:Program"); if (generateFacets) { params.add(FacetParams.FACET_FIELD, "npp:ConductorName_facet"); params.add(FacetParams.FACET_FIELD, "npp:SoloistsNames_facet"); params.add(FacetParams.FACET_FIELD, "npp:WorksComposerNames_facet"); params.add(FacetParams.FACET_FIELD, "npp:LocationName_facet"); params.add(FacetParams.FACET_FIELD, "npp:VenueName_facet"); params.add(FacetParams.FACET_FIELD, "npp:EventTypeName_facet"); params.add(FacetParams.FACET_FIELD, "npp:Season_facet"); } } else if (doctype.equalsIgnoreCase("printedMusic")) { //set the document type restriction params.add(CommonParams.FQ, "{!tag=test}nyp\\:DocumentType:Printed Music"); if (generateFacets) { params.add(FacetParams.FACET_FIELD, "npm:ScoreMarkingArtist_facet"); params.add(FacetParams.FACET_FIELD, "npm:ComposerName_facet"); } } else if (doctype.equalsIgnoreCase("part")) { //set the document type restriction params.add(CommonParams.FQ, "{!tag=test}nyp\\:DocumentType:Part"); if (generateFacets) { params.add(FacetParams.FACET_FIELD, "npm:ComposerName_facet"); params.add(FacetParams.FACET_FIELD, "npm:UsedByArtistName_facet"); params.add(FacetParams.FACET_FIELD, "npm:PartMarkingArtist_facet"); params.add(FacetParams.FACET_FIELD, "npm:PartTypeDesc_facet"); } // if sort parameter has been supplied (e.g. non-facet search) - apply additional part sorting if (sortColumn != null && sortOrder != null) { logger.debug("Addition additional sort parameter for PART type..."); String prevParams = (String) params.get(CommonParams.SORT); String newParams = prevParams + ", npm:PartID ASC"; params.add(CommonParams.SORT, newParams); } } else if (doctype.equalsIgnoreCase("businessRecord")) { //set the document type restriction params.add(CommonParams.FQ, "{!tag=test}nyp\\:DocumentType:Business Record"); if (generateFacets) { params.add(FacetParams.FACET_FIELD, "npb:Names_facet"); params.add(FacetParams.FACET_FIELD, "npb:Subject_facet"); params.add(FacetParams.FACET_FIELD, "npb:RecordGroup_facet"); params.add(FacetParams.FACET_FIELD, "npb:Series_facet"); params.add(FacetParams.FACET_FIELD, "npb:SubSeries_facet"); } } else if (doctype.equalsIgnoreCase("visual")) { //set the document type restriction params.add(CommonParams.FQ, "{!tag=test}nyp\\:DocumentType:Visual"); if (generateFacets) { params.add(FacetParams.FACET_FIELD, "npv:Photographer_facet"); params.add(FacetParams.FACET_FIELD, "npv:CopyrightHolder_facet"); params.add(FacetParams.FACET_FIELD, "npv:ImageType_facet"); params.add(FacetParams.FACET_FIELD, "npv:PlaceOfImage_facet"); params.add(FacetParams.FACET_FIELD, "npv:Event_facet"); params.add(FacetParams.FACET_FIELD, "npv:PersonalNames_facet"); params.add(FacetParams.FACET_FIELD, "npv:LocationName_facet"); params.add(FacetParams.FACET_FIELD, "npv:VenueName_facet"); } } else if (doctype.equalsIgnoreCase("audio")) { //set the document type restriction params.add(CommonParams.FQ, "{!tag=test}nyp\\:DocumentType:Audio"); //no facets being generated } else if (doctype.equalsIgnoreCase("video")) { //set the document type restriction params.add(CommonParams.FQ, "{!tag=test}nyp\\:DocumentType:Video"); //no facets being generated } else { logger.error("Invalid document type: " + doctype); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid document type: " + doctype); } if (logger.isDebugEnabled()) { logger.debug("Params: " + params); } //set the new request parameters, then call the default handler behavior req.setParams(SolrParams.toSolrParams(params)); super.handleRequestBody(req, rsp); }
From source file:org.alfresco.repo.search.impl.solr.SolrQueryHTTPClient.java
License:Open Source License
protected void buildHightlightParameters(SearchParameters searchParameters, URLCodec encoder, StringBuilder url) throws UnsupportedEncodingException { if (searchParameters.getHighlight() != null) { url.append("&").append(HighlightParams.HIGHLIGHT + "=true"); url.append("&" + HighlightParams.HIGHLIGHT + ".q=") .append(encoder.encode(searchParameters.getSearchTerm(), "UTF-8")); if (searchParameters.getHighlight().getSnippetCount() != null) { url.append("&").append(HighlightParams.SNIPPETS + "=") .append(searchParameters.getHighlight().getSnippetCount()); }//from w w w . j a v a 2s. c o m if (searchParameters.getHighlight().getFragmentSize() != null) { url.append("&").append(HighlightParams.FRAGSIZE + "=") .append(searchParameters.getHighlight().getFragmentSize()); } if (searchParameters.getHighlight().getMaxAnalyzedChars() != null) { url.append("&").append(HighlightParams.MAX_CHARS + "=") .append(searchParameters.getHighlight().getMaxAnalyzedChars()); } if (searchParameters.getHighlight().getMergeContiguous() != null) { url.append("&").append(HighlightParams.MERGE_CONTIGUOUS_FRAGMENTS + "=") .append(searchParameters.getHighlight().getMergeContiguous()); } if (searchParameters.getHighlight().getUsePhraseHighlighter() != null) { url.append("&").append(HighlightParams.USE_PHRASE_HIGHLIGHTER + "=") .append(searchParameters.getHighlight().getUsePhraseHighlighter()); } if (searchParameters.getHighlight().getPrefix() != null) { url.append("&").append(HighlightParams.SIMPLE_PRE + "=") .append(encoder.encode(searchParameters.getHighlight().getPrefix(), "UTF-8")); } if (searchParameters.getHighlight().getPostfix() != null) { url.append("&").append(HighlightParams.SIMPLE_POST + "=") .append(encoder.encode(searchParameters.getHighlight().getPostfix(), "UTF-8")); } if (searchParameters.getHighlight().getFields() != null && !searchParameters.getHighlight().getFields().isEmpty()) { List<String> fieldNames = new ArrayList<>(searchParameters.getHighlight().getFields().size()); for (FieldHighlightParameters aField : searchParameters.getHighlight().getFields()) { ParameterCheck.mandatoryString("highlight field", aField.getField()); fieldNames.add(aField.getField()); if (aField.getSnippetCount() != null) { url.append("&f.").append(encoder.encode(aField.getField(), "UTF-8")) .append("." + HighlightParams.SNIPPETS + "=").append(aField.getSnippetCount()); } if (aField.getFragmentSize() != null) { url.append("&f.").append(encoder.encode(aField.getField(), "UTF-8")) .append("." + HighlightParams.FRAGSIZE + "=").append(aField.getFragmentSize()); } if (aField.getFragmentSize() != null) { url.append("&f.").append(encoder.encode(aField.getField(), "UTF-8")) .append("." + HighlightParams.FRAGSIZE + "=").append(aField.getFragmentSize()); } if (aField.getMergeContiguous() != null) { url.append("&f.").append(encoder.encode(aField.getField(), "UTF-8")) .append("." + HighlightParams.MERGE_CONTIGUOUS_FRAGMENTS + "=") .append(aField.getMergeContiguous()); } if (aField.getPrefix() != null) { url.append("&f.").append(encoder.encode(aField.getField(), "UTF-8")) .append("." + HighlightParams.SIMPLE_PRE + "=") .append(encoder.encode(aField.getPrefix(), "UTF-8")); } if (aField.getPostfix() != null) { url.append("&f.").append(encoder.encode(aField.getField(), "UTF-8")) .append("." + HighlightParams.SIMPLE_POST + "=") .append(encoder.encode(aField.getPostfix(), "UTF-8")); } } url.append("&").append(HighlightParams.FIELDS + "=") .append(encoder.encode(String.join(",", fieldNames), "UTF-8")); } } }
From source file:org.alfresco.solr.highlight.AlfrescoHighlighterTest.java
License:Open Source License
@Test public void highlightingSnippetsFragSizeTest() { logger.info("######### Testing SNIPPETS / FRAGSIZE ###########"); SolrServletRequest req = areq(//ww w . ja v a 2 s .c om params("q", "name:long", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", HighlightParams.Q, "long", HighlightParams.FIELDS, "content,name,title", HighlightParams.SNIPPETS, String.valueOf(4), HighlightParams.FRAGSIZE, String.valueOf(40)), "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}"); assertQ(req, "*[count(//lst[@name='highlighting']/lst)=2]", "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='some very <em>long</em> name']", "//lst[@name='highlighting']/lst[1]/arr[@name='title']/str[.='title1 is very <em>long</em>']", "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='this is some <em>long</em> text. It has the']", "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' word <em>long</em> in many places. In fact, it has']", "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' <em>long</em> on some different fragments. Let us']", "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' see what happens to <em>long</em> in this case.']"); }
From source file:org.alfresco.solr.highlight.AlfrescoHighlighterTest.java
License:Open Source License
@Test public void highlightingPhraseQueriesTest() { logger.info("######### Testing PHRASE QUERIES ###########"); //Phrase hightling is on by default SolrServletRequest req = areq(//from ww w .ja va 2 s .c om params("q", "name:long", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", HighlightParams.Q, "\"some long\"", HighlightParams.FIELDS, "name", HighlightParams.SIMPLE_PRE, "(", HighlightParams.SIMPLE_POST, ")", HighlightParams.SNIPPETS, String.valueOf(1), HighlightParams.FRAGSIZE, String.valueOf(100)), "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}"); assertQ(req, "//lst[@name='highlighting']/lst/arr/str[.='this is (some) (long) text. It has the word long in many places. In fact, it has long on some']"); req = areq( params("q", "name:long", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", HighlightParams.Q, "\"some long\"", HighlightParams.FIELDS, "name", HighlightParams.USE_PHRASE_HIGHLIGHTER, "false", HighlightParams.SIMPLE_PRE, "(", HighlightParams.SIMPLE_POST, ")", HighlightParams.SNIPPETS, String.valueOf(1), HighlightParams.FRAGSIZE, String.valueOf(100)), "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}"); assertQ(req, "//lst[@name='highlighting']/lst/arr/str[.='(some) very (long) name']", "//lst[@name='highlighting']/lst/arr/str[.='this is (some) (long) text. It has the word (long) in many places. In fact, it has (long) on (some)']"); }
From source file:org.alfresco.solr.highlight.AlfrescoHighlighterTest.java
License:Open Source License
@Test public void highlightingMaxAnalyzedCharsTest() { logger.info("######### maxAnalyzedChars ###########"); SolrServletRequest req = areq(params("q", "name:long", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", HighlightParams.Q, "long", HighlightParams.FIELDS, "name,title", HighlightParams.MAX_CHARS, "18", HighlightParams.SIMPLE_PRE, "{", HighlightParams.SIMPLE_POST, "}"), "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}"); assertQ(req, "*[count(//lst[@name='highlighting']/lst)=2]", "*[count(//lst[@name='highlighting']/lst/arr[@name='name'])=2]", "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='some very {long} name']", "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='this is some {long}']"); }
From source file:org.alfresco.solr.highlight.AlfrescoHighlighterTest.java
License:Open Source License
@Test public void highlightingMergeContinuousFragmentsTest() { logger.info("######### MergeContiguous ###########"); SolrServletRequest req = areq(/*from w ww . jav a 2s . c om*/ params("q", "name:long", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", HighlightParams.Q, "'some long'", HighlightParams.FIELDS, "name", HighlightParams.MERGE_CONTIGUOUS_FRAGMENTS, "true", HighlightParams.SIMPLE_PRE, "{", HighlightParams.SIMPLE_POST, "}", HighlightParams.SNIPPETS, String.valueOf(4), HighlightParams.FRAGSIZE, String.valueOf(40)), "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}"); assertQ(req, "*[count(//lst[@name='highlighting']/lst/arr)=1]", "//lst[@name='highlighting']/lst/arr[@name='name']/str[.='this is {some} {long} text. It has the word long in many places. In fact, it has long on some different fragments. Let us see what happens to long in this case.']"); }
From source file:org.alfresco.solr.highlight.AlfrescoHighlighterTest.java
License:Open Source License
@Test public void highlightingLocalConfigurationsTest() { logger.info("######### testLocal ###########"); SolrServletRequest req = areq(//from w w w .ja v a 2 s .co m params("q", "name:long", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", HighlightParams.Q, "long", HighlightParams.FIELDS, "name,title", "f.title." + HighlightParams.SIMPLE_PRE, "(", "f.title." + HighlightParams.SIMPLE_POST, ")", "f.name." + HighlightParams.SIMPLE_PRE, "[", "f.name." + HighlightParams.SIMPLE_POST, "]", HighlightParams.SIMPLE_PRE, "{", HighlightParams.SIMPLE_POST, "}"), "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}"); assertQ(req, "*[count(//lst[@name='highlighting']/lst/arr[@name='name'])=2]", "*[count(//lst[@name='highlighting']/lst/str[@name='DBID'])=2]", "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='some very [long] name']", "//lst[@name='highlighting']/lst[1]/arr[@name='title']/str[.='title1 is very (long)']", "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='this is some [long] text. It has the word [long] in many places. In fact, it has [long] on some']"); }
From source file:org.alfresco.solr.highlight.AlfrescoHighlighterTest.java
License:Open Source License
@Test public void highlightingRequiredFieldsTest() { logger.info("######### requireFieldMatch ###########"); SolrServletRequest req = areq(// w w w . j a v a 2s. c o m params("q", "name:long", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", HighlightParams.Q, "long", HighlightParams.FIELDS, "name,title", HighlightParams.SIMPLE_PRE, "{", HighlightParams.SIMPLE_POST, "}"), "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}"); assertQ(req, "*[count(//lst[@name='highlighting']/lst)=2]", "*[count(//lst[@name='highlighting']/lst/arr[@name='title'])=1]", "//lst[@name='highlighting']/lst[1]/arr[@name='title']/str[.='title1 is very {long}']"); //add name req = areq(params("q", "name:long OR title:long", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", HighlightParams.Q, "title:long", HighlightParams.FIELDS, "name,title", HighlightParams.FIELD_MATCH, "true", HighlightParams.SIMPLE_PRE, "{", HighlightParams.SIMPLE_POST, "}"), "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}"); assertQ(req, "*[count(//lst[@name='highlighting']/lst)=2]", "*[count(//lst[@name='highlighting']/lst/arr[@name='title'])=1]", "*[count(//lst[@name='highlighting']/lst/arr[@name='name'])=0]", "//lst[@name='highlighting']/lst[1]/arr[@name='title']/str[.='title1 is very {long}']"); logger.info("######### MultiTerm ###########"); }
From source file:org.alfresco.solr.highlight.AlfrescoHighlighterTest.java
License:Open Source License
@Test public void highlightingPrePostTest() { logger.info("######### Testing PRE / POST ###########"); SolrServletRequest req = areq(//from ww w. j a v a2 s . com params("q", "name:long", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", HighlightParams.Q, "long", HighlightParams.FIELDS, "content,name,title", HighlightParams.SIMPLE_PRE, "<al>", HighlightParams.SIMPLE_POST, "<fresco>", HighlightParams.SNIPPETS, String.valueOf(4), HighlightParams.FRAGSIZE, String.valueOf(40)), "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}"); assertQ(req, "*[count(//lst[@name='highlighting']/lst)=2]", "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='some very <al>long<fresco> name']", "//lst[@name='highlighting']/lst[1]/arr[@name='title']/str[.='title1 is very <al>long<fresco>']", "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='this is some <al>long<fresco> text. It has the']", "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' word <al>long<fresco> in many places. In fact, it has']", "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' <al>long<fresco> on some different fragments. Let us']", "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' see what happens to <al>long<fresco> in this case.']"); }
From source file:org.alfresco.solr.highlight.AlfrescoHighlighterTest.java
License:Open Source License
@Test public void highlightingCamelCaseTest() { logger.info("######### CamelCase ###########"); SolrServletRequest req = areq(/*from w ww. j a va2 s . c o m*/ params("q", "name:cabbage", "qt", "/afts", "start", "0", "rows", "5", HighlightParams.HIGHLIGHT, "true", //HighlightParams.Q, "lon*", HighlightParams.FIELDS, "name", HighlightParams.HIGHLIGHT_MULTI_TERM, "false", HighlightParams.SIMPLE_PRE, "{", HighlightParams.SIMPLE_POST, "}", HighlightParams.SNIPPETS, String.valueOf(1), HighlightParams.FRAGSIZE, String.valueOf(100)), "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}"); assertQ(req, "*[count(//lst[@name='highlighting']/lst)=1]", "*[count(//lst[@name='highlighting']/lst/arr[@name='name'])=1]", "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='Mixed{Cabbage}String and plurals and discussion']"); }