Package it.unimi.dsi.mg4j.query.nodes

Source Code of it.unimi.dsi.mg4j.query.nodes.AbstractTermExpanderTest

package it.unimi.dsi.mg4j.query.nodes;

import it.unimi.dsi.mg4j.query.parser.QueryParserException;
import it.unimi.dsi.mg4j.query.parser.SimpleParser;
import junit.framework.TestCase;


public class AbstractTermExpanderTest extends TestCase {

  public void testExpand() throws QueryParserException {
    QueryTransformer addAqueryTransformer = new AbstractTermExpander() {
      @Override
      public Query expand( Term term ) {
        return new Term( "a" + term.term );
      }

      @Override
      public Query expand( Prefix prefix ) {
        return prefix;
      }
    };
   
    Query query = new SimpleParser().parse( "foo AND bar" );
    assertEquals( new And( new Term( "afoo"), new Term( "abar") ), addAqueryTransformer.transform( query ) );

    QueryTransformer expandQueryTransformer = new AbstractTermExpander() {
      /** The visitor used by this expander. */
      @Override
      public Query expand( Term term ) {
        return new MultiTerm( term, new Term( "a" + term.term ) );
      }

      @Override
      public Query expand( Prefix prefix ) {
        return prefix;
      }
    };
   
    assertEquals( new And( new MultiTerm( new Term( "foo" ), new Term( "afoo" ) ), new MultiTerm( new Term( "bar" ), new Term( "abar") ) ), expandQueryTransformer.transform( query ) );
  }
}
TOP

Related Classes of it.unimi.dsi.mg4j.query.nodes.AbstractTermExpanderTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.