Setting up my search function

I tested the search functions that I implemented on the website. I ran into some small problems. I can’t put special characters in the search field, otherwise my application will crash. I tried to solve this using some replacements on the characters with which he crashed, but this will not cure the pain. When I entered this sign: * in the search field, he gave me the following error:

Unable to parse '<%%> echo;': '' or '?' not allowed as first character in WildcardQuery. I had this error before and then the spaces were divided between all the words. The error has disappeared. However, when I now replace this: * with this: "" I will get the error described above. Is there a standard way by which I can solve a special problem? I will write my code here to get the best feedback.

Analyzer analyzer = new StandardAnalyzer();
QueryParser qpContent = new QueryParser(Index.ContentFieldName, analyzer);
keyword.Trim();

keyword = keyword.Replace("\"", "");
keyword = keyword.Replace("^", "");
keyword = keyword.Replace("*", "");

Query queryContent = qpContent.Parse(keyword + "*");              
QueryParser qpLanguage = new QueryParser("language", analyzer);
Query queryLanguage = qpLanguage.Parse(Sitecore.Context.Language.Name.ToString());

As you can see, I will first replace *, and then add it back to queryparser. I am not 100% familiar with such functionality and therefore do not know what I'm doing wrong. All help is much appreciated, thanks!

+3
source share

Source: https://habr.com/ru/post/1729897/


All Articles