Get only one matching row from Solr array - solr

How do I get only a row which matches my query: ?q=taxonomy_ids:1/636/*
Got that result:
Want only: <str>1/636/587</str>

There is no easy way. However, there is a trick, where you use a match highlighter and use those results instead of the results returned from the search itself. You may want to configure PRE/POST highlight tags to empty strings. There was an article on the web about somewhere, but I can't find it again.
The disadvantage is that you get your results twice. Once as docs and once as highlight.
The other option is a custom component that hooks into Lucene's explain structure.

Related

Faceting before collapse in Solr

I am using CollapseQueryParser Plugin in Solr to collapse results across one common field.
Quoting the official Solr Documentation -
This parser collapses the result set to a single document per group before it forwards the result set to the rest of the search components. So all downstream components (faceting, highlighting, etc.) will work with the collapsed result set.
There are multiple facet fields in the query, and for one particular facet, I need to do the faceting or aggregation before the collapse happens and as usual for others. I tried excluding it with a tag and using collapse.facet=facet.before, but these didn't work.
Is there any way to do this in Solr? I am using Solr-7.7.2.
Thanks in advance!
As mentioned in the comments, I found a way to handle this. Posting this for someone who might encounter this in future.
I had to tag the collapse query seperately and then use that tag wherever i needed exclusion as shown below.
While collpsing -
fq={!tag%3DcollapseTag}{!collapse+field%3Dcollapse_field+nullPolicy%3Dignore+cache%3Dfalse}
And while faceting -
facet.field={!ex%3Dfksize,collapseTag}size_string_mv

How can I use RelationshipFilter in 2sxc Visual Query with text field instead of entity field?

I'm trying to do the same as this example does under title "Attribute-On-Relationship to Query other Fields".
I'm editing Blog application visual query.
So I have RelationshipFilter, which takes entities of type Category via Default in point. And I want to filter them by field Name. Here I can get list of names either from params or from list of posts and their categories. That's not a problem as far as I understand.
So looks like Name has to be of entity type. I'm struggling right now with this filter, since I want to filter Category by field Name of simple text type. Which means that I have nothing to specify in Relationship Attribute. EntityTitle or just empty Relationship Attribute field don't work and cause Bad Request error. So is there a way to make it work?
P.S. ValueFilter is not an option, since it doesn't support returning nothing if there are no items, that satisfy condition and also it supports only filter by item's Attribute, that contains Value and no option that Value can contain any in Attribute with separator.
The RelationshipFilter is only meant for relationships (item with item) - and you seem to want to do a string-compare.
I'm not really sure what you should do because I don't have context, but if things get really special, best use LINQ instead. Check out the tutorials for LINQ here: https://2sxc.org/dnn-tutorials/en/razor/linq/home

Reactive search Datasearch Show suggestions with default Query and/or custom query, only getting results on the first character

I have a reactive search Datasearch component that is running a default Query in order to exclude some results based on an Id. If I use the Datasearch without a default query, I am getting the suggestions just fine. But whenever I add the default query I can see the correct suggestions on the first character but after that it stops giving any suggestions.
I have been looking around in the render rawData and data variables. And I can see there are still rawData vars, but the Data input stops after the first hit. In addition, When I add a custom query, it seems that the suggestions do not really take this in account as it still shows suggestions outside of the subset created by the query.
My question is now, How to get the default query and custom query to work together with suggestions?
It seems that all the other components work correctly with my default query as in only showing results in the subset created by the custom query
Would be really helpful if someone could point me in the right direction on this one, Thanks in advance.
Update:
I want to add that when I look in the stateProvided object. Whenever I add the defaultQuery. The stateprovider stop showing the SearchState after one character in the searchbox. It seems like it's completely blocking the normal behaviour

Multiple/split filter chains for a single Solr field

Is it possible to configure a Solr field to have multiple/split Filter chains? For example, could I create a Filter chain that looks like this?:
StandardTokenizer
↓
LowerCaseFilter
↙ ↘
SynonymnFilter PhoneticFilter
↓
NGramFilter
I've done quite a bit of searching and haven't found any examples of setting up a Filter chain this way.
EDIT
The main reason I would like to do this in the context of a single field (as opposed to indexing the data twice using a copy field) is for highlighting. If I use a copy field to run a different filter chain on the same data, my highlighting results come back like this:
"highlighting":{
"1234": {
"firstName_phonetic":["<hl>John</hl>"],
"firstName_ngram":["<hl>John</hl>"]
}
}
This makes consuming the results a bit more difficult as the consuming app needs to choose which highlighted field to display. Ideally, I'd get something back like this:
"highlighting":{
"1234": {
"firstName":["<hl>John</hl>"]
}
}
The output of one filter goes to the next filter in the chain. There is no support for "branching".
You'll be implementing this method if you want a custom filter.
org.apache.lucene.analysis.TokenStream.incrementToken()
This method returns a boolean. You can see an example here.
Another possible solution is to use a copyField to combine firstName_phonetic and firstName_ngram into firstName and use hl.fl=firstName
It sounds reasonable just to use copyField and index two different fields, each with its own chain.
But, I guess nothing prevents you from implementing your own MyCustomFilter that does what you need, and you plug that one into your conf.

Solr autocomplete keyword and geolocation based

I am looking for getting auto complete suggestions using Solr based on keyword as well as geolocation. Is there a way the 'Suggester' component or any other way, Solr can take in multiple fields for auto completion?
For e.g. if I have a restaurants database and I want to get suggestions using keyword e.g. 'Piz', the results should be based both on the keyword 'Piz' and also the locations that are close to certain latitude, longitude.
Is there a way to do it in Solr ?
Thanks.
you create a handler that:
in the index analyzer chaing, use EdgeNGram to math what the user entered so far
boost results with geodist(): play around with recip() etc until you get desired weight on the location boosting
call that handler and pass current location and user entered chars and you are done

Resources