Skip to content

Ineffective conditional and logic error in "search()" view. #136

@qzMalekuz

Description

@qzMalekuz

While auditing the search implementation in search/views.py, I identified a functional logic error where the view attempts to validate search results using an ineffective conditional:

File: search/views.py. (Lines 90–91).

Image

1. Problem

The _xapian_search function (Line 34) initializes all_results = {} and populates it with model name strings as keys.

  • Checking "if None in (c['results'])" checks if "None" is a key in the results dictionary.
  • Since _xapian_search never uses "None" as a key, this conditional will always return False.
  • This effectively breaks the selection logic between the primary search (c) and the fallback "compact" search (d).

2. Current Behavior

Currently, the search view consistently returns the results of "d" (the search with all spaces removed via "removespace(query)"), regardless of whether the primary space-preserved search (c) found matches. This can lead to unexpected search results when multi-word queries are used.

3. Proposed Fix

Refactor the logic to correctly prioritize the primary search results:

  • Check if the primary search (c['results']) is not empty (if c['results']:).
  • If the primary search finds matches, it should be preferred over the space-removed fallback.
  • Update the conditional to correctly reference the dictionary content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions