Class SearchResultConverter
java.lang.Object
io.goobi.viewer.model.iiif.search.SearchResultConverter
Converts resources found in a search to IIIF Search objects.
- Author:
- Florian Alpers
-
Constructor Summary
ConstructorsConstructorDescriptionSearchResultConverter(AbstractApiUrlManager urls, String pi, Integer pageNo) Creates a new converter; parameters are used to construct urls or result resources. -
Method Summary
Modifier and TypeMethodDescriptionde.intranda.api.iiif.search.SearchHitconvertAltoToHit(List<de.intranda.digiverso.ocr.alto.model.structureclasses.lineelements.Word> altoElements) Converts a list of also word elements to a search hit, containing an annotation for each word in the list.de.intranda.api.iiif.search.SearchHitconvertCommentToHit(String queryRegex, String pi, Comment comment) Generates a search hit from aComment.de.intranda.api.iiif.search.SearchHitconvertMetadataToHit(String queryRegex, String fieldName, org.apache.solr.common.SolrDocument doc) Creates a IIIF Search hit from the field fieldName within the SolrDocumnet doc.de.intranda.api.iiif.search.SearchHitconvertUGCToHit(String queryRegex, org.apache.solr.common.SolrDocument ugc) Creates a IIIF Search hit from a UGC solr document (usually a crowdsourcing created comment/metadata).de.intranda.api.iiif.search.SearchHitcreateAltoHit(List<de.intranda.digiverso.ocr.alto.model.structureclasses.Line> lines, org.apache.commons.lang3.Range<Integer> position, List<de.intranda.digiverso.ocr.alto.model.structureclasses.Line> containingLines) Creates aSearchHitof the text within the given position within the given lines.de.intranda.api.iiif.search.SearchHitcreateFulltextHit(String queryRegex, String text, String pi, Integer pageNo) Create a SearchHit for the given text.getAnnotationsFromAlto(Path path, String query) Creates annotations for all matches of the given query within the given alto file.getAnnotationsFromFulltext(String text, String pi, Integer pageNo, String query, long previousHitCount, int firstIndex, int numHits) Create annotations for all matches of the given query within the given text file Returns only a partial result if the firstIndex is larger than 0 and numHits is smaller than the total number of hits.Getter for the fieldpageNo.getPi()Getter for the fieldpi.Getter for the fieldpresentationBuilder.getSearchTerms(String regex, String value, List<String> searchMotivation) Get all matches to the given regex in the given value asSearchTerms.getSearchTerms(String regex, org.apache.solr.common.SolrDocument doc, List<String> fieldsToSearch, List<String> searchMotivation) Get all matches to the given regex in the fieldsToSearch of the given doc asSearchTerms.voidSetter for the fieldpageNo.voidSetter for the fieldpi.
-
Constructor Details
-
SearchResultConverter
Creates a new converter; parameters are used to construct urls or result resources.- Parameters:
urls- the API URL manager for constructing resource URIspi- The PI of the manifest to searchpageNo- The page number of generated resources
-
-
Method Details
-
setPi
Setter for the fieldpi.- Parameters:
pi- persistent identifier of the manifest being searched
-
getPi
Getter for the fieldpi.- Returns:
- the persistent identifier (PI) of the record being searched
-
setPageNo
Setter for the fieldpageNo.- Parameters:
pageNo- page order number of generated resources
-
getPageNo
Getter for the fieldpageNo.- Returns:
- the physical page order number of generated search resources, or null if not set
-
getPresentationBuilder
Getter for the fieldpresentationBuilder.- Returns:
- the IIIF presentation v2 builder used to generate annotation URIs
-
convertCommentToHit
public de.intranda.api.iiif.search.SearchHit convertCommentToHit(String queryRegex, String pi, Comment comment) Generates a search hit from aComment.- Parameters:
queryRegex- The regex matching the search termspi- The PI of the work containing the commentcomment- The comment containing the search terms- Returns:
- a
SearchHit
-
convertUGCToHit
public de.intranda.api.iiif.search.SearchHit convertUGCToHit(String queryRegex, org.apache.solr.common.SolrDocument ugc) Creates a IIIF Search hit from a UGC solr document (usually a crowdsourcing created comment/metadata).- Parameters:
queryRegex- regex pattern matching the search termsugc- Solr document of type UGC to search within- Returns:
- A search hit matching the queryRegex within the given UGC SolrDocument
-
convertMetadataToHit
public de.intranda.api.iiif.search.SearchHit convertMetadataToHit(String queryRegex, String fieldName, org.apache.solr.common.SolrDocument doc) Creates a IIIF Search hit from the field fieldName within the SolrDocumnet doc.- Parameters:
queryRegex- regex pattern matching the search termsfieldName- Solr field name to read metadata value fromdoc- Solr document containing the field to search- Returns:
- A search hit for a Solr field search
-
getAnnotationsFromAlto
public AnnotationResultList getAnnotationsFromAlto(Path path, String query) throws IOException, org.jdom2.JDOMException Creates annotations for all matches of the given query within the given alto file.- Parameters:
path- path to the ALTO XML filequery- a regex; each match of the query within the alto document creates aSearchHitwith one or more annotations referencing alto word or line elements- Returns:
- A result list containing hits for each mach of the query and annotations containing the hits
- Throws:
org.jdom2.JDOMExceptionIOException
-
getAnnotationsFromFulltext
public AnnotationResultList getAnnotationsFromFulltext(String text, String pi, Integer pageNo, String query, long previousHitCount, int firstIndex, int numHits) Create annotations for all matches of the given query within the given text file Returns only a partial result if the firstIndex is larger than 0 and numHits is smaller than the total number of hits.- Parameters:
text- the text to searchpi- the PI of the work containing the annotationspageNo- The page number of the canvas containing the annotationsquery- The regex matching all hits in the text filepreviousHitCount- The number of hits already found in previous pagesfirstIndex- The index of the first overal hit to be returned in the result itself. Larger than 0 only for later pages within a paged annotation collectionnumHits- The maximal number of hits to be returned in the result itself. This is the maximal size of the hit list within a single result page of a paged annotation collection- Returns:
- A result list containing all matching hits within the range set by previousHitCount, firstIndex and numHits
-
getSearchTerms
public SearchTermList getSearchTerms(String regex, org.apache.solr.common.SolrDocument doc, List<String> fieldsToSearch, List<String> searchMotivation) Get all matches to the given regex in the fieldsToSearch of the given doc asSearchTerms.- Parameters:
regex- A regex matching all text which should be returned as a searchTermdoc- The document within to searchfieldsToSearch- The fields to search for the regexsearchMotivation- The motivation to be set for the search url of the searchTerms- Returns:
- A list of search terms
-
getSearchTerms
Get all matches to the given regex in the given value asSearchTerms.- Parameters:
regex- A regex matching all text which should be returned as a searchTermvalue- The text to be searched with the regexsearchMotivation- The motivation to be set for the search url of the searchTerms- Returns:
- A list of search terms
-
convertAltoToHit
public de.intranda.api.iiif.search.SearchHit convertAltoToHit(List<de.intranda.digiverso.ocr.alto.model.structureclasses.lineelements.Word> altoElements) Converts a list of also word elements to a search hit, containing an annotation for each word in the list.- Parameters:
altoElements- A list of ALTO word elements- Returns:
- A hit of the combined words
-
createAltoHit
public de.intranda.api.iiif.search.SearchHit createAltoHit(List<de.intranda.digiverso.ocr.alto.model.structureclasses.Line> lines, org.apache.commons.lang3.Range<Integer> position, List<de.intranda.digiverso.ocr.alto.model.structureclasses.Line> containingLines) Creates aSearchHitof the text within the given position within the given lines.- Parameters:
lines- The lines containing the hitposition- A range covering character positions of the matched text. the position is relative to the entire text of the given linescontainingLines- The lines to be included as annotations in the hit- Returns:
- A search hit containing the match at the given position
-
createFulltextHit
public de.intranda.api.iiif.search.SearchHit createFulltextHit(String queryRegex, String text, String pi, Integer pageNo) Create a SearchHit for the given text. Each match of the given queryRegex in the text is included as a TextQuoteSelector in the hit- Parameters:
queryRegex- The regex matching the hittext- The text to searchpi- The PI of the manifest containing the annotationspageNo- The order of the canvas containing the annotations- Returns:
- A search hit containing a TextQuoteSelector for each match of the regex and a single annotations covering the entire text
-