Umbraco Examine for searching and returning result...
# help-with-umbraco
b
Hi, I am trying to get the search results of child items. Some child items are within one parent item and some child items are from another parent item. I tried to build a query using examine however I'm not getting the expected results. Any assistance would be much appreciated. The following below is what I'm trying to accomplish: var query = index.Searcher.CreateQuery("content"); var results = query.ParentId(nodeItem1Id).And().ParentId(nodeItem2Id).Execute();
j
With
And()
it would have to have both those ids as a parent wich is only possible if they are the same. Should probably be
Or()
instead?
m
for multiple or/and look at the groupedOr/groupedAnd https://github.com/Shazwazza/Examine/wiki/Grouped-Operations
b
So I'm looking to only get child items from two different parent nodes and combine them. I would use .parentId(nodeid) and execute that function twice to get two sets of children results and combine them afterwards but I prefer executing the query only once to get the full set.
j
switching and to or would do that
b
Or() doesn't seem to make any difference
b
I would write it little differently give me 2 and will send you example
@bran31 something like this:
Copy code
var query = index.Searcher.CreateQuery("content");

        var results = query.Group(x=>x.GroupedOr(new List<string>(){"parentID" }, new List<string>()
        {
            nodeItem1Id.ToString(),
            nodeItem2Id.ToString(),
        }),BooleanOperation.And).Execute();
b
I've tried the following, it still gave no results when I plucked two different node ids in the second parameter. It seems that the second parameter accepts a string[] rather than a list. Has this query been tested on umbraco version 12?
b
Ahhh forgot do to array πŸ˜… it wasn't tested as it was example and this method will work in V12 as V12 uses examine 3 anyway
But yeah I used code this type a lot, so not sure why it wouldn't workπŸ€”
d
Is "parentId" a field in your index at all? Just a sanity check
j
Also string field names are case sensitive FYI
b
I copied parentID from v8 umbraco side, it might be something for sanity check if umbraco didnt change it in v9-v12 πŸ˜‚ as i had backoffice for v8 opened so checked the name of property there
j
In our solutions we use the path option. and specify it in a groupedOr like this: query.And().GroupedOr(new[] { "path" }, paths); where path is set with node.Path.MultipleCharacterWildcard()
b
@Johan R. you shouldnt use built in path tbh πŸ˜‰ or wildcard in paths searching πŸ˜‰
j
Why not?
b
@Johan R. you might have 2 nodes with IDs 123 and 1234 and if you search on built in field, you need make expensive match with wildcard, and you don't want do wilcards as now 123,* will match 1234 if you don't play around with query. Best is have separate field with path as separate values and do exact match
j
no but you can search for all items below a home node like -1,1073,*
b
It is expensive...
Also if you don't set analyser it might go funky πŸ˜…
Wildcard are really expensive and introduce a lot complexity in queries, you can get them to work but you leave a lot performance on table plus debbuging is hell
j
luke 4 the win πŸ˜›
b
If I want make my life harder yeah Luke 4 win 🀣
Luke introduce other implementation of lucene which might cause other issues even when they are supposed to be compatible with each other
But yeah I am tired of fighting lucene queries I spend too much of my life on it already πŸ˜‚
68 Views