How can I sort in Solr empty fields to the last position? - solr

I have in Apache Solr a field named "firstname" with a String in it, which can be empty. I want to sort the field in ascending order, but if it is empty, how can I determine that it should be sorted to the end?
I already tried sortMissingLast="true", but it didn't go as expected, because it only sorts fields last, if the field is missing and not an empty value.

Related

Mongo DB Query to check if document array field element present in more than one document

I have been searching through the MongoDB query syntax with various combinations of terms to see if I can find the right syntax for the type of query I want to create.
We have a collection containing documents with an array field. This array field contains ids of items associated with the document.
I want to be able to check if an item has been associated more than once. If it has then more than one document will have the id element present in its array field.
I don't know in advance the id(s) to check for as I don't know which items are associated more than once. I am trying to detect this. It would be comparatively straightforward to query for all documents with a specific value in their array field.
What I need is some query that can return all the documents where one of the elements of its array field is also present in the array field of a different document.
I don't know how to do this. In SQL it might have been possible with subqueries. In Mongo Query Language I don't know how to do this or even if it can be done.
You can use $lookup to self join the rows and output the document when there is a match and $project with exclusion to drop the joined field in 3.6 mongo version.
$push with [] array non equality match to output document where there is matching document.
db.col.aggregate([
{"$unwind":"$array"},
{"$lookup":{
"from":col,
"localField":"array",
"foreignField":"array",
"as":"jarray"
}},
{"$group":{
"_id":"$_id",
"fieldOne":{"$first":"$fieldOne"},
... other fields
"jarray":{"$push":"$jarray"}
}},
{"$match":{"jarray":{"$ne":[]}}},
{"$project":{"jarray":0}}
])

How to find a SOLR entry that has a field with no value?

I have a local SOLR server with some entries that have a field "debaTest": "" while some entries don't have this field at all.
Is there a way in Solr to filter out the entries that have this field? the value for the field will always be null or empty.
Please note: Something in the lines of q=-debaTest:[* TO *] or
-debaTest:* won't work for my requirement as this returns the entries that don't have these fields at all and I want the entries that have this field but without a value.

Solr search on a field with ReverseStringFilterFactory return 0 records for reverse input

I have a requirement where user should able to get same result when searched with a String in reversed or striaght for
example: q="F44" or q="44F" should result same result.
I have created a new field "text_rev" which is assigned to below Field Type.
And I did Copy field with actual/original field "retailId"
<copyField source="retailId" dest="text_rev"/>
<fieldType name="text_rvsstr" class="solr.TextField"><analyzer><tokenizer class="solr.StandardTokenizerFactory"/><filter class="solr.ReverseStringFilterFactory"/></analyzer></fieldType>
when I search with q=text_rev:F44 i get the result but when i search with q=text_rev:44F i get 0 results.
Please advice.
Those searches are on the same field. Searching the reverse direction is only going to work on the reversed field, and searching the forward direction is only going to work on the original field.
By searching both fields for the same information, you can check both directions in one query.
q=retailId:F44 OR text_rev:F44
You need to search both fields. Also, if you actually expect to search in reverse, you need to have asymmetric index and query-type definition. Otherwise your term will get reversed both during indexing and querying and you effectively loose any reason to do so.
You can test that by using Analyse screen of the Admin UI and providing content in both boxes. It will then show how the terms get processed and matched during indexing/querying.

Last element of multivalued field in solr

Is there any way to get last element of multivalued field in solr. I want to run a query with search string present as the last element of multivalued field.Help would be really appreciated.
The easiest thing would be to use UpdateRequestProcessor chain to copy only the last value into the dedicated field and search against that. You can use LastFieldValueUpdateProcessorFactory for that.

SOLR - String field sorting

I've a string field defined in SOLR that is populated with values such as "020001" and "50002" etc...
I require it to be a string field since I tokenize it for filtering purposes. Now, when I try to sort on this field it shows wrong order (not even ASCII). Is there a way to sort this field in the asc./desc. order? Thanks.
If you sort on a tokenized field, you're probably sorting on a multivalued field, which is something which will probably not give you the result you're expecting.
You can solve this by adding a dedicated field for sorting that contain the value you want to sort by, which will also allow you to use a more proper field type (such as tint) if you want to parse the value into an integer or still use it as a String value.

Resources