Search in sources :

Example 1 with SearchTerm

use of org.codice.ddf.catalog.ui.query.delegate.SearchTerm in project ddf by codice.

the class CqlResult method countMatches.

private void countMatches(Set<SearchTerm> searchTerms, Metacard mc) {
    List<String> textAttributes = mc.getMetacardType().getAttributeDescriptors().stream().filter(CqlResult::isTextAttribute).filter(Objects::nonNull).map(descriptor -> mc.getAttribute(descriptor.getName())).filter(Objects::nonNull).map(attribute -> Optional.ofNullable(attribute.getValue())).filter(Optional::isPresent).map(Optional::get).map(Object::toString).collect(Collectors.toList());
    List<SearchTerm> terms = searchTerms.stream().filter(term -> !"*".equals(term.getTerm())).collect(Collectors.toList());
    int totalTokens = 0;
    for (String value : textAttributes) {
        BufferedReader reader = new BufferedReader(new StringReader(value.toLowerCase()));
        String line;
        try {
            while ((line = reader.readLine()) != null) {
                String[] tokens = line.split("[\\s\\p{Punct}]+");
                for (String token : tokens) {
                    totalTokens++;
                    for (SearchTerm term : terms) {
                        if (term.match(token)) {
                            matches.put(term.getTerm(), matches.getOrDefault(term.getTerm(), 0) + 1);
                        }
                    }
                }
            }
        } catch (IOException e) {
            LOGGER.debug("Unable to read line", e);
        }
        matches.put("*", totalTokens);
    }
}
Also used : ValidationRule(org.locationtech.spatial4j.context.jts.ValidationRule) ShapeReader(org.locationtech.spatial4j.io.ShapeReader) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) FilterAdapter(ddf.catalog.filter.FilterAdapter) StringUtils(org.apache.commons.lang3.StringUtils) AttributeType(ddf.catalog.data.AttributeType) Action(ddf.action.Action) DistanceUtils(org.locationtech.spatial4j.distance.DistanceUtils) ImmutableList(com.google.common.collect.ImmutableList) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) QueryRequest(ddf.catalog.operation.QueryRequest) ParseException(java.text.ParseException) Result(ddf.catalog.data.Result) DateTimeFormat(org.joda.time.format.DateTimeFormat) JtsSpatialContextFactory(org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory) Logger(org.slf4j.Logger) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) PropertyJsonMetacardTransformer(ddf.catalog.transformer.metacard.propertyjson.PropertyJsonMetacardTransformer) WktQueryDelegate(org.codice.ddf.catalog.ui.query.delegate.WktQueryDelegate) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) ImmutableMap(com.google.common.collect.ImmutableMap) DateTime(org.joda.time.DateTime) Set(java.util.Set) IOException(java.io.IOException) Shape(org.locationtech.spatial4j.shape.Shape) Collectors(java.util.stream.Collectors) SpatialContextFactory(org.locationtech.spatial4j.context.SpatialContextFactory) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Objects(java.util.Objects) Query(ddf.catalog.operation.Query) List(java.util.List) Attribute(ddf.catalog.data.Attribute) StringReader(java.io.StringReader) SearchTerm(org.codice.ddf.catalog.ui.query.delegate.SearchTerm) Optional(java.util.Optional) ActionRegistry(ddf.action.ActionRegistry) BufferedReader(java.io.BufferedReader) SpatialContext(org.locationtech.spatial4j.context.SpatialContext) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) IOException(java.io.IOException) SearchTerm(org.codice.ddf.catalog.ui.query.delegate.SearchTerm)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Action (ddf.action.Action)1 ActionRegistry (ddf.action.ActionRegistry)1 Attribute (ddf.catalog.data.Attribute)1 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)1 AttributeType (ddf.catalog.data.AttributeType)1 Metacard (ddf.catalog.data.Metacard)1 Result (ddf.catalog.data.Result)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 FilterAdapter (ddf.catalog.filter.FilterAdapter)1 Query (ddf.catalog.operation.Query)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 PropertyJsonMetacardTransformer (ddf.catalog.transformer.metacard.propertyjson.PropertyJsonMetacardTransformer)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ParseException (java.text.ParseException)1