1 Reply Latest reply on May 30, 2011 7:41 PM by Tim Evers

    FullTextEntityManager

    scope_talka Newbie

      Could someone help me with this code. I keep getting the following error - @In attribute requires non-null value: userSearchDao.fem



      @Name( "userDao" )
      @Scope( ScopeType.STATELESS )
      @AutoCreate
      public class UserDAO {
              
              private final EntityManager em;
              @In FullTextEntityManager fem;
              
              public UserDAO() {
                      em = ( EntityManager )Component.getInstance( "entityManager", true );
              }
              
              @SuppressWarnings( "unchecked" )
              public List<User> searchUsers( final String text ) {
                      final Query query;
                      
                      try {
                              FullTextEntityManager fem = Search.getFullTextEntityManager( em );
                  query = fem.createFullTextQuery( getLuceneQuery( text ), User.class );
                  return query.getResultList();
              } catch ( ParseException ex ) {
                  log.error( "search error", ex );
                  return null;
              }
              }
              
              private org.apache.lucene.search.Query getLuceneQuery( final String queryString ) throws ParseException {
                      try {
                          Map<String, Float> boostPerField = new HashMap<String, Float>( 2 );
                          boostPerField.put( "subject", (float) 4 );
                          boostPerField.put( "description", (float) 1 );
                          String[] searchFields = { "subject", "description" };
                          QueryParser parser = new MultiFieldQueryParser( Version.LUCENE_31, searchFields, new StandardAnalyzer( Version.LUCENE_31 ), boostPerField );
                          parser.setDefaultOperator( QueryParser.Operator.OR );
                          org.apache.lucene.search.Query luceneQuery = null;
                          luceneQuery = parser.parse( queryString );
                          return luceneQuery;
                      } catch ( ParseException ex ) {
                      return null;
                  }
         }    
      }