Last element of multivalued field in solr - 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.

Related

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.

How to save value with wildcard in Solr?

all.
I have the following trouble with Solr. I need to implement "reverse" search with wildcards. I mean I want to keep value like "auto*" and this item should be found with request like "autocar", "autoplan" or "automate". Could someone help me with this, please? Thanks.
If you want to match shorter indexed value (auto) against longer searched value (autobus), you want a custom analysis chain that includes EdgeNGramFilter on the query side only. Then, the incoming search word will get split into possible prefixes and matched against the indexed term.

to get the count of multi valued field in solr

In solr i have a multiValued field called animal and it has the values {cat,dog} is it possible to get the number of values inside the multiValued field in solr(in my example 2)?
If you want to count the items in a multivalued field use CountFieldValuesUpdateProcessorFactory
There is no direct way to get the count of items in a multivalued field.
You can always maintain the field count during indexing and use it.
If not using during query time, you can always count the list size.

Solrj Query Dynamic Field

In Solrj (Solr 3.6), am I able to filter my search for a dynamic field:
params.set("fl", "name*_s");
Or do I still need to copy this field to a new field (non-dynamic) in order to search it?
Thank you in advance.
params.set("fl", "name*_s");
I don't think you can do this in 3.6. At least, the patch is labelled as "Fix Version/s: 4.0"
Now, you can still retrieve a value from a specific dynamic field, like "name123_s" by naming it directly.
But I'm not sure if I'm answering the right question, as "fl" isn't involved in filtering, or searching. "fl" is the list of stored fields to return.
If you want to search multiple fields, you should look at the "qf" parameter of the edismax query parser.

How to find if a document starts with a given term in solr?

I have a solr index with indexed text.
I'd like to query documents that start with a certain term.
I didn't find a way to do that with the lucene or dismax query parser.
Is there a way to do that?
A solution I thought of is to index the strings with a special token at the beginning of each line, i.e: "STARTOFTEXT" and then query for "STARTOFTEXT something".
Is there a nicer solution?
What about making a field in the schema that contains the first word? Then when when you build the document you can grab the first word and store it separately from the rest of the text.

Resources