How to do case insensitive search using QueryBuilder in CQ? - aem

I am doing CQ search using Querybuilder on a set of 8 properties. One of them is a text box. So case insensitive search needs to be done on it. All others are drop downs.
Issue: Case sensitive search is happening on the text box.
Below mentioned in piece of code. When I include case insensitive code, the search is not happening properly.
Any pointers on this will be really helpful.
map.put("1_customcase.property", searchkey);
map.put("1_customcase.property.value", searchkey);
map.put("1_customcase.case", "no_case");
map.put("orderby", "customcase");**
map.put("2_property", propertyname);
map.put("2_property.value", value);
map.put("3_property", propertyname);
map.put("3_property.value", value);
...
...
...
Query query = builder.createQuery(PredicateGroup.create(map), session);

Related

AEM 6.3 Query builder - How to search for case insensitive?

How can we make the query to ignore case sensitivity of the property.value ?
Our query:
path=/content/central-content/jcr:content/main/decline_letter
property.value=0091A
property=#letterNumber
type=nt:unstructured
Works for 0091A but fails for 0091a
Using fulltext seemed to be helping/working.
path=/content/central-content/jcr:content/main/decline_letter
fulltext=0091A
property=#letterNumber
type=nt:unstructured
orderby.case=ignore
fulltext may not be a good solution is we have to be searching among a lot of nodes/data. In our case, we search for a very minimal number of nodes.

Possible to get words matched fuzzily by MongoDB full text search?

I'm writing a UI that presents the results of a MongoDB full text search query, visually highlighting the matched search terms in each result; this works well enough for full word or phrase matches, but not for partial/fuzzy matches.
For example, if I search for "delete" a will get a search result that contains "deletion", which does not contain the full word "delete" and therefore won't be highlighted if I merely highlight the full search term matches. I do want the partial matches, though.
Is there any way to project the set of matched words/substrings when I execute the query?
I've so far been unable to find anything in the docs that hints at this being possible, but I thought it worth asking around. Any help would be greatly appreciated.
You can use the Mongo DB Atlas feature where you can search your text based on different Analyzers that MongoDB provides. And you can then do a search like this: Without the fuzzy object, it would do a full-text-match search.
$search:{
{
index: 'analyzer_name_created_from_atlas_search',
text: {
query: 'Text to do a full match or fuzzy match with',
path: 'sentence',
fuzzy:{
maxEdits: 2 #max 2 is allowed
}
}
}
}

Hibernate Search Turkish Character

I am trying to search a field filled with Turkish characters.
For example: Müdürlük.
But when I try to query this field not able to get results. I am new to hibernate search. What should I do?
There may be other problem (I can't tell without the code), but one thing you'll probably want is to use a language-specific analyzer, so that "mudurluk" will match "Müdürlük" for instance, or so that "istanbul" will match "İstanbul" (capital dotted "i").
To do that with Hibernate Search using annotations, fill in the analyzer attribute of your #Field annotation:
#Field(analyzer = #Analyzer(impl = org.apache.lucene.analysis.tr.TurkishAnalyzer.class))
String myProperty;
If you mapped your entity using the programmatic API, the process should be fairly similar.
Please see the official documentation for more details about analyzers in Hibernate Search: https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#_analyzer
EDIT: don't forget to reindex your data after you changed the analyzer.

Case insensitive with Exact Search term Query

I am trying to make a query that searches for the exact keyword but case insensitively.
It works fine but the issue that it searches for the whole keywords into the DB that CONTAINS my search term.
mongoTemplate.findOne(Query.query(Criteria.where("resourceID").regex(id, "i")), Resource.class);
I need to make like the follwoing script but in java:
db.stuff.find( { foo: /^bar$/i } );
Resource resource = mongoTemplateGoVacation.findOne(Query.query(Criteria.where("resourceID").regex("^"+id+"$", "i")), Resource.class);

Can we get match items' position at Lucence.net search result?

I'm using Lucene.net to implement fulltext search feature in an Asp.net application. The search result page should high light the match items. I got the instance of Lucene.Net.Search.Hits and used .Doc(int i) method to get Lucene Document.
But I don't know how to get the position of match item by existing method or property of some Lucene class. Does Lucene.net provide any feature to support high light query string?
You can use Highlighter or FastVectorHighlighter which can be found in contrib
As the previous answerer said, you should use either Highlighter or FastVectorHighlighter from contrib.
Here's an example of using Highlighter lib to get highlighted fragments:
Formatter formatter = new SimpleHTMLFormatter("<span><b>", "</b></span>");
Lucene.Net.Highlight.Scorer scorer = new QueryScorer(query, field);
Lucene.Net.Highlight.Encoder encoder = new SimpleHTMLEncoder();
var highlighter = new Highlighter(formatter, encoder, scorer);
highlighter.SetTextFragmenter(new SimpleFragmenter(100));
string[] fragments =
highlighter.GetBestFragments(DefaultAnalyzer, field, doc.Get(field), 3);
Some Highlighter-related gotchas:
To highlight a field, it should be added to index with Field.Store.YES option
Your query should be rewritten before passing it to highlighter
The analyzer you pass to highlighter should be the same you use for indexing and searching