Beispiel #1
0
    def get_subject(self, key, details=False, offset=0, limit=12, sort='first_publish_year desc', **filters):
        meta = self.get_meta(key)

        q = self.make_query(key, filters)
        subject_type = meta.name
        name = meta.path.replace("_", " ")

        if details:
            kw = self.query_optons_for_details()
        else:
            kw = {}

        from search import work_search
        result = work_search(q, offset=offset, limit=limit, sort=sort, **kw)
        for w in result.docs:
            w.ia = w.ia and w.ia[0] or None

        subject = Subject(
            key=key,
            name=name,
            subject_type=subject_type,
            work_count = result['num_found'],
            works=result['docs']
        )

        if details:
            #subject.ebook_count = dict(result.facets["has_fulltext"]).get("true", 0)
            subject.ebook_count = self.get_ebook_count(meta.name, q[meta.facet_key], q.get('publish_year'))

            subject.subjects = result.facets["subject_facet"]
            subject.places = result.facets["place_facet"]
            subject.people = result.facets["person_facet"]
            subject.times = result.facets["time_facet"]

            subject.authors = result.facets["author_facet"]
            subject.publishers = result.facets["publisher_facet"]

            subject.publishing_history = [[year, count] for year, count in result.facets["publish_year"] if year > 1000]

            # strip self from subjects and use that to find exact name
            for i, s in enumerate(subject[meta.key]):
                if s.key.lower() == key.lower():
                    subject.name = s.name;
                    subject[meta.key].pop(i)
                    break

        return subject
Beispiel #2
0
    def get_subject(self, key, details=False, offset=0, limit=12, sort="first_publish_year desc", **filters):
        meta = self.get_meta(key)

        q = self.make_query(key, filters)
        subject_type = meta.name
        name = meta.path.replace("_", " ")

        if details:
            kw = self.query_optons_for_details()
        else:
            kw = {}

        from search import work_search

        result = work_search(q, offset=offset, limit=limit, sort=sort, **kw)
        for w in result.docs:
            w.ia = w.ia and w.ia[0] or None
            if not w.get("public_scan") and w.ia and w.get("lending_edition"):
                doc = web.ctx.site.store.get("ebooks/books/" + w["lending_edition"]) or {}
                w["checked_out"] = doc.get("borrowed") == "true"

            # XXX-Anand: Oct 2013
            # Somewhere something is broken, work keys are coming as OL1234W/works/
            # Quick fix it solve that issue.
            if w.key.endswith("/works/"):
                w.key = "/works/" + w.key.replace("/works/", "")

        subject = Subject(
            key=key, name=name, subject_type=subject_type, work_count=result["num_found"], works=result["docs"]
        )

        if details:
            subject.ebook_count = dict(result.facets["has_fulltext"]).get("true", 0)
            # subject.ebook_count = self.get_ebook_count(meta.name, q[meta.facet_key], q.get('publish_year'))

            subject.subjects = result.facets["subject_facet"]
            subject.places = result.facets["place_facet"]
            subject.people = result.facets["person_facet"]
            subject.times = result.facets["time_facet"]

            subject.authors = result.facets["author_facet"]
            subject.publishers = result.facets["publisher_facet"]
            subject.languages = result.facets["language"]

            # Ignore bad dates when computing publishing_history
            # year < 1000 or year > current_year+1 are considered bad dates
            current_year = datetime.datetime.utcnow().year
            subject.publishing_history = [
                [year, count] for year, count in result.facets["publish_year"] if 1000 < year <= current_year + 1
            ]

            # strip self from subjects and use that to find exact name
            for i, s in enumerate(subject[meta.key]):
                if "key" in s and s.key.lower() == key.lower():
                    subject.name = s.name
                    subject[meta.key].pop(i)
                    break

        return subject
Beispiel #3
0
    def get_subject(self,
                    key,
                    details=False,
                    offset=0,
                    limit=12,
                    sort='first_publish_year desc',
                    **filters):
        meta = self.get_meta(key)

        q = self.make_query(key, filters)
        subject_type = meta.name
        name = meta.path.replace("_", " ")

        if details:
            kw = self.query_optons_for_details()
        else:
            kw = {}

        from search import work_search
        result = work_search(q, offset=offset, limit=limit, sort=sort, **kw)
        if not result:
            return None

        for w in result.docs:
            w.ia = w.ia and w.ia[0] or None
            w['checked_out'] = False
            if not w.get('public_scan') and w.ia and w.get(
                    'lending_identifier'):
                doc = web.ctx.site.store.get("ebooks/" +
                                             w['lending_identifier']) or {}
                w['checked_out'] = doc.get("borrowed") == "true"

            # XXX-Anand: Oct 2013
            # Somewhere something is broken, work keys are coming as OL1234W/works/
            # Quick fix it solve that issue.
            if w.key.endswith("/works/"):
                w.key = "/works/" + w.key.replace("/works/", "")

        subject = Subject(key=key,
                          name=name,
                          subject_type=subject_type,
                          work_count=result['num_found'],
                          works=result['docs'])

        if details:
            subject.ebook_count = dict(result.facets["has_fulltext"]).get(
                "true", 0)
            #subject.ebook_count = self.get_ebook_count(meta.name, q[meta.facet_key], q.get('publish_year'))

            subject.subjects = result.facets["subject_facet"]
            subject.places = result.facets["place_facet"]
            subject.people = result.facets["person_facet"]
            subject.times = result.facets["time_facet"]

            subject.authors = result.facets["author_facet"]
            subject.publishers = result.facets["publisher_facet"]
            subject.languages = result.facets['language']

            # Ignore bad dates when computing publishing_history
            # year < 1000 or year > current_year+1 are considered bad dates
            current_year = datetime.datetime.utcnow().year
            subject.publishing_history = [[
                year, count
            ] for year, count in result.facets["publish_year"]
                                          if 1000 < year <= current_year + 1]

            # strip self from subjects and use that to find exact name
            for i, s in enumerate(subject[meta.key]):
                if "key" in s and s.key.lower() == key.lower():
                    subject.name = s.name
                    subject[meta.key].pop(i)
                    break

        # Fetch more works until offset is > than work_count.
        # This ensures that we render the correct ammount of works.
        if offset < subject.work_count:
            rest_subject = get_subject(key,
                                       details=details,
                                       offset=limit + offset,
                                       sort=sort,
                                       limit=limit,
                                       **filters)
            if len(rest_subject.works) > 0:
                subject.works.extend(rest_subject.works)

        return subject
Beispiel #4
0
    def get_subject(
        self,
        key,
        details=False,
        offset=0,
        limit=DEFAULT_RESULTS,
        sort='first_publish_year desc',
        **filters,
    ):
        meta = self.get_meta(key)

        q = self.make_query(key, filters)
        subject_type = meta.name
        name = meta.path.replace("_", " ")

        if details:
            kw = self.query_optons_for_details()
        else:
            kw = {}

        result = work_search(q, offset=offset, limit=limit, sort=sort, **kw)
        if not result:
            return None

        for w in result.docs:
            w.ia = w.ia and w.ia[0] or None

            # XXX-Anand: Oct 2013
            # Somewhere something is broken, work keys are coming as OL1234W/works/
            # Quick fix it solve that issue.
            if w.key.endswith("/works/"):
                w.key = "/works/" + w.key.replace("/works/", "")

        subject = Subject(
            key=key,
            name=name,
            subject_type=subject_type,
            work_count=result['num_found'],
            works=add_availability(result['docs']),
        )

        if details:
            subject.ebook_count = dict(result.facets["has_fulltext"]).get("true", 0)

            subject.subjects = result.facets["subject_facet"]
            subject.places = result.facets["place_facet"]
            subject.people = result.facets["person_facet"]
            subject.times = result.facets["time_facet"]

            subject.authors = result.facets["author_facet"]
            subject.publishers = result.facets["publisher_facet"]
            subject.languages = result.facets['language']

            # Ignore bad dates when computing publishing_history
            # year < 1000 or year > current_year+1 are considered bad dates
            current_year = datetime.datetime.utcnow().year
            subject.publishing_history = [
                [year, count]
                for year, count in result.facets["publish_year"]
                if 1000 < year <= current_year + 1
            ]

            # strip self from subjects and use that to find exact name
            for i, s in enumerate(subject[meta.key]):
                if "key" in s and s.key.lower() == key.lower():
                    subject.name = s.name
                    subject[meta.key].pop(i)
                    break

        return subject
Beispiel #5
0
    def get_subject(self, key, details=False, offset=0, limit=12, sort='first_publish_year desc', **filters):
        meta = self.get_meta(key)

        q = self.make_query(key, filters)
        subject_type = meta.name
        name = meta.path.replace("_", " ")

        if details:
            kw = self.query_optons_for_details()
        else:
            kw = {}

        from search import work_search
        result = work_search(q, offset=offset, limit=limit, sort=sort, **kw)
        for w in result.docs:
            w.ia = w.ia and w.ia[0] or None
            if not w.get('public_scan') and w.ia and w.get('lending_edition'):
                doc = web.ctx.site.store.get("ebooks/books/" + w['lending_edition']) or {}
                w['checked_out'] = doc.get("borrowed") == "true"
                
        subject = Subject(
            key=key,
            name=name,
            subject_type=subject_type,
            work_count = result['num_found'],
            works=result['docs']
        )

        if details:
            subject.ebook_count = dict(result.facets["has_fulltext"]).get("true", 0)
            #subject.ebook_count = self.get_ebook_count(meta.name, q[meta.facet_key], q.get('publish_year'))

            subject.subjects = result.facets["subject_facet"]
            subject.places = result.facets["place_facet"]
            subject.people = result.facets["person_facet"]
            subject.times = result.facets["time_facet"]

            subject.authors = result.facets["author_facet"]
            subject.publishers = result.facets["publisher_facet"]
            subject.languages = result.facets['language']

            subject.publishing_history = [[year, count] for year, count in result.facets["publish_year"] if year > 1000]

            # strip self from subjects and use that to find exact name
            for i, s in enumerate(subject[meta.key]):
                if "key" in s and s.key.lower() == key.lower():
                    subject.name = s.name;
                    subject[meta.key].pop(i)
                    break

        return subject