package info.bukova.isspst.ui.search;

import info.bukova.isspst.UrlResolverHolder;
import info.bukova.isspst.services.fulltext.FullTextService;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.select.annotation.WireVariable;

import java.util.List;

public class SearchForm {
	
	@WireVariable
	private FullTextService fulltextService;
	@WireVariable
	private UrlResolverHolder urlResolverHolder;
	private List<SearchResult> results;
	
	private String keyWord;
	
	public void init() {
		
	}
	
	@Command
	@NotifyChange("results")
	public void doSearch() {
		if (keyWord == null || keyWord.isEmpty()) {
			return;
		}
		
		List<?> result = fulltextService.globalSearch(keyWord);
		
		SearchListTransformer srt = new SearchListTransformer(urlResolverHolder);
		results = srt.transform(result);
		
		System.out.println(result.size());
	}

	public String getKeyWord() {
		return keyWord;
	}

	public void setKeyWord(String keyWord) {
		this.keyWord = keyWord;
	}

	public List<SearchResult> getResults() {
		return results;
	}

}
