Skip to content

Instantly share code, notes, and snippets.

@SergioLarios
Last active October 10, 2016 08:16
Show Gist options
  • Save SergioLarios/01728338b5b6ff4e19d3d12ca67f184f to your computer and use it in GitHub Desktop.
Save SergioLarios/01728338b5b6ff4e19d3d12ca67f184f to your computer and use it in GitHub Desktop.
// Metadata
SearchParams sp = new SearchParams(companyId, groupId, locale, userId, start, end);
SearchParams sp = SearchUtils.generateSc(sp); // Generamos el search context que necesitamos para crear querys
// Query string
sp.setQuery(inputQuery); // String
// Temas
if (areasInteresCatIds.size() > 0) {
sp.setCategoyList(areasInteresCatIds); // Listado de longs
}
// Query profesroes
if (Validator.isNotBlank(professorName)) {
List<AssetCategory> professors = searchCategoriesByName(companyId, groupId, Arrays.asList(professorVocaId),
locale, professorName);
List<BooleanQuery> professorsBq = new ArrayList<>();
BooleanQuery professorsMainBq = BooleanQueryFactoryUtil.create(sp.getSearchContext());
for (AssetCategory professorCat : professors) {
BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(sp.getSearchContext());
booleanQuery.addTerm("assetCategoryIds", professorCat.getCategoryId());
professorsBq.add(booleanQuery);
}
for (BooleanQuery booleanQuery : professorsBq) {
professorsMainBq.add(booleanQuery, BooleanClauseOccur.SHOULD); // De esta manera definimos que puede ser cualqueira de las categorias
}
sp.appendBq(professorsMainBq);
}
// tipolgias
sp.setStrcIds(strcIds) // Listado de longs con los structure ids que se quieren buscar
// Ciudad
if (Validator.isNotBlank(cityName)) {
BooleanQuery cityMainBq = BooleanQueryFactoryUtil.create(sp.getSearchContext());
String evStructureFieldName = DDMIndexerUtil.encodeName(eventoStructureId, "ciudad",
prms.getLocale());
BooleanQuery booleanQueryEv = BooleanQueryFactoryUtil.create(sp.getSearchContext());
booleanQueryEv.addTerm(evStructureFieldName, cityName, false);
String confStructureFieldName = DDMIndexerUtil.encodeName(confStructureId, "lugar",
prms.getLocale());
BooleanQuery booleanQueryConf = BooleanQueryFactoryUtil.create(sp.getSearchContext());
booleanQueryConf.addTerm(confStructureFieldName, cityName, false);
cityMainBq.add(booleanQueryEv, BooleanClauseOccur.SHOULD);
cityMainBq.add(booleanQueryConf, BooleanClauseOccur.SHOULD);
sp.appendBq(cityMainBq);
}
// Rango de fechas
if (hasDatesFilter) {
BooleanQuery datesMainBq = BooleanQueryFactoryUtil.create(sp.getSearchContext());
long startValue = dateFrom; // long representando un Date del inicio del rango
long endValue = dateTo;// long representando un Date del fin del rango
String evStructureFieldName = DDMIndexerUtil.encodeName(eventoStructureId, "fecha",
prms.getLocale());
BooleanQuery booleanQueryEv = BooleanQueryFactoryUtil.create(sp.getSearchContext());
booleanQueryEv.addNumericRangeTerm(evStructureFieldName, startValue, endValue);
String confStructureFieldName = DDMIndexerUtil.encodeName(confStructureId, "fecha",
prms.getLocale());
BooleanQuery booleanQueryConf = BooleanQueryFactoryUtil.create(sp.getSearchContext());
booleanQueryConf.addNumericRangeTerm(confStructureFieldName, startValue, endValue);
String articleStructureFieldName = DDMIndexerUtil.encodeName(articleStructureId, "fecha",
prms.getLocale());
BooleanQuery booleanQueryarticle = BooleanQueryFactoryUtil.create(sp.getSearchContext());
booleanQueryarticle.addNumericRangeTerm(articleStructureFieldName, startValue, endValue);
datesMainBq.add(booleanQueryEv, BooleanClauseOccur.SHOULD);
datesMainBq.add(booleanQueryConf, BooleanClauseOccur.SHOULD);
datesMainBq.add(booleanQueryarticle, BooleanClauseOccur.SHOULD);
sp.appendBq(datesMainBq);
}
// Sort
Sort sort = null,
if (sortPortFecha) {
String structureFieldName = DDMIndexerUtil.
encodeName(structureId, fieldName, prms.getLocale());
sort = new Sort("", true); // El boolean es para hacer un reverse del sort
}
else {
sort = new Sort("viewCount", true);
}
sp.setSort(Arrays.asList(sort));
// Final call
SearchPagi results = SearchUtils.customSearch(sp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment