package org.neo4j.tutor.search;

import java.util.Collections;
import org.neo4j.api.core.EmbeddedNeo;
import org.neo4j.api.core.Node;
import org.neo4j.api.core.RelationshipType;

public class SearchEngine extends AbstractSearchEngine
{
	private static final RelationshipType HAS_KEYWORD = 
		MyRelationshipTypes.HAS_KEYWORD;
	private static final RelationshipType TRANSLATION = 
		MyRelationshipTypes.TRANSLATION;
	
	public SearchEngine( EmbeddedNeo neo )
	{
		super( neo );
	}
	
	/**
	 * Returns all document nodes connected to a keyword or a translation of
	 * that keyword. If keyword doesn't exist an empty iterable will return.
	 * 
	 * @param language the language of the keyword
	 * @param keyword the value of the keyword
	 * @return documents connected to the keyword (including translations) 
	 */
	public Iterable<Node> searchDocuments( String language, String keyword )
	{
		// get keyword node where we will start the the traversal
		Node keywordNode = getKeywordNode( language, keyword );
		if ( keywordNode == null )
		{
			System.out.println( "Keyword not found" );
			return Collections.emptyList();
		}
		// --- TODO 
		// --- Find all documents that has keyword connected to it and 
		// --- all documents connected to other languages that keyword 
		// --- translates to
		// --- Do this by creating a traverser from the keywordNode and traverse
		// --- the TRANSLATION and HAS_KEYWORD relationships.
		// --- Use DEPTH_FIRST traversal, HAS_KEYWORD should be INCOMING 
		// --- direction but TRANSLATION should be traversed in BOTH directions
		// --- You need to write a Returnable evaluator simular to the one 
		// --- in the matrix example where we only return nodes when last
		// --- relationship traversed is of type HAS_KEYWORD

		// return keywordNode.traverse( ... );
		return null;
	}
}
