com.rbmhtechnology.vind.api.SmartSearchServerBase Maven / Gradle / Ivy
package com.rbmhtechnology.vind.api;
import com.rbmhtechnology.vind.annotations.AnnotationUtil;
import com.rbmhtechnology.vind.api.query.FulltextSearch;
import com.rbmhtechnology.vind.api.result.BeanSearchResult;
import com.rbmhtechnology.vind.api.result.SearchResult;
import com.rbmhtechnology.vind.model.DocumentFactory;
import com.rbmhtechnology.vind.parser.queryparser.VindQueryParser;
public abstract class SmartSearchServerBase extends SearchServer {
@Override
public BeanSearchResult execute(FulltextSearch search, Class c) {
if(search.isSmartParsing()) {
return doExecute(smartParse(search, c),c);
} else {
return doExecute(search, c);
}
}
protected abstract BeanSearchResult doExecute(FulltextSearch search, Class c);
@Override
public SearchResult execute(FulltextSearch search, DocumentFactory factory) {
if(search.isSmartParsing()) {
return doExecute(smartParse(search, factory),factory);
} else {
return doExecute(search, factory);
}
}
protected abstract SearchResult doExecute(FulltextSearch search, DocumentFactory factory);
protected FulltextSearch smartParse(FulltextSearch search, DocumentFactory factory) {
final VindQueryParser parser = new VindQueryParser();
final FulltextSearch smartSearch = parser.parse(search.getSearchString(), factory);
search.text(smartSearch.getSearchString());
search.filter(smartSearch.getFilter());
return search;
}
protected FulltextSearch smartParse(FulltextSearch search, Class c) {
final DocumentFactory factory = AnnotationUtil.createDocumentFactory(c);
return smartParse(search, factory);
}
}