Question

I'm using Infinispan 6.0.2 and Hibernate Search 4.4.0.

In my cache, there are some data which value is hibernate_search_DSL (type String). When I use keyword search with hibernate, it can't find the result with underscore (hibernate_search_DSL).

I think in Hibernate hibernate_search_DSL is just one word, so I wrote a String Bridge try to replace all _ to space, but it doesn't work.

Here is my class:

public class NormaliseValue implements StringBridge{

    public String objectToString(Object object)
    {
        if(object == null)
            throw new IllegalArgumentException("There is no value to normalise");

        String value = object.toString();
        value.replaceAll("_", " ");
        return value;
    }
}

And mapping index:

mapping.entity(Hibernate.class).indexed().providedId()
    .property("value", ElementType.FIELD).field().bridge(NormaliseValue.class);

Is something wrong or there is any solution simpler to find result with underscore???

Was it helpful?

Solution

The default behaviour is to use the StandardAnalyzer, which breaks input strings on whitespaces and symbols. So the literal "hibernate_search_DSL" is probably (I assume you're using the default analyzer) tokenized into the different keywords "hibernate", "search" and "dsl" (as it also does lowercasing).

The principle of full-text is that then when you tokenize the query via the same Analyzer, it will match and score according the to parts.

If you want to disable this and just use an exact-match, disable the Analyzer on the property with the annotation:

@Field(analyze = Analyze.NO)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top