Help with a Search Issue
# help-with-umbraco
h
Can anyone see what might be wrong with my query, the index exists and search in the backoffice examine screen returns results, but the query below is not returning anything
Copy code
if (_examineManager.TryGetIndex("ForumIndex", out var index))
            {
                var searcher = index.Searcher;
                var criteria = searcher.CreateQuery(IndexTypes.Content, BooleanOperation.And);
                var examineQuery = criteria.NodeTypeAlias("forumPost");

                if (!string.IsNullOrEmpty(query))
                {
                    if (textFields.Count > 1)
                    {
                        string[] terms = query.Split(' ');
                        examineQuery.And().GroupedOr(textFields, terms);
                    }
                    else
                    {
                        examineQuery.And().Field(textFields.First(), query.MultipleCharacterWildcard());
                    }
                }

                results = examineQuery.Execute();
            }
j
You can set a breakpoint on the
Copy code
csharp
results = examineQuery.Execute();
and then you can get the full lucene query string. You can use that to test whether the specific search gets any results in the backoffice. The backoffice index searcher accepts lucene strings
a
Is your alias correct? Always nice to use ForumPost.ModelTypeAlias if you're using typed models to be sure 🙂
Also textxFields.First() assume contains the first field to search, is the used name correct ? 🙂
Further I dont see anything weird
h
I'll try setting breakpoint, names/aliases all look to be correct
this is the query
+__NodeTypeAlias:forumpost +message:test*
which returns data in the back office
j
It should have more than that in the query string? Since you have
searcher.CreateQuery(IndexTypes.Content, BooleanOperation.And);
it should atleast have
+__IndexType: content
, also given that you have a custom index - are you sure that it has that indextype?
m
ps string[] terms = query.Split(' '); you don't actually need to do that, as examine will automatically split a space delimited string.. only way to actually get it to search on "a b c" is to use phrase matching via Escape() eg
Copy code
string keyword = "aa bb cc"
.GroupedOr(new[] { "nodeName" }, keyword.Escape(), keyword.Boost(12))
results in
{ Category: content, LuceneQuery: +__NodeTypeAlias:tenderpage +((nodeName:"aa bb cc" ((nodeName:aa nodeName:bb nodeName:cc)^12.0)) }
h
This is what I see in the debugger {Category: "content", LuceneQuery: {+__NodeTypeAlias:forumpost +message:test*}
Using this in the BO
+__IndexType: content +__NodeTypeAlias:forumpost +message:test*
doesn't return results, so what have I done wrong?
Doh! I'm a total numpty 🤣
it should be
searcher.CreateQuery("forum", BooleanOperation.And);
😄 Thanks for the pointers.
because I was doing this new ValueSet(content.Id.ToString(), "Forum",content.ContentType.Alias ,indexValues);
j
Ahh yep so it was the indextype 🙂
2 Views