Search in sources :

Example 1 with StringSuggestionSearch

use of com.rbmhtechnology.vind.api.query.suggestion.StringSuggestionSearch in project vind by RBMHTechnology.

the class SolrSearchServer method buildSolrQuery.

protected SolrQuery buildSolrQuery(ExecutableSuggestionSearch search, DocumentFactory assets, DocumentFactory childFactory) {
    final String searchContext = search.getSearchContext();
    final SolrQuery query = new SolrQuery();
    query.setRequestHandler("/suggester");
    if (search.isStringSuggestion()) {
        StringSuggestionSearch s = (StringSuggestionSearch) search;
        query.setParam("suggestion.field", s.getSuggestionFields().stream().map(name -> {
            if (Objects.nonNull(childFactory)) {
                final FieldDescriptor<?> field = Objects.nonNull(assets.getField(name)) ? assets.getField(name) : childFactory.getField(name);
                if (Objects.isNull(field)) {
                    log.warn("No field descriptor found for field name {} in factories: {}, {}", name, assets.getType(), childFactory.getType());
                }
                return getFieldname(field, UseCase.Suggest, searchContext);
            } else {
                if (Objects.isNull(assets.getField(name))) {
                    log.warn("No field descriptor found for field name {} in factory: {}", name, assets.getType());
                }
                return getFieldname(assets.getField(name), UseCase.Suggest, searchContext);
            }
        }).filter(Objects::nonNull).toArray(String[]::new));
    } else {
        DescriptorSuggestionSearch s = (DescriptorSuggestionSearch) search;
        query.setParam("suggestion.field", s.getSuggestionFields().stream().map(descriptor -> getFieldname(descriptor, UseCase.Suggest, searchContext)).filter(Objects::nonNull).toArray(String[]::new));
    }
    query.setParam("q", search.getInput());
    // TODO: somehow this is still needed here, it should by configuration
    query.setParam("suggestion.df", SUGGESTION_DF_FIELD);
    query.setParam("suggestion.limit", String.valueOf(search.getLimit()));
    String parentTypeFilter = "_type_:" + assets.getType();
    if (Objects.nonNull(childFactory)) {
        parentTypeFilter = "(" + parentTypeFilter + " OR _type_:" + childFactory.getType() + ")";
    }
    query.add(CommonParams.FQ, parentTypeFilter);
    // filters
    if (search.hasFilter()) {
        SolrUtils.Query.buildFilterString(search.getFilter(), assets, childFactory, query, searchContext, false);
        new SolrChildrenSerializerVisitor(assets, childFactory, searchContext, false);
    }
    // suggestion deep search
    if (Objects.nonNull(childFactory)) {
        if (search.hasFilter()) {
            // TODO clean up!
            final String parentFilterQuery = "(" + String.join(" AND ", query.getFilterQueries()) + ")";
            final String childrenFilterQuery = search.getFilter().accept(new SolrChildrenSerializerVisitor(assets, childFactory, searchContext, false));
            final String childrenBJQ = "{!child of=\"_type_:" + assets.getType() + "\" v='" + childrenFilterQuery + "'}";
            query.set(CommonParams.FQ, String.join(" ", parentFilterQuery, "OR", childrenBJQ));
        }
    }
    return query;
}
Also used : Delete(com.rbmhtechnology.vind.api.query.delete.Delete) SearchServerException(com.rbmhtechnology.vind.SearchServerException) URISyntaxException(java.net.URISyntaxException) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) Asserts(org.apache.http.util.Asserts) StringUtils(org.apache.commons.lang3.StringUtils) SolrServerException(org.apache.solr.client.solrj.SolrServerException) Fieldname(com.rbmhtechnology.vind.solr.backend.SolrUtils.Fieldname) Facet(com.rbmhtechnology.vind.api.query.facet.Facet) UpdateOperation(com.rbmhtechnology.vind.api.query.update.UpdateOperation) ParseException(java.text.ParseException) FileSystemUtils(com.rbmhtechnology.vind.utils.FileSystemUtils) Path(java.nio.file.Path) SearchServer(com.rbmhtechnology.vind.api.SearchServer) Slice(com.rbmhtechnology.vind.api.query.division.Slice) AnnotationUtil(com.rbmhtechnology.vind.annotations.AnnotationUtil) SchemaResponse(org.apache.solr.client.solrj.response.schema.SchemaResponse) Update(com.rbmhtechnology.vind.api.query.update.Update) SchemaRequest(org.apache.solr.client.solrj.request.schema.SchemaRequest) DescriptorSuggestionSearch(com.rbmhtechnology.vind.api.query.suggestion.DescriptorSuggestionSearch) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) com.rbmhtechnology.vind.api.query(com.rbmhtechnology.vind.api.query) RealTimeGet(com.rbmhtechnology.vind.api.query.get.RealTimeGet) Stream(java.util.stream.Stream) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrPingResponse(org.apache.solr.client.solrj.response.SolrPingResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) com.rbmhtechnology.vind.api.result(com.rbmhtechnology.vind.api.result) ClientUtils(org.apache.solr.client.solrj.util.ClientUtils) ServiceProvider(com.rbmhtechnology.vind.api.ServiceProvider) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Interval(com.rbmhtechnology.vind.api.query.facet.Interval) SolrRequest(org.apache.solr.client.solrj.SolrRequest) java.util(java.util) ExecutableSuggestionSearch(com.rbmhtechnology.vind.api.query.suggestion.ExecutableSuggestionSearch) FieldDescriptor(com.rbmhtechnology.vind.model.FieldDescriptor) NumberFormat(java.text.NumberFormat) UpdateOperations.set(com.rbmhtechnology.vind.api.query.update.Update.UpdateOperations.set) CollectionUtils(org.apache.commons.collections.CollectionUtils) SearchConfiguration(com.rbmhtechnology.vind.configure.SearchConfiguration) Logger(org.slf4j.Logger) StringSuggestionSearch(com.rbmhtechnology.vind.api.query.suggestion.StringSuggestionSearch) LatLng(com.rbmhtechnology.vind.model.value.LatLng) Resources(com.google.common.io.Resources) DateUtil(org.apache.solr.common.util.DateUtil) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) org.apache.solr.common.params(org.apache.solr.common.params) IOException(java.io.IOException) NamedList(org.apache.solr.common.util.NamedList) Document(com.rbmhtechnology.vind.api.Document) SolrClient(org.apache.solr.client.solrj.SolrClient) SolrDocument(org.apache.solr.common.SolrDocument) DocumentFactory(com.rbmhtechnology.vind.model.DocumentFactory) Page(com.rbmhtechnology.vind.api.query.division.Page) UpdateOperations(com.rbmhtechnology.vind.api.query.update.Update.UpdateOperations) DescriptorSuggestionSearch(com.rbmhtechnology.vind.api.query.suggestion.DescriptorSuggestionSearch) StringSuggestionSearch(com.rbmhtechnology.vind.api.query.suggestion.StringSuggestionSearch) SolrQuery(org.apache.solr.client.solrj.SolrQuery) FieldDescriptor(com.rbmhtechnology.vind.model.FieldDescriptor)

Aggregations

Resources (com.google.common.io.Resources)1 SearchServerException (com.rbmhtechnology.vind.SearchServerException)1 AnnotationUtil (com.rbmhtechnology.vind.annotations.AnnotationUtil)1 Document (com.rbmhtechnology.vind.api.Document)1 SearchServer (com.rbmhtechnology.vind.api.SearchServer)1 ServiceProvider (com.rbmhtechnology.vind.api.ServiceProvider)1 com.rbmhtechnology.vind.api.query (com.rbmhtechnology.vind.api.query)1 Delete (com.rbmhtechnology.vind.api.query.delete.Delete)1 Page (com.rbmhtechnology.vind.api.query.division.Page)1 Slice (com.rbmhtechnology.vind.api.query.division.Slice)1 Facet (com.rbmhtechnology.vind.api.query.facet.Facet)1 Interval (com.rbmhtechnology.vind.api.query.facet.Interval)1 RealTimeGet (com.rbmhtechnology.vind.api.query.get.RealTimeGet)1 DescriptorSuggestionSearch (com.rbmhtechnology.vind.api.query.suggestion.DescriptorSuggestionSearch)1 ExecutableSuggestionSearch (com.rbmhtechnology.vind.api.query.suggestion.ExecutableSuggestionSearch)1 StringSuggestionSearch (com.rbmhtechnology.vind.api.query.suggestion.StringSuggestionSearch)1 Update (com.rbmhtechnology.vind.api.query.update.Update)1 UpdateOperations (com.rbmhtechnology.vind.api.query.update.Update.UpdateOperations)1 UpdateOperations.set (com.rbmhtechnology.vind.api.query.update.Update.UpdateOperations.set)1 UpdateOperation (com.rbmhtechnology.vind.api.query.update.UpdateOperation)1