use of org.entando.entando.aps.system.services.searchengine.SearchEngineFilter in project entando-core by entando.
the class TestSearchEngineManager method testSearchAllContents.
public void testSearchAllContents() throws Throwable {
try {
Thread thread = this.dataObjectSearchEngineManager.startReloadDataObjectsReferences();
thread.join();
Set<String> allowedGroup = new HashSet<String>();
SearchEngineFilter[] filters = {};
SearchEngineManager sem = (SearchEngineManager) this.dataObjectSearchEngineManager;
List<String> freeContentsId = sem.searchEntityId(filters, null, allowedGroup);
assertNotNull(freeContentsId);
allowedGroup.add(Group.ADMINS_GROUP_NAME);
List<String> allContentsId = sem.searchEntityId(filters, null, allowedGroup);
assertNotNull(allContentsId);
assertTrue(allContentsId.size() > freeContentsId.size());
} catch (Throwable t) {
throw t;
}
}
use of org.entando.entando.aps.system.services.searchengine.SearchEngineFilter in project entando-core by entando.
the class TestSearchEngineManager method testFacetedAllContents.
public void testFacetedAllContents() throws Throwable {
try {
Thread thread = this.dataObjectSearchEngineManager.startReloadDataObjectsReferences();
thread.join();
SearchEngineManager sem = (SearchEngineManager) this.dataObjectSearchEngineManager;
Set<String> allowedGroup = new HashSet<String>();
allowedGroup.add(Group.ADMINS_GROUP_NAME);
SearchEngineFilter[] filters = {};
FacetedContentsResult result = sem.searchFacetedEntities(filters, null, allowedGroup);
assertNotNull(result);
assertNotNull(result.getContentsId());
assertNotNull(result.getOccurrences());
assertTrue(result.getContentsId().size() > 0);
assertTrue(result.getOccurrences().size() > 0);
} catch (Throwable t) {
throw t;
}
}
use of org.entando.entando.aps.system.services.searchengine.SearchEngineFilter in project entando-core by entando.
the class SearchEngineManager method searchEntityId.
@Override
public List<String> searchEntityId(String langCode, String word, Collection<String> allowedGroups) throws ApsSystemException {
SearchEngineFilter[] filters = new SearchEngineFilter[0];
if (StringUtils.isNotEmpty(langCode) && StringUtils.isNotEmpty(word)) {
SearchEngineFilter filter = new SearchEngineFilter(langCode, word);
filter.setIncludeAttachments(true);
filters = this.addFilter(filters, filter);
}
return this.searchEntityId(filters, null, allowedGroups);
}
use of org.entando.entando.aps.system.services.searchengine.SearchEngineFilter in project entando-core by entando.
the class SearcherDAO method createQuery.
protected Query createQuery(SearchEngineFilter[] filters, Collection<ITreeNode> categories, Collection<String> allowedGroups) {
BooleanQuery mainQuery = new BooleanQuery();
if (filters != null && filters.length > 0) {
for (int i = 0; i < filters.length; i++) {
SearchEngineFilter filter = filters[i];
Query fieldQuery = this.createQuery(filter);
mainQuery.add(fieldQuery, BooleanClause.Occur.MUST);
}
}
if (allowedGroups == null) {
allowedGroups = new HashSet<String>();
}
if (!allowedGroups.contains(Group.ADMINS_GROUP_NAME)) {
if (!allowedGroups.contains(Group.FREE_GROUP_NAME)) {
allowedGroups.add(Group.FREE_GROUP_NAME);
}
BooleanQuery groupsQuery = new BooleanQuery();
Iterator<String> iterGroups = allowedGroups.iterator();
while (iterGroups.hasNext()) {
String group = iterGroups.next();
TermQuery groupQuery = new TermQuery(new Term(IIndexerDAO.CONTENT_GROUP_FIELD_NAME, group));
groupsQuery.add(groupQuery, BooleanClause.Occur.SHOULD);
}
mainQuery.add(groupsQuery, BooleanClause.Occur.MUST);
}
if (null != categories && !categories.isEmpty()) {
BooleanQuery categoriesQuery = new BooleanQuery();
Iterator<ITreeNode> cateIter = categories.iterator();
while (cateIter.hasNext()) {
ITreeNode category = cateIter.next();
String path = category.getPath(IIndexerDAO.CONTENT_CATEGORY_SEPARATOR, false);
TermQuery categoryQuery = new TermQuery(new Term(IIndexerDAO.CONTENT_CATEGORY_FIELD_NAME, path));
categoriesQuery.add(categoryQuery, BooleanClause.Occur.MUST);
}
mainQuery.add(categoriesQuery, BooleanClause.Occur.MUST);
}
return mainQuery;
}
use of org.entando.entando.aps.system.services.searchengine.SearchEngineFilter in project entando-core by entando.
the class UserFilterOptionBean method extractFilter.
public SearchEngineFilter extractFilter() {
if (null == this.getFormFieldValues()) {
return null;
}
SearchEngineFilter filter = null;
String value0 = this.getFormValue(0);
String value1 = this.getFormValue(1);
if (!this.isAttributeFilter()) {
if (this.getKey().equals(KEY_FULLTEXT) && !StringUtils.isEmpty(value0)) {
// String[] fieldsSuffix = {"", "_option"};
filter = new SearchEngineFilter(this.getCurrentLang().getCode(), value0, this.getOption(value1));
String attachOption = this.getFormValue(2);
try {
filter.setIncludeAttachments(Boolean.parseBoolean(attachOption));
} catch (Exception e) {
}
} else if (this.getKey().equals(KEY_CATEGORY) && !StringUtils.isEmpty(value0)) {
filter = new SearchEngineFilter(IIndexerDAO.CONTENT_CATEGORY_FIELD_NAME, value0, SearchEngineFilter.TextSearchOption.EXACT);
}
} else {
AttributeInterface attribute = this.getAttribute();
if (attribute instanceof ITextAttribute && !StringUtils.isEmpty(value0)) {
filter = new SearchEngineFilter(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
// String[] fieldsSuffix = {"_textFieldName"};
} else if (attribute instanceof DateAttribute && (!StringUtils.isEmpty(value0) || !StringUtils.isEmpty(value1))) {
Date big0 = null;
try {
big0 = DateConverter.parseDate(value0, this.getDateFormat());
} catch (Exception e) {
}
Date big1 = null;
try {
big1 = DateConverter.parseDate(value1, this.getDateFormat());
} catch (Exception e) {
}
// String[] fieldsSuffix = {"_dateStartFieldName", "_dateEndFieldName"};
filter = new SearchEngineFilter(this.getIndexFieldName(), big0, big1);
} else if (attribute instanceof BooleanAttribute && (!StringUtils.isEmpty(value0) && !StringUtils.isEmpty(value1))) {
filter = new SearchEngineFilter(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
// String[] fieldsSuffix = {"_booleanFieldName", "_booleanFieldName_ignore", "_booleanFieldName_control"};
} else if (attribute instanceof NumberAttribute && (!StringUtils.isEmpty(value0) || !StringUtils.isEmpty(value1))) {
// String[] fieldsSuffix = {"_numberStartFieldName", "_numberEndFieldName"};
BigDecimal big0 = null;
try {
big0 = new BigDecimal(value0);
} catch (Exception e) {
}
BigDecimal big1 = null;
try {
big1 = new BigDecimal(value1);
} catch (Exception e) {
}
filter = new SearchEngineFilter(this.getIndexFieldName(), big0, big1);
}
}
return filter;
}
Aggregations