Skip to content
This repository
Browse code

Allow query_id to be a page with 'haspart' objects. Don't throw excep…

…tions on mismatch of categories (this allows a query to be inserted before the referred categories are inserted)

(cherry picked from commit f5c3d3b)
  • Loading branch information...
commit 5b0b29c3fde56b955993745e807206b0c72c6f52 1 parent 9a2892e
Marc Worrell mworrell authored arjan committed

Showing 1 changed file with 25 additions and 14 deletions. Show diff stats Hide diff stats

  1. +25 14 modules/mod_search/support/search_query.erl
39 modules/mod_search/support/search_query.erl
@@ -327,7 +327,8 @@ parse_query([{query_id, Id}|Rest], Context, Result) ->
327 327 Q = z_convert:to_list(m_rsc:p(Id, 'query', Context)),
328 328 parse_query(parse_query_text(Q) ++ Rest, Context, Result);
329 329 false ->
330   - throw({error, {invalid_query_id, Id}})
  330 + % Fetch the id's haspart objects (assume a collection)
  331 + parse_query([{hassubject, Id, haspart} | Rest], Context, Result)
331 332 end;
332 333
333 334 %% rsc_id=<rsc id>
@@ -520,26 +521,36 @@ assure_categories(Name, Context) ->
520 521 true -> [Name];
521 522 false -> Name
522 523 end,
523   - Cats1 = lists:filter(fun(C) -> not(C == undefined) andalso not(C == []) end, Cats),
524   - [ assure_category(C, Context) || C <- Cats1 ].
  524 + lists:foldl(fun(C, Acc) ->
  525 + case assure_category(C, Context) of
  526 + error -> Acc;
  527 + {ok, N} -> [N|Acc]
  528 + end
  529 + end,
  530 + [],
  531 + Cats).
525 532
526 533 %% Make sure the given name is a category.
  534 +assure_category([], _) -> error;
  535 +assure_category(<<>>, _) -> error;
  536 +assure_category(undefined, _) -> error;
527 537 assure_category(Name, Context) ->
528 538 case m_category:name_to_id(Name, Context) of
529 539 {ok, _Id} ->
530   - Name;
  540 + {ok, Name};
531 541 _ ->
532   - CatId = try
533   - z_convert:to_integer(Name)
534   - catch
535   - _:_ ->
536   - throw({error, {unknown_category, Name}})
537   - end,
538   - case m_category:id_to_name(CatId, Context) of
  542 + case m_rsc:rid(Name, Context) of
539 543 undefined ->
540   - throw({error, {unknown_category, Name}});
541   - Name1 ->
542   - Name1
  544 + lager:warning("Query: unknown category ~p", [Name]),
  545 + error;
  546 + CatId ->
  547 + case m_category:id_to_name(CatId, Context) of
  548 + undefined ->
  549 + lager:warning("Query: ~p is not a category", [CatId]),
  550 + error;
  551 + Name1 ->
  552 + {ok, Name1}
  553 + end
543 554 end
544 555 end.
545 556

0 comments on commit 5b0b29c

Please sign in to comment.
Something went wrong with that request. Please try again.