def get_publication_vals(pub, include_articles, add_type=False): """Extract public fields from a Publication record.""" vals = { "pub_id": pub.pub_id, "pub_name": pub.pub_name, "pub_edition": pub.pub_edition, "pub_date": pub.pub_date, "pub_description": pub.pub_description, "pub_url": pub.pub_url, "pub_seqno": pub.pub_seqno, "pub_image_id": pub.pub_id if pub.pub_image else None, "pub_tags": decode_tags(pub.pub_tags), "publ_id": pub.publ_id, "time_created": int(pub.time_created.timestamp()) if pub.time_created else None, } if include_articles: articles = sorted(pub.articles, key=get_article_sort_key) vals["articles"] = [get_article_vals(a) for a in articles] if add_type: vals["type"] = "publication" return vals
def get_publication_vals(pub, include_articles, deep): """Extract public fields from a Publication record.""" vals = { "_type": "publication", "pub_id": pub.pub_id, "pub_name": pub.pub_name, "pub_edition": pub.pub_edition, "pub_date": pub.pub_date, "pub_description": pub.pub_description, "pub_url": pub.pub_url, "pub_seqno": pub.pub_seqno, "pub_image_id": pub.pub_id if pub.pub_image else None, "pub_tags": decode_tags(pub.pub_tags), "publ_id": pub.publ_id, "time_created": int(pub.time_created.timestamp()) if pub.time_created else None, } if include_articles: articles = sorted(pub.articles, key=get_article_sort_key) vals["articles"] = [get_article_vals(a, False) for a in articles] if deep: vals["_parent_publ"] = asl_articles.publishers.get_publisher_vals( pub.parent_publ, False, False) if pub.parent_publ else None return vals
def search_publication(pub_id): """Search for a publication.""" pub = Publication.query.get(pub_id) if not pub: return jsonify([]) results = [get_publication_vals(pub, True, True)] articles = sorted(pub.articles, key=get_article_sort_key) for article in articles: article = get_article_vals(article, True) _create_aslrb_links(article) results.append(article) return jsonify(results)
def search_article(article_id): """Search for an article.""" article = Article.query.get(article_id) if not article: return jsonify([]) article = get_article_vals(article, True) _create_aslrb_links(article) results = [article] if article["pub_id"]: pub = Publication.query.get(article["pub_id"]) if pub: results.append(get_publication_vals(pub, True, True)) return jsonify(results)
def search_article( article_id ): """Search for an article.""" article = Article.query.get( article_id ) if not article: return jsonify( [] ) vals = get_article_vals( article, True ) _create_aslrb_links( vals ) results = [ vals ] if article.parent_pub: results.append( get_publication_vals( article.parent_pub, True, True ) ) if article.parent_publ: results.append( get_publisher_vals( article.parent_publ, True, True ) ) return jsonify( results )
def get_publisher_vals( publ, include_pubs, include_articles ): """Extract public fields from a Publisher record.""" vals = { "_type": "publisher", "publ_id": publ.publ_id, "publ_name": publ.publ_name, "publ_description": publ.publ_description, "publ_url": publ.publ_url, "publ_image_id": publ.publ_id if publ.publ_image else None, } if include_pubs: pubs = sorted( publ.publications, key=get_publication_sort_key ) vals[ "publications" ] = [ get_publication_vals( p, False, False ) for p in pubs ] if include_articles: articles = sorted( publ.articles, key=get_article_sort_key ) vals[ "articles" ] = [ get_article_vals( a, False ) for a in articles ] return vals
_search_index_path = None _search_aliases = {} _search_weights = {} _author_aliases = {} _logger = logging.getLogger("search") _SQLITE_FTS_SPECIAL_CHARS = "+-#':/.@$" # NOTE: The column order defined here is important, since we have to access row results by column index. _SEARCHABLE_COL_NAMES = [ "name", "name2", "description", "authors", "scenarios", "tags" ] _get_publisher_vals = lambda p: get_publisher_vals(p, True) _get_publication_vals = lambda p: get_publication_vals(p, True, True) _get_article_vals = lambda a: get_article_vals(a, True) _PASSTHROUGH_REGEXES = set([ re.compile(r"\bAND\b"), re.compile(r"\bOR\b"), re.compile(r"\bNOT\b"), re.compile(r"\((?![Rr]\))"), ]) # NOTE: The following are special search terms used by the test suite. SEARCH_ALL = "<!all!>" SEARCH_ALL_PUBLISHERS = "<!publishers!>" SEARCH_ALL_PUBLICATIONS = "<!publications!>" SEARCH_ALL_ARTICLES = "<!articles!>" BEGIN_HILITE = '<span class="hilite">'