fix: prefer rent price for mixed buy-rent search results#13
Conversation
There was a problem hiding this comment.
A few concerns before merging.
Inconsistent offering_type application: _hit now resolves the offering type via the preferred hint, but _property_details still uses first(source.get("offering_type")). For a mixed ["buy", "rent"] listing this can yield offering_type="rent" on the Listing while raw_offering_type/status are derived from "buy". The preferred type should either flow through that path too, or the parser should intentionally keep those concepts separate with test coverage.
| rent_amount = first(price.get("rent_price")) | ||
| sale_range = mapping(price.get("selling_price_range")) | ||
| rent_range = mapping(price.get("rent_price_range")) | ||
| range_data = sale_range or rent_range |
There was a problem hiding this comment.
The initial range_data = sale_range or rent_range is now dead code since both branches of the if/else immediately reassign it. Please drop that line. The else branch also just re-derives the original behavior, so this could collapse into a single prefer_rent flag instead of duplicating three lines per branch.
| ) | ||
|
|
||
|
|
||
| def _offering_type(value: Any, preferred: str | None = None) -> str | None: |
There was a problem hiding this comment.
_offering_type() adds a second raw-offering normalization path next to the existing first() + normalize_offering_type() pattern. Since preferred selection is now part of parser behavior, consider centralizing that handling and using it consistently rather than only in _hit.
| path = source.get("object_detail_page_relative_url") | ||
| tiny_id = tiny_id_from_url(path) | ||
| offering_type = normalize_offering_type(first(source.get("offering_type"))) | ||
| offering_type = _offering_type(source.get("offering_type"), preferred_offering_type) |
There was a problem hiding this comment.
Threading preferred_offering_type from the client into the pure parser couples parsing to caller intent. If that context is required to choose between sale and rent fields, can we make it an explicit parser-level decision and apply it consistently through the parsed model? Right now it enters through _hit, but related metadata still follows the old first-offering path.
Summary
rent_pricefields forcategory="rent"results when Funda returns mixedkoophuurlistings with both sale and rent prices.Why
Funda can return listings whose
offering_typeis['buy', 'rent']for rental searches. Previously the parser selected the first offering type (buy) and therefore exposed the sale price (for example400000) even though the user searchedcategory="rent"and the raw payload also containedrent_price(for example2250).Verification
uv run python -m py_compile funda/*.py examples/*.py tests/*.pyuv run python -m unittest discover -s tests -vPYFUNDA_LIVE=1 uv run python -m unittest tests.test_live -vuv buildclient.search('amsterdam', category='rent', max_price=2500)[0]now returnsoffering_type == 'rent'andprice.amount == raw['_source']['price']['rent_price'][0].