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;
}
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.DATAOBJECT_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.DATAOBJECT_CATEGORY_SEPARATOR, false);
TermQuery categoryQuery = new TermQuery(new Term(IIndexerDAO.DATAOBJECT_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 SearcherDAO method createQuery.
private Query createQuery(SearchEngineFilter filter) {
BooleanQuery fieldQuery = new BooleanQuery();
String key = filter.getKey();
Object value = filter.getValue();
if (null != value) {
if (value instanceof String) {
SearchEngineFilter.TextSearchOption option = filter.getTextSearchOption();
if (null == option) {
option = SearchEngineFilter.TextSearchOption.AT_LEAST_ONE_WORD;
}
String stringValue = value.toString();
String[] values = stringValue.split("\\s+");
if (!option.equals(SearchEngineFilter.TextSearchOption.EXACT)) {
BooleanClause.Occur bc = BooleanClause.Occur.SHOULD;
if (option.equals(SearchEngineFilter.TextSearchOption.ALL_WORDS)) {
bc = BooleanClause.Occur.MUST;
} else if (option.equals(SearchEngineFilter.TextSearchOption.ANY_WORD)) {
bc = BooleanClause.Occur.MUST_NOT;
}
for (int i = 0; i < values.length; i++) {
TermQuery term = new TermQuery(new Term(key, values[i].toLowerCase()));
// NOTE: search lower case....
fieldQuery.add(term, bc);
}
} else {
PhraseQuery phraseQuery = new PhraseQuery();
for (int i = 0; i < values.length; i++) {
// NOTE: search lower case....
phraseQuery.add(new Term(key, values[i].toLowerCase()));
}
return phraseQuery;
}
} else if (value instanceof Date) {
String toString = DateTools.timeToString(((Date) value).getTime(), DateTools.Resolution.MINUTE);
TermQuery term = new TermQuery(new Term(filter.getKey(), toString));
fieldQuery.add(term, BooleanClause.Occur.MUST);
} else if (value instanceof Number) {
TermQuery term = new TermQuery(new Term(filter.getKey(), value.toString()));
fieldQuery.add(term, BooleanClause.Occur.MUST);
}
} else if (filter.getStart() instanceof Number || filter.getEnd() instanceof Number) {
// .............................. TODO
} else {
String start = null;
String end = null;
if (filter.getStart() instanceof Date || filter.getEnd() instanceof Date) {
if (null != filter.getStart()) {
start = DateTools.timeToString(((Date) filter.getStart()).getTime(), DateTools.Resolution.MINUTE);
}
if (null != filter.getEnd()) {
end = DateTools.timeToString(((Date) filter.getEnd()).getTime(), DateTools.Resolution.MINUTE);
}
} else {
start = (null != filter.getStart()) ? filter.getStart().toString().toLowerCase() : null;
end = (null != filter.getEnd()) ? filter.getEnd().toString().toLowerCase() : null;
}
BytesRef byteStart = (null != start) ? new BytesRef(start.getBytes()) : null;
BytesRef byteEnd = (null != end) ? new BytesRef(end.getBytes()) : null;
TermRangeQuery range = new TermRangeQuery(filter.getKey(), byteStart, byteEnd, true, true);
fieldQuery.add(range, BooleanClause.Occur.MUST);
}
return fieldQuery;
}
use of org.entando.entando.aps.system.services.searchengine.SearchEngineFilter in project entando-core by entando.
the class TestSearchEngineManager method testSearchContentsId_7.
public void testSearchContentsId_7() throws Throwable {
try {
DataObject content_1 = this.createDataObject_1();
this.dataObjectSearchEngineManager.deleteIndexedEntity(content_1.getId());
this.dataObjectSearchEngineManager.addEntityToIndex(content_1);
DataObject content_2 = this.createDataObject_2();
this.dataObjectSearchEngineManager.deleteIndexedEntity(content_2.getId());
this.dataObjectSearchEngineManager.addEntityToIndex(content_2);
DataObject content_3 = this.createDataObject_3();
this.dataObjectSearchEngineManager.deleteIndexedEntity(content_3.getId());
this.dataObjectSearchEngineManager.addEntityToIndex(content_3);
// San Pietroburgo è una città meravigliosa W3C-WAI
// 100
// Il turismo ha incrementato più del 20 per cento nel 2011-2013, quando la Croazia ha aderito all'Unione europea. Consegienda di questo aumento è una serie di modernizzazione di alloggi di recente costruzione, tra cui circa tre dozzine di ostelli.
// 101
// La vita è una cosa meravigliosa
// 103
SearchEngineManager sem = (SearchEngineManager) this.dataObjectSearchEngineManager;
List<String> allowedGroup = new ArrayList<String>();
allowedGroup.add(Group.FREE_GROUP_NAME);
SearchEngineFilter filter1 = new SearchEngineFilter("it", "San meravigliosa", SearchEngineFilter.TextSearchOption.ALL_WORDS);
SearchEngineFilter[] filters1 = { filter1 };
List<String> contentsId = sem.searchEntityId(filters1, null, allowedGroup);
assertNotNull(contentsId);
assertEquals(1, contentsId.size());
assertTrue(contentsId.contains(content_1.getId()));
SearchEngineFilter filter2 = new SearchEngineFilter("it", "San meravigliosa", SearchEngineFilter.TextSearchOption.AT_LEAST_ONE_WORD);
SearchEngineFilter[] filters2 = { filter2 };
contentsId = sem.searchEntityId(filters2, null, allowedGroup);
assertNotNull(contentsId);
assertEquals(2, contentsId.size());
assertTrue(contentsId.contains(content_1.getId()));
assertTrue(contentsId.contains(content_3.getId()));
SearchEngineFilter filter3 = new SearchEngineFilter("it", "San meravigliosa", SearchEngineFilter.TextSearchOption.EXACT);
SearchEngineFilter[] filters3 = { filter3 };
contentsId = sem.searchEntityId(filters3, null, allowedGroup);
assertNotNull(contentsId);
assertEquals(0, contentsId.size());
SearchEngineFilter filter4 = new SearchEngineFilter("it", "una cosa meravigliosa", SearchEngineFilter.TextSearchOption.EXACT);
SearchEngineFilter[] filters4 = { filter4 };
contentsId = sem.searchEntityId(filters4, null, allowedGroup);
assertNotNull(contentsId);
assertEquals(1, contentsId.size());
assertTrue(contentsId.contains(content_3.getId()));
} catch (Throwable t) {
throw t;
}
}
Aggregations