Code Search for Developers
 
 
  

SearchCommand.java from Kneobase at Krugle


Show SearchCommand.java syntax highlighted

/*
 * Created on 24/06/2004
 *
 */
package com.kneobase.web.search;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.Vector;

import com.kneobase.KneobaseException;
import com.kneobase.search.query.HighlighterConfiguration;
import com.kneobase.search.query.Hits;

/**
 * @author Ernesto De Santis
 *
 */
public class SearchCommand {
    
    private String userInput;
	private String mimetype;
    private String field;
    private String source;
    private String query;
    private Exception error;
    private String language;
    
    private Hits hits;
    private Collection sources;
    private Collection fields;
    private Collection languages;
    private Collection mimetypes;

	private HighlighterConfiguration highlighterConfiguration;

    /**
     * @param hits
     */
    public void setHits(Hits hits) {
        this.hits = hits;
    }
    
    public int getHitsLength(){
        return hits.length();
    }
    
    public Iterator getHitsIterator(){
        HitsIterator itHits = new HitsIterator(hits);
        itHits.setHighlighterConfiguration(getHighlighterConfiguration());
		return itHits;
    }

    /**
     * @return
     */
    public String getUserInput() {
        return userInput;
    }

    /**
     * @param string
     */
    public void setUserInput(String string) {
        userInput = string;
    }

    /**
     * @return
     */
    public Exception getError() {
        return error;
    }

    /**
     * @return
     */
    public String getQuery() {
        return query;
    }

    /**
     * @param e
     */
    public void setError(Exception e) {
        error = e;
    }

    /**
     * @param string
     */
    public void setQuery(String string) {
        query = string;
    }

    /**
     * @return
     */
    public Hits getHits() {
        return hits;
    }

    /**
     * @return
     */
    public Collection getSources() {
        return sources;
    }

    /**
     * @param set
     */
    public void setSources(Set set) {
		List aux = new Vector(set); 
		Collections.sort(aux);
        sources = aux;
    }

    /**
     * @return
     */
    public Collection getFields() {
        return fields;
    }

    /**
     * @param collection
     */
    public void setFields(Collection collection) {
        fields = collection;
    }

    /**
     * @return
     */
    public String getField() {
        return field;
    }

    /**
     * @return
     */
    public String getSource() {
        return source;
    }

    /**
     * @param string
     */
    public void setField(String string) {
        field = string;
    }

    /**
     * @param string
     */
    public void setSource(String string) {
        source = string;
    }

	/**
	 * @return
	 */
	public String getLanguage() {
		return language;
	}

	/**
	 * @return
	 */
	public Collection getLanguages() {
		return languages;
	}

	/**
	 * @param string
	 */
	public void setLanguage(String string) {
		language = string;
	}

	/**
	 * @param collection
	 */
	public void setLanguages(Collection collection) {
		languages = collection;
	}

    /**
     * @return
     */
    public Collection getMimetypes() {
        return mimetypes;
    }

    /**
     * @param collection
     */
    public void setMimetypes(Collection collection) {
        mimetypes = collection;
    }

    /**
     * @return
     */
    public String getMimetype() {
        return mimetype;
    }

    /**
     * @param string
     */
    public void setMimetype(String string) {
        mimetype = string;
    }

	/**
	 * @return
	 */
	public HighlighterConfiguration getHighlighterConfiguration() {
		return highlighterConfiguration;
	}

	/**
	 * @param configuration
	 */
	public void setHighlighterConfiguration(HighlighterConfiguration configuration) {
		highlighterConfiguration = configuration;
	}

}

/**
 * Package class
 */
class HitsIterator implements Iterator{

    private Hits hits;
    private int offset;
    private int maxHits = 30;
	private HighlighterConfiguration hlc;
    
    HitsIterator(Hits h){
        hits=h;
        offset=0;
    }

    HitsIterator(Hits h, int maxHits){
        hits=h;
        offset=0;
        this.maxHits = maxHits;
    }
    
    public boolean hasNext() {
        return offset < hits.length() && offset < maxHits;
    }

    public Object next() {
        try {
            if (offset < maxHits) {
                String highlight;
                if (hlc != null)
                    highlight =
                        hits.getHighLightedText(
                            offset,
                            hlc.getFieldToHighlight(),
                            hlc.getMaxNumFragmentsRequired(),
                            hlc.getFragmentSize(),
                            hlc.getTextBetweenFragments(),
                            hlc.getFormatter());
                else
                    highlight =
                        hits.getHighLightedText(
                            offset,
                            HighlighterConfiguration.DEFAULT_FIELD_TO_HIGHLIGHT);

                return new DocBean(hits.get(offset++), highlight);
            } else
                return null;
        } catch (IOException e) {
            //TODO log
            return null;
        } catch (KneobaseException e) {
            //TODO log
            return null;
        }
    }

    //not implemented.
    public void remove() {
    }
    
	/**
	 * @return
	 */
	public HighlighterConfiguration getHighlighterConfiguration() {
		return hlc;
	}

	/**
	 * @param configuration
	 */
	public void setHighlighterConfiguration(HighlighterConfiguration configuration) {
		hlc = configuration;
	}

}





See more files for this project here

Kneobase

Kneobase is an enterprise search engine, based upon the Lucene search engine and the Spring framework. It allows to perform full-text search across many different content sources. It is highly adaptable out-of-the-box and has a pluggable architecture.

Project homepage: http://sourceforge.net/projects/kneobase
Programming language(s): Java,XML
License: other

  DocBean.java
  SearchCommand.java
  SearchController.java