Class SearchResultConverter

java.lang.Object
io.goobi.viewer.model.iiif.search.SearchResultConverter

public class SearchResultConverter extends Object
Converts resources found in a search to IIIF Search objects
Author:
florian
  • Constructor Details

    • SearchResultConverter

      public SearchResultConverter(AbstractApiUrlManager urls, String pi, Integer pageNo)
      Create a new converter; parameters are used to construct urls or result resources
      Parameters:
      urls -
      pi - The PI of the manifest to search
      pageNo - The page number of generated resources
  • Method Details

    • setPi

      public void setPi(String pi)

      Setter for the field pi.

      Parameters:
      pi - a String object.
    • getPi

      public String getPi()

      Getter for the field pi.

      Returns:
      a String object.
    • setPageNo

      public void setPageNo(Integer pageNo)

      Setter for the field pageNo.

      Parameters:
      pageNo - a Integer object.
    • getPageNo

      public Integer getPageNo()

      Getter for the field pageNo.

      Returns:
      a Integer object.
    • getPresentationBuilder

      public AbstractBuilder getPresentationBuilder()

      Getter for the field presentationBuilder.

      Returns:
      a AbstractBuilder object.
    • convertCommentToHit

      public de.intranda.api.iiif.search.SearchHit convertCommentToHit(String queryRegex, String pi, Comment comment)
      Generates a search hit from a Comment
      Parameters:
      pi - The PI of the work containing the comment
      queryRegex - The regex matching the search terms
      comment - 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)
      Create a IIIF Search hit from a UGC solr document (usually a crowdsourcing created comment/metadata)
      Parameters:
      queryRegex - a String object.
      ugc - a SolrDocument object.
      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)
      Create a IIIF Search hit from the field fieldName within the SolrDocumnet doc
      Parameters:
      queryRegex - a String object.
      fieldName - a String object.
      doc - a SolrDocument object.
      Returns:
      A search hit for a Solr field search
    • getAnnotationsFromAlto

      public AnnotationResultList getAnnotationsFromAlto(Path path, String query) throws IOException, org.jdom2.JDOMException
      Create annotations for all matches of the given query within the given alto file
      Parameters:
      path -
      query - a regex; each match of the query within the alto document creates a SearchHit with 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.JDOMException
      IOException
    • 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 search
      pi - the PI of the work containing the annotations
      pageNo - The page number of the canvas containing the annotations
      query - The regex matching all hits in the text file
      previousHitCount - The number of hits already found in previous pages
      firstIndex - 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 collection
      numHits - 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 as SearchTerms
      Parameters:
      regex - A regex matching all text wich should be returned as a searchTerm
      doc - The document within to search
      fieldsToSearch - The fields to search for the regex
      searchMotivation - The motivation to be set for the search url of the searchTerms
      Returns:
      A list of search terms
    • getSearchTerms

      public SearchTermList getSearchTerms(String regex, String value, List<String> searchMotivation)
      Get all matches to the given regex in the given value as SearchTerms
      Parameters:
      regex - A regex matching all text wich should be returned as a searchTerm
      value - The text to be searched with the regex
      searchMotivation - 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)
      Convert 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 a SearchHit of the text within the given position within the given lines.
      Parameters:
      lines - The lines containing the hit
      position - A range covering character positions of the matched text. the position is relative to the entire text of the given lines
      containingLines - 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 hit
      text - The text to search
      pi - The PI of the manifest containing the annotations
      pageNo - 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