All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jaeksoft.searchlib.web.controller.query.SearchFieldsController Maven / Gradle / Ivy

Go to download

OpenSearchServer is a powerful, enterprise-class, search engine program. Using the web user interface, the crawlers (web, file, database, ...) and the REST/RESTFul API you will be able to integrate quickly and easily advanced full-text search capabilities in your application. OpenSearchServer runs on Windows and Linux/Unix/BSD.

The newest version!
/**   
 * License Agreement for OpenSearchServer
 *
 * Copyright (C) 2008-2012 Emmanuel Keller / Jaeksoft
 * 
 * http://www.open-search-server.com
 * 
 * This file is part of OpenSearchServer.
 *
 * OpenSearchServer is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 * OpenSearchServer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with OpenSearchServer. 
 *  If not, see .
 **/

package com.jaeksoft.searchlib.web.controller.query;

import java.util.ArrayList;
import java.util.List;

import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.bind.annotation.NotifyChange;

import com.jaeksoft.searchlib.Client;
import com.jaeksoft.searchlib.SearchLibException;
import com.jaeksoft.searchlib.request.RequestTypeEnum;
import com.jaeksoft.searchlib.request.SearchField;
import com.jaeksoft.searchlib.request.SearchFieldRequest;
import com.jaeksoft.searchlib.schema.Indexed;
import com.jaeksoft.searchlib.schema.SchemaField;
import com.jaeksoft.searchlib.webservice.query.search.SearchFieldQuery.SearchField.Mode;

public class SearchFieldsController extends AbstractQueryController {

	private transient String selectedSearchField;

	private transient List searchableFields;

	public SearchFieldsController() throws SearchLibException {
		super(RequestTypeEnum.SearchFieldRequest);
	}

	@Override
	protected void reset() throws SearchLibException {
		selectedSearchField = null;
		searchableFields = null;
	}

	public List getSearchableFields() throws SearchLibException {
		synchronized (this) {
			if (searchableFields != null)
				return searchableFields;
			Client client = getClient();
			if (client == null)
				return null;
			searchableFields = new ArrayList(0);
			for (SchemaField field : client.getSchema().getFieldList())
				if (field.checkIndexed(Indexed.YES))
					searchableFields.add(field.getName());
			return searchableFields;
		}
	}

	public void setSelectedSearchField(String value) {
		synchronized (this) {
			selectedSearchField = value;
		}
	}

	public String getSelectedSearchField() {
		synchronized (this) {
			return selectedSearchField;
		}
	}

	private SearchFieldRequest getSearchFieldRequest()
			throws SearchLibException {
		return (SearchFieldRequest) getRequest();
	}

	public Mode[] getSearchFieldModes() {
		return Mode.values();
	}

	@Command
	@NotifyChange("*")
	public void onSearchFieldAdd() throws SearchLibException {
		synchronized (this) {
			if (selectedSearchField == null)
				return;
			getSearchFieldRequest().add(
					new SearchField(selectedSearchField, Mode.PATTERN, 1.0,
							1.0, null, null));
		}
	}

	@Command
	@NotifyChange("*")
	public void onSearchFieldRemove(
			@BindingParam("searchfield") SearchField searchField)
			throws SearchLibException {
		synchronized (this) {
			getSearchFieldRequest().remove(searchField);
		}
	}

	@Override
	@GlobalCommand
	public void eventSchemaChange(Client client) throws SearchLibException {
		reset();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy