IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

[HibernateSearch] FullTextFilter - ajout parametre au filtre?


Sujet :

Hibernate Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2007
    Messages
    500
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Avril 2007
    Messages : 500
    Par défaut [HibernateSearch] FullTextFilter - ajout parametre au filtre?
    Bonjour, j'ai actuellement le filtre / code suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    	@Transactional(propagation = Propagation.REQUIRED)
    	public List<IJob> getJobListForZipCode(long functionId, long parution, String filter, String[] typeId, String zipCode, String typeZoom) {
     
     
    		List<IJob> jobs = new ArrayList<IJob>();
    		List<IJob> tempJobs = null;
    		long today = new Date().getTime();
     
    		FullTextEntityManager fem = Search.getFullTextEntityManager(em);
    		Analyzer analyzer = fem.getSearchFactory().getAnalyzer(
    				SOLR_JOB_ANALYZER_NAME);
    		MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[] {
    				"name", "description" }, analyzer);
     
    		DecimalFormat nfId = new DecimalFormat("000", DecimalFormatSymbols
    				.getInstance(Locale.US));
     
    		if (filter != null && !"".equals(filter.trim())
    				&& (!filter.startsWith("ent:"))) {
    			try {
     
    				parser.setAllowLeadingWildcard(true);
    				// Lucene parser don't want this char
    				if (filter != null) {
    					filter = filter.replace(':', ' ').trim();
    					filter = filter.replace('^', ' ').trim();
    				}
     
    				Query query = parser.parse(StringUtils.convertNonAscii(filter));
    				FullTextQuery hibQuery = fem.createFullTextQuery(query,
    						JobEntity.class);			
     
    					for(int d=0 ; d < typeId.length ; d++ ){
     
    						hibQuery.enableFullTextFilter("JobEntity.filter.geoZipCode")
    						.setParameter("publicationDelay", parution)
    						.setParameter("functionId", nfId.format(functionId));
    						//.setParameter("typeId", nfId.format(Long.parseLong(typeId[d])))				
    						//.setParameter("zipCode", zipCode);
     
    									tempJobs = (List<IJob>) hibQuery.getResultList();
     
    					}
     
    				List<Long> companyIdWithoutSubscriptionList = em
    						.createQuery(
    								"select distinct c.id from CompanyEntity c "
    										+ "where (c.id in (select s.company.id from SubscriptionEntity s "
    										+ "where s.startDate <= " + today
    										+ " and " + today + " <= s.endDate)) ")
    						.getResultList();
     
    				Map<Long, Object> companyIdWithoutSubscriptionMap = returnCompanyIdWithoutSubscription(companyIdWithoutSubscriptionList);
    				Iterator it = tempJobs.iterator();
    				while (it.hasNext()) {
    					IJob tempJob = (IJob) it.next();
    					if (companyIdWithoutSubscriptionMap
    							.containsKey((Long) tempJob.getCompany().getId())) {
     
    								jobs.add(tempJob);
     
    					}
    				}
     
    			} catch (ParseException e) {
    				e.printStackTrace();
    				jobs = new ArrayList<IJob>();
    			}
    		}
    	return jobs;
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     
     
            long functionId = computeFunctionIdParameters(request);
            long parution = computeParutionParameter(request);       
            String filter = computeFilterParameter(request);
            String[] typeId = computeTypeIdParameter(request);
            String[] zipCode = zipCodeParameter(request);
            String typeZoom = "";
     
            putZoomParameterInSession(request);
     
            WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext());  
            facade =(IBusinessClientFacade)springContext.getBean("facade");  
     
            List<List<IJob>> jobs = new ArrayList<List<IJob>>();
            if(zipCode.length < 23){
            	typeZoom = "Region";
            }
            else{
            	typeZoom = "Departement";
            }
     
        	if (filter != null && !"".equals(filter.trim())	&& (!filter.startsWith("ent:"))) {
    			jobs.add(facade.getJobListForZipCode(functionId, parution, filter, typeId, zipCode[0],typeZoom));
    		}
    		else{
    	        for(int i = 0, l = zipCode.length; i < l; i++){
     
    				jobs.add(facade.getJobListForZipCode(functionId, parution, filter, typeId, zipCode[i],typeZoom));
     
    			}
    		}
     
    		response.setContentType("application/json");
    		response.setCharacterEncoding("UTF-8");
    		PrintWriter pw = response.getWriter();
     
            pw.print(JSONUtils.JSONJobs(zipCode,jobs));
            pw.close();
    		response.flushBuffer(); 
     
    	}
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    public class GeoZipFilter  {
     
     
        private long publicationDelay;
        private String functionId;
        private String typeId;
        private String zipCode;
     
     
        @Key
        public FilterKey getKey() {
            StandardFilterKey key = new StandardFilterKey();
     
            key.addParameter(publicationDelay);
            key.addParameter(functionId);
            key.addParameter(typeId);
            key.addParameter(zipCode);
            return key;
        }
     
        @Factory
        public Filter getFilter() {
     
            ChainedFilter filter = new ChainedFilter() {
                /**
                 * 
                 */
                private static final long serialVersionUID = 8725514094671660409L;
     
                public BitSet bits(IndexReader reader) throws IOException {
                    return super.bits(reader);
                }
            };
     
            filter.addFilter(new RangeFilter("publicationDate", String.valueOf(System.currentTimeMillis()-publicationDelay) , String.valueOf(System.currentTimeMillis()), true, true));
            if (!functionId.equals("000")) {
            	filter.addFilter(new RangeFilter("functionId", functionId, functionId, true, true));				
    		}
    /*       
            if (!typeId.equals("000")) {
            	filter.addFilter(new RangeFilter("typeId", typeId, typeId, true, true));				
    		}
            
            if (!zipCode.equals("000")){
            	filter.addFilter(new RangeFilter("workAddress.zipCode", zipCode+"000" , zipCode+"999" , true, false));
            }
     */       
            filter.addFilter(new RangeFilter("archivingDate","0","0",true,true));
     
            return new CachingWrapperFilter(filter) {
     
                private static final long serialVersionUID = 4491361196544402881L;
     
                @SuppressWarnings("deprecation")
    			public BitSet bits(IndexReader reader) throws IOException {
                    return super.bits(reader);
                }
            };
        }
    Ce code / filtre existait deja avant, mais sans les parametres TypeId et ZipCode, et je tente donc de le modifier afin qu'il prenne en compte ces parametres , ce que , jusqu'a present je n'arrive pas à faire.
    Là ils sont commentés , mais si je les active dans mon code, le resultat de ma requete est null

    SI par hasard, une bonne âme connaissant le FullTextSearch passait par là :p


    merci.

  2. #2
    Membre éclairé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2007
    Messages
    500
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Avril 2007
    Messages : 500
    Par défaut
    je rajoute aussi mes deux classes utilisées pour la recherche :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    @AnalyzerDefs( { @AnalyzerDef(name = "jobAnalyzer", tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class), filters = {
            @TokenFilterDef(factory = ISOLatin1AccentFilterFactory.class),
            @TokenFilterDef(factory = LowerCaseFilterFactory.class),
            @TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = { @Parameter(name = "language", value = "French") }) }) })
    @FullTextFilterDefs( {
            @FullTextFilterDef(name = "JobEntity.filter.geoCode", impl = GeoFilter.class, cache = FilterCacheModeType.NONE),
            @FullTextFilterDef(name = "JobEntity.filter.geoZipCode", impl = GeoZipFilter.class, cache = FilterCacheModeType.NONE),
            @FullTextFilterDef(name = "JobEntity.filter.toPurge", impl = PurgeFilter.class, cache = FilterCacheModeType.NONE),
            @FullTextFilterDef(name = "JobEntity.filter.criteriaCode", impl = CriteriaFilter.class, cache = FilterCacheModeType.NONE),
            @FullTextFilterDef(name = "JobEntity.filter.telesiteCriteriaCode", impl = TelesiteCriteriaFilter.class, cache = FilterCacheModeType.NONE) })
    @Entity
    @Indexed(index = "indexes/job")
    @Table(name = "job")
    @Analyzer(definition = "jobAnalyzer")
    public class JobEntity implements IJob, Serializable {
     
        // ========================================================================
        // Instances variables
        // ========================================================================
     
        /**
         * 
         */
        private static final long serialVersionUID = -1496587007336871708L;
     
        @Id
        @DocumentId
        @GeneratedValue(strategy = GenerationType.AUTO)
        private long id;
     
        @Fields( { @Field(index = Index.UN_TOKENIZED, name = "sortByName"),
                @Field(index = Index.TOKENIZED) })
        @Column(length = 250)
        @Boost(2)
        // @FieldBridge(impl=StringSeparatorBridge.class)
        private String name;
     
        @Field(index = Index.TOKENIZED)
        @Column(length = 25000)
        // @FieldBridge(impl=StringSeparatorBridge.class)
        private String description;
     
        // Functions are precreated so CascadeType.PERSIST is rather useless.
        // It could have been here for the beauty of the work, but who cares for the
        // beauty ...
     
        @ManyToOne(targetEntity = FunctionEntity.class, fetch = FetchType.EAGER)
        private IFunction function;
     
        @OneToOne(optional = true, targetEntity = BasicAddressEntity.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
        private IBasicAddress address;
     
        @OneToOne(optional = true, targetEntity = AddressEntity.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
        private IAddress workAddress;
     
        @ManyToOne(targetEntity = CompanyEntity.class, fetch = FetchType.EAGER)
        private ICompany company;
     
        private String reference;
     
        private long creationDate;
     
        private long modificationDate;
     
        @Field(index = Index.UN_TOKENIZED)
        private long publicationDate;
     
        private Double latitude;
     
        private Double longitude;
     
        @Field(index = Index.UN_TOKENIZED, name = "latitude")
        @Transient
        private String latitudeStr;
     
        @Field(index = Index.UN_TOKENIZED, name = "longitude")
        @Transient
        private String longitudeStr;
     
        @Field(index = Index.UN_TOKENIZED, name = "functionId")
        @Transient
        private String functionId;
     
        @Field(index = Index.UN_TOKENIZED, name = "companyName")
        // @FieldBridge(impl=StringSeparatorBridge.class)
        @Transient
        private String companyName;
     
        @OneToMany(targetEntity = AnswerEntity.class, mappedBy = "job", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
        private Set<IAnswer> answerList;
     
        @Field(index = Index.UN_TOKENIZED)
        private long archivingDate;
     
        private String contactMail;
     
        private String phone;
     
        // /
        @ManyToOne(targetEntity = TypeEntity.class, fetch = FetchType.EAGER)
        private IType type;
     
        @Field(index = Index.UN_TOKENIZED, name = "typeId")
        @Transient
        private String typeId;
     
        /**
         * In order to candidate on an other site. When a jod is added : Email or
         * URL not Email and URL
         */
        private String url;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    @Entity
    @Indexed
    @Table(name = "address")
    public class AddressEntity extends BasicAddressEntity implements IAddress , Serializable{
     
        // ========================================================================
        // Instances variables
        // ========================================================================
     
        /**
         * 
         */
        private static final long serialVersionUID = 708555024557782807L;
     
        @Field(index = Index.UN_TOKENIZED, store = Store.NO)
        private String region;

Discussions similaires

  1. VBA Problème ajout de commentaires + filtre auto
    Par Contrec dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 23/02/2009, 08h56
  2. Réponses: 1
    Dernier message: 29/10/2008, 16h42
  3. Ajout parametre dans select
    Par Shandler dans le forum Général JavaScript
    Réponses: 15
    Dernier message: 07/05/2008, 10h14
  4. Réponses: 1
    Dernier message: 23/04/2008, 11h39
  5. Réponses: 0
    Dernier message: 27/03/2008, 10h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo