private static BoundaryScanner getBoundaryScanner(Field field) { final FieldOptions fieldOptions = field.fieldOptions(); final Locale boundaryScannerLocale = fieldOptions.boundaryScannerLocale(); switch(fieldOptions.boundaryScannerType()) { case SENTENCE: if (boundaryScannerLocale != null) { return new BreakIteratorBoundaryScanner(BreakIterator.getSentenceInstance(boundaryScannerLocale)); } return DEFAULT_SENTENCE_BOUNDARY_SCANNER; case WORD: if (boundaryScannerLocale != null) { return new BreakIteratorBoundaryScanner(BreakIterator.getWordInstance(boundaryScannerLocale)); } return DEFAULT_WORD_BOUNDARY_SCANNER; default: if (fieldOptions.boundaryMaxScan() != SimpleBoundaryScanner.DEFAULT_MAX_SCAN || fieldOptions.boundaryChars() != SimpleBoundaryScanner.DEFAULT_BOUNDARY_CHARS) { return new SimpleBoundaryScanner(fieldOptions.boundaryMaxScan(), fieldOptions.boundaryChars()); } return DEFAULT_SIMPLE_BOUNDARY_SCANNER; } }
public SourceScoreOrderFragmentsBuilder(FieldMapper mapper, SearchContext searchContext, FetchSubPhase.HitContext hitContext, String[] preTags, String[] postTags, BoundaryScanner boundaryScanner) { super(preTags, postTags, boundaryScanner); this.mapper = mapper; this.searchContext = searchContext; this.hitContext = hitContext; }
@Override protected BoundaryScanner get(String fieldName, SolrParams params) { // construct Locale String language = params.getFieldParam(fieldName, HighlightParams.BS_LANGUAGE); String country = params.getFieldParam(fieldName, HighlightParams.BS_COUNTRY); if(country != null && language == null){ throw new SolrException(ErrorCode.BAD_REQUEST, HighlightParams.BS_LANGUAGE + " parameter cannot be null when you specify " + HighlightParams.BS_COUNTRY); } Locale locale = null; if(language != null){ locale = country == null ? new Locale(language) : new Locale(language, country); } else { locale = Locale.ROOT; } // construct BreakIterator String type = params.getFieldParam(fieldName, HighlightParams.BS_TYPE, "WORD").toLowerCase(Locale.ROOT); BreakIterator bi = null; if(type.equals("character")){ bi = BreakIterator.getCharacterInstance(locale); } else if(type.equals("word")){ bi = BreakIterator.getWordInstance(locale); } else if(type.equals("line")){ bi = BreakIterator.getLineInstance(locale); } else if(type.equals("sentence")){ bi = BreakIterator.getSentenceInstance(locale); } else throw new SolrException(ErrorCode.BAD_REQUEST, type + " is invalid for parameter " + HighlightParams.BS_TYPE); return new org.apache.lucene.search.vectorhighlight.BreakIteratorBoundaryScanner(bi); }
/** * Return a {@link org.apache.lucene.search.vectorhighlight.FragmentsBuilder} appropriate for this field. * * @param params The params controlling Highlighting * @return An appropriate {@link org.apache.lucene.search.vectorhighlight.FragmentsBuilder}. */ public FragmentsBuilder getFragmentsBuilder(SolrParams params, BoundaryScanner bs) { numRequests++; params = SolrParams.wrapDefaults(params, defaults); return getFragmentsBuilder( params, getPreTags( params, null ), getPostTags( params, null ), bs ); }
@Override protected FragmentsBuilder getFragmentsBuilder( SolrParams params, String[] preTags, String[] postTags, BoundaryScanner bs ) { org.apache.lucene.search.vectorhighlight.SimpleFragmentsBuilder sfb = new org.apache.lucene.search.vectorhighlight.SimpleFragmentsBuilder( preTags, postTags, bs ); sfb.setMultiValuedSeparator( getMultiValuedSeparatorChar( params ) ); return sfb; }
@Override protected FragmentsBuilder getFragmentsBuilder( SolrParams params, String[] preTags, String[] postTags, BoundaryScanner bs ) { org.apache.lucene.search.vectorhighlight.ScoreOrderFragmentsBuilder sofb = new org.apache.lucene.search.vectorhighlight.ScoreOrderFragmentsBuilder( preTags, postTags, bs ); sofb.setMultiValuedSeparator( getMultiValuedSeparatorChar( params ) ); return sofb; }
@Override protected BoundaryScanner get(String fieldName, SolrParams params) { int maxScan = params.getFieldInt(fieldName, HighlightParams.BS_MAX_SCAN, 10); String str = params.getFieldParam(fieldName, HighlightParams.BS_CHARS, ".,!? \t\n"); Character[] chars = new Character[str.length()]; for(int i = 0; i < str.length(); i++){ chars[i] = str.charAt(i); } return new org.apache.lucene.search.vectorhighlight.SimpleBoundaryScanner(maxScan, chars); }
private BoundaryScanner getBoundaryScanner(String fieldName, SolrParams params) { String bs = params.getFieldParam(fieldName, HighlightParams.BOUNDARY_SCANNER); SolrBoundaryScanner solrBs = boundaryScanners.get(bs); if (solrBs == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown boundaryScanner: " + bs); } return solrBs.getBoundaryScanner(fieldName, params); }
public SourceScoreOrderFragmentsBuilder(FieldMapper mapper, SearchContext searchContext, String[] preTags, String[] postTags, BoundaryScanner boundaryScanner) { super(preTags, postTags, boundaryScanner); this.mapper = mapper; this.searchContext = searchContext; }
public SimpleFragmentsBuilder(FieldMapper mapper, String[] preTags, String[] postTags, BoundaryScanner boundaryScanner) { super(preTags, postTags, boundaryScanner); this.mapper = mapper; }
public SourceSimpleFragmentsBuilder(FieldMapper mapper, SearchContext searchContext, String[] preTags, String[] postTags, BoundaryScanner boundaryScanner) { super(mapper, preTags, postTags, boundaryScanner); this.searchContext = searchContext; }
public SourceSimpleFragmentsBuilder(FieldMapper mapper, SearchContext searchContext, FetchSubPhase.HitContext hitContext, String[] preTags, String[] postTags, BoundaryScanner boundaryScanner) { super(mapper, preTags, postTags, boundaryScanner); this.searchContext = searchContext; this.hitContext = hitContext; }
protected abstract FragmentsBuilder getFragmentsBuilder( SolrParams params, String[] preTags, String[] postTags, BoundaryScanner bs );
public BoundaryScanner getBoundaryScanner(String fieldName, SolrParams params){ numRequests++; params = SolrParams.wrapDefaults(params, defaults); return get(fieldName, params); }
protected FragmentsBuilder getFragmentsBuilder(String fieldName, SolrParams params) { BoundaryScanner bs = getBoundaryScanner(fieldName, params); return getSolrFragmentsBuilder(fieldName, params).getFragmentsBuilder(params, bs); }