Autocomplete con findText

Crear el índice

if(aulasFacade.createIndex(new Document("idaula","text"))){
           System.out.println("creo el indice");
       }else{
           System.out.println("no creo el indice");
       }

Crear el Services

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.avbravo.ejbsiu.services;

import com.avbravo.avbravoutils.JsfUtil;
import com.avbravo.ejbsiu.ejb.AulasFacade;
import com.avbravo.ejbsiu.entity.Aulas;
import java.time.LocalTime;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import org.bson.Document;

/**
 *
 * @author avbravo
 */
@Stateless
public class AulasServices {
    @Inject
    AulasFacade aulasFacade;

    public static LocalTime getHour(){

       return LocalTime.now();
    }

    public List<Aulas> complete(String query) {
        List<Aulas> suggestions = new ArrayList<>();

        try {
            query = query.trim();
            if (query.length() < 1) {
                return suggestions;
            }

            suggestions = aulasRepository.findText("idaula",  query,new Document("idaula",1));

        } catch (Exception e) {
            JsfUtil.errorMessage("complete() " + e.getLocalizedMessage());
        }

        return suggestions;
    }


}

En el Controller

En la página xhtml

Last updated

Was this helpful?