/ucengine/src/backends/search/erlang/uce_event_erlang_search.erl
Erlang | 67 lines | 41 code | 8 blank | 18 comment | 0 complexity | 4cc85ff4e98ce27d4dfeda829d02faa6 MD5 | raw file
1%% 2%% U.C.Engine - Unified Collaboration Engine 3%% Copyright (C) 2011 af83 4%% 5%% This program is free software: you can redistribute it and/or modify 6%% it under the terms of the GNU Affero General Public License as published by 7%% the Free Software Foundation, either version 3 of the License, or 8%% (at your option) any later version. 9%% 10%% This program is distributed in the hope that it will be useful, 11%% but WITHOUT ANY WARRANTY; without even the implied warranty of 12%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13%% GNU Affero General Public License for more details. 14%% 15%% You should have received a copy of the GNU Affero General Public License 16%% along with this program. If not, see <http://www.gnu.org/licenses/>. 17%% 18-module(uce_event_erlang_search). 19 20-export([add/2, list/11, search_metadata/2]). 21 22-include("uce.hrl"). 23 24%% It is not needed to index something here 25add(_, _) -> 26 {ok, created}. 27 28search_value(_, []) -> 29 true; 30search_value(Value, [Word|Words]) -> 31 case string:str(Value, Word) of 32 0 -> 33 false; 34 _ -> 35 search_value(Value, Words) 36 end. 37 38search_metadata([], _) -> 39 false; 40search_metadata({struct, Values}, Words) -> 41 search_metadata(Values, Words); 42search_metadata({array, Values}, Words) -> 43 search_metadata(Values, Words); 44search_metadata([{_, Value}|Tail], Words) when is_list(Value) -> 45 case search_value(Value, Words) of 46 true -> 47 true; 48 false -> 49 search_metadata(Tail, Words) 50 end; 51search_metadata(_, _Words) -> 52 false. 53 54filter(Events, []) -> 55 Events; 56filter(Events, Words) -> 57 lists:filter(fun(#uce_event{metadata=Metadata}) -> 58 search_metadata(Metadata, Words) 59 end, 60 Events). 61 62list(Domain, Location, Search, From, Type, DateStart, DateEnd, Parent, Start, Max, Order) -> 63 {ok, Events} = (db:get(uce_event, Domain)):list(Domain, Location, From, Type, DateStart, DateEnd, Parent, Order), 64 65 FilteredEvents = filter(Events, Search), 66 EventPage = uce_paginate:paginate(FilteredEvents, Start, Max), 67 {ok, length(FilteredEvents), EventPage}.