Ejemplo n.º 1
0
 def __filter_from_root_layer(self, search_def: SearchDef,
                              source_layer: SourceLayer,
                              data: Group) -> VideoArray:
     term_to_videos = source_layer.get_index()
     terms = functions.string_to_pieces(search_def.text)
     if search_def.cond == "exact":
         selection_and = set(data.videos)
         for term in terms:
             selection_and &= term_to_videos.get(term, set())
         video_filter = Video.has_terms_exact
         selection = (video for video in selection_and
                      if video_filter(video, terms))
     elif search_def.cond == "and":
         selection = set(data.videos)
         for term in terms:
             selection &= term_to_videos.get(term, set())
     elif search_def.cond == "id":
         (term, ) = terms
         video_id = int(term)
         selection = (video for video in data.videos
                      if video.video_id == video_id)
     else:  # search_def.cond == 'or'
         selection = set(term_to_videos.get(terms[0], set()))
         for term in terms[1:]:
             selection |= term_to_videos.get(term, set())
         selection &= set(data.videos)
     return VideoArray(selection)
Ejemplo n.º 2
0
 def terms(self, as_set=False):
     term_sources = [self.filename.path, str(self.meta_title)]
     for prop in self.database.get_prop_types():
         if prop.type is str and prop.name in self.properties:
             val = self.properties[prop.name]
             if prop.multiple:
                 term_sources.extend(val)
             else:
                 term_sources.append(val)
     return string_to_pieces(" ".join(term_sources), as_set=as_set)
Ejemplo n.º 3
0
 def find(search: SearchDef, videos: Iterable[Video]) -> Iterable[Video]:
     terms = functions.string_to_pieces(search.text)
     video_filter = getattr(Video, f"has_terms_{search.cond}")
     return (video for video in videos if video_filter(video, terms))
Ejemplo n.º 4
0
 def _key_of(self, text: str) -> str:
     pieces = string_to_pieces(text)
     if len(pieces) > 20:
         pieces = pieces[:20] + ["..."]
     hl_key = "".join(piece.title() for piece in pieces)
     return f"{hl_key}_{FNV64.hash(text)}"
Ejemplo n.º 5
0
 def terms(self, as_set=False):
     return string_to_pieces(self.filename.path, as_set=as_set)