示例#1
0
def make_cite_count_query(cd: CleanData) -> str:
    """Given the cleaned data from a form, return a valid Solr fq string"""
    start = cd.get("cited_gt") or "*"
    end = cd.get("cited_lt") or "*"
    if start == "*" and end == "*":
        return ""
    else:
        return "citeCount:[%s TO %s]" % (start, end)
示例#2
0
def get_selected_field_string(cd: CleanData, prefix: str) -> str:
    """Pulls the selected checkboxes out of the form data, and puts it into
    Solr strings. Uses a prefix to know which items to pull out of the cleaned
    data. Check forms.py to see how the prefixes are set up.

    Final strings are of the form "A" OR "B" OR "C", with quotes in case there
    are spaces in the values.
    """
    selected_fields = [
        '"%s"' % k.replace(prefix, "") for k, v in cd.items()
        if (k.startswith(prefix) and v is True)
    ]
    if len(selected_fields) == cd["_%scount" % prefix]:
        # All the boxes are checked. No need for filtering.
        return ""
    else:
        selected_field_string = " OR ".join(selected_fields)
        return selected_field_string
示例#3
0
def get_query_citation(cd: CleanData) -> Optional[List[Citation]]:
    """Extract citations from the query string and return them, or return
    None
    """
    if not cd.get("q"):
        return None
    citations = get_citations(cd["q"],
                              do_post_citation=False,
                              do_defendant=False)

    citations = [c for c in citations if isinstance(c, Citation)]

    matches = None
    if len(citations) == 1:
        # If it's not exactly one match, user doesn't get special help.
        matches = match_citation(citations[0])
        if len(matches) == 1:
            # If more than one match, don't show the tip
            return matches.result.docs[0]

    return matches
示例#4
0
def build_main_query(
    cd: CleanData,
    highlight: str = "all",
    order_by: str = "",
    facet: bool = True,
    group: bool = True,
) -> SearchParam:
    main_params = cast(
        SearchParam,
        {
            "q": cleanup_main_query(cd["q"] or "*"),
            "sort": cd.get("order_by", order_by),
            "caller": "build_main_query",
        },
    )
    add_faceting(main_params, cd, facet)
    add_boosts(main_params, cd)
    add_highlighting(main_params, cd, highlight)
    add_filter_queries(main_params, cd)
    add_grouping(main_params, cd, group)

    print_params(main_params)
    return main_params