finding matches for part words in SOLR - solr

I have a field with value of "holmes#sible.com"
I want get back this field If I search for "sible".
I use ngrams filter, which would help only if the string was "sible#holmes.com"
Which filters/tokenizers should I use for such a thing (pretty much the LIKE in sql).

EdgeNGramFilterFactory would help only if the string was "sible#holmes.com" but NGramFilterFactory will get what you want with "holmes#sible.com" too.

Related

SOLR: Fuzzy search on a text field with spaces

Here's my problem: I have a single text field that is indexed by SOLR, which is the usernames from our database. I'd like the search to be fuzzy and not an exact match. Eg; if the username is "krishnarayaprolu" and I search with a spelling mistake "krishnIrayaprolu", it should still return the record.
This is working fine for me except when the usernames have a space in them. So a username: "krishna rayaprolu", and a search string "krishnI rayaprolu~0.5" is not returning the record. It is returning fine if the spelling mistake is at the end like "krishna rayaprolI~0.5". Any ideas?
For my config, I tried WhiteSpaceTokenizerFactory and StandardTokenizerFactory. On the search side, I tried quotes and escaping the space. None of them helped with my space+fuzziness problem. I'm using the admin interface for searching. Appreciate any pointers.
I have solution for your problem, only need to add some fields in your schema.
Create new ngram field and copy all you title name in ngram field.
When you fire any query for missspell word and you get blank result then split
the word and again fire the same query you will get results as expected.
Example : Suppose user searching for word "krishna rayaprolu" but type it as "krishnI rayaprolu~0.5", then
create query in below way you will get results as expected hopefully.
**(ngram:"krishnI rayaprolu~0.5" OR ngram:"kri" OR ngram:"kris" OR ngram:"krish" OR ngram:"krishn" OR ngram:"krishnI" OR ngram:"ray" OR ngram:"raya" OR ngram:"rayap" ..... )**
We have split the word sequence wise and fire query on field ngram.
Hope it will help you.

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.

Using solr shingle filter at query time

I am trying to build a field in my Solr Schema which will be able to join words together at query time and then search for this new joined word in the index.
Lets say I have the word "bluetooth" in my index and I want this to come up in results when I search "blue tooth".
So far I have been unsuccessful in trying varying combinations of shinglefilterfactory and positionfilterfactory as well as keyword, standard and whitespace tokenizers.
I'm hoping someone might be able to point me in the right direction to solve this!
Your goal is looking obscure to me and strange a little bit. But for your specific use-case the following filter can be used:
"solr.PatternReplaceCharFilterFactory"
"pattern"="[\\W]"
"replacement"=""
It will make "blue tooth" to be replaced into "bluetooth". And also you can specify that field-analysis for query-time only.
But let me tell you that usually tokenization is used instead of concatenation. And let me also offer you the following filter - WordDelimiterFilter. In such case this guy can split "BlueTooth" into "blue" and "tooth" based on cases.

Search if not contains in SOLR?

I have a Some String in SOLR "Starting User","Ending User","Friend"
etc... I want to see the results no having user
I tried -t1:*User* but it is not bringing appropriate result.
If t1 is defined as type string, and you indexed the data "You are good boy", and you search with good/boy - you will not get any results. You have to use complete phrase
Solution is, use "text_general" for t1. So then when you index above phrase, it will be tokenized as you, are, good,boy etc and will return results when you search with good/boy
Please try to understand how analyzers, tokenizer and filters work during indexing and searching. happy Learning

Solr query results using *

I want to provide for partial matching, so I am tacking on * to the end of search queries. What I've noticed is that a search query of gatorade will return 12 results whereas gatorade* returns 7. So * seems to be 1 or many as opposed to 0 or many ... how can I achieve this? Am I going about partial matching in Solr all wrong? Thanks.
First, I think Solr wildcards are better summarized by "0 or many" than "1 or many". I doubt that's the source of your problem. (For example, see the javadocs for WildcardQuery.)
Second, are you using stemming, because my first guess is that you're dealing with a stemming issue. Solr wildcards can behave kind of oddly with stemming. This is because wildcard expansion is based by searching through the list of terms stored in the inverted index; these terms are going to be in stemmed form (perhaps something like "gatorad"), rather than the words from the original source text (perhaps "gatorade" or "gatorades").
For example, suppose you have a stemmer that maps both "gatorade" and "gatorades" to the stem "gatorad". This means your inverted index will not contain either "gatorade" or "gatorades", only "gatorad". If you then issue the query gatorade*, Solr will walk the term index looking for all the stems beginning with "gatorade". But there are no such stems, so you won't get any matches. Similarly, if you searched gatorades*, Solr will look for all stems beginning with "gatorades". But there are no such stems, so you won't get any matches.
Third, for optimal help, I'd suggest posting some more information, in particular:
Some particular query URLs you are submitting to Solr
An excerpt from your schema.xml file. In particular, include A) the field elements for the fields you are having trouble with, and B) the field type definitions corresponding to those fields
so what I was looking for is to make the search term for 'gatorade' -> 'gatorade OR gatorade*' which will give me all the matches i'm looking for.
If you want a query to return all documents that match either a stemmed form of gatorade or words that begin with gatorade, you'll need to construct the query yourself: +(gatorade gatorade*). You could alternatively extend the SolrParser to do this, but that's more work.
Another alternative is to use NGrams and TokenFilterFactories, specifically the EdgeNGramFilterFactory. .
This will create indexes for ngrams or parts of words. Documents, with a min ngram size of 5 and max ngram size of 8, would index: Docum Docume Document Documents
There is a bit of a tradeoff for index size and time. One of the Solr books quotes as a rough guide: Indexing takes 10 times longer Uses 5 times more disk space Creates 6 times more distinct terms.
However, the EdgeNGram will do better than that.
You do need to make sure that you don't submit wildcard character in your queries. As you aren't doing a wildcard search, you are matching a search term on ngrams(parts of words).
My guess is the missing matches are "Gatorade" (with a capital 'G'), and you have a lowercase filter on your field. The idea is that you have filters in your schema.xml that preprocess the input data, but wildcard queries do not use them;
see this about how Solr deals with wildcard queries:
http://solr.pl/en/2010/12/20/wildcard-queries-and-how-solr-handles-them/
("Solr and wildcard handling").
From what I've read the wildcards only matched words with additional characters after the search term. "Gatorade*" would match Gatorades but not Gatorade itself. It appears there's been an update to Solr in version 3.6 that takes this into account by using the 'multiterm' field type instead of the 'text' field.
A better description is here:
http://bensch.be/the-solr-wildcard-problem-and-multiterm-solution

Resources