What is the proper syntax for using wildcards with quotes in a SOLR query string? - solr

I'm trying to structure a query string in SOLR that will search a field for a term in quotation marks, but I want it to return substring matches. As an example:
query: "his test"
should return hits where it finds "his test", "this test", "his testing", but not "test his" for example. Does this make sense? What's the right way to construct the URL to hit /solr/select/ ?
Thanks!

to accomplish your example, just turn on an english stemmer and stopword filter in your analysis chain. the stopword filter will leave a "hole" (position increment) which will be respected by phrase queries, so "his" and "this" both map to a hole.
the stemfilter will map testing and test to the same term.
Uwe says:
There is a simple Lucene-Rule: Whenever you need wildcards think about your analysis, you probably did something wrong :-)

Your query should looks in standard way, except you need wildcard in it.
If you want to add wildcard at the beginning of the term you would need ReversedWildcardFilterFactory in the schema. Check out schema example (lines: 332-346)
For more info about how Solr with wildcards work read short article: Wildcard queries and how Solr handles them

Related

SOLR boost query with contain syntax

in my solr call i want to boost all queries that have the word "mobile" in the longtext.
My call looks like this:
&q=*my_query*&defType=edismax&qf=xtitleLow_stringS^20++xartnumLow_stringS&ps=2&bq=xtitleLow_stringS:(*mobile*)^40
when i use the Boost query like this:
&bq=xtitleLow_stringS:"mobile"^40
it will work for fulltext but i just want to boost a query that contains it. I thought i can use the "*" contain to especially search for it. But it doesen't work, is there a mistake in my syntax?
thank you!
The syntax of the boost query seems incorrect in my opinion.
The "*" wildcard can only be used in a query when preceded by the word "text".
e.g. &bq=xtitleLow_stringS:text:mobile^40
To boost all queries that contain the word "mobile", you can write as:
&bq=xtitleLow_stringS:mobile^40
This should boost any query that contains the word "mobile" in the xtitleLow_stringS field by 40 factor.

Solr syntax for phrase query

I have a field with definition:
"replace-field": {
"name":"search_words",
"type":"lowercase",
"stored":true,
"indexed": true,
"multiValued": true
}
that contains sentences as array (thus multiValued: true):
"id":500
"search_words":["How much oil should you pour into the engine",
"How important is engine oil?]
How should I create a query thatwould return that document (with id = 500) when user inputs phrase "engine oil"?
With single term queries I can user *engine* and it would find that document becasue engine is in the middle of the sentence but I can't find a way to be able to seearch for phrases in sentences. Is it even possible using solr?
Solr supports phrase search, and is what it was actually designed for. Wildcard searches are not really the way you should use Solr by default - the field type should tell Solr how to process the text in the field to make you get hits when querying it in a regular way.
In this case the standard text_en would probably work fine, or a field definition with a Standard Tokenizer and a lowercasefilter (and possibly a WordDelimiterGraphFilter to get rid of special characters).
The query would then be search_words:"engine oil".

how to do solr search including sepcial characters like (-,&.. etc)?

I need to do solr search for a string like BEBIL1407-GREEN with special character(-) but it is ignoring - and searches for only with BEBIL1407. I need to search with a hole word.Im using solr_4.5.1
Example Query :
q=BEBIL1407-GREEN&qt=select&start=0&rows=24&fq=clg%3A%222%22&fq=isAproved%3A%22Y%22&fl=id
Your question is about searching for BEBIL1407-GREEN but finding BEBIL1407.
You did not post your schem or your query parser.
As default solr using the standard query parser on field "text" with fieldtype "text_general".
You can test with the solr analysis screen the way from a word (in real text) to the corresponding token in the index.
For "text_general" the word "BEBIL1407-GREEN" goes to two token: "bebil1407" and "green".
The Standard-Parser does support escaping of special characters this would help if your word starts with a hyphen(minus sign). But in this case most possible the tokenizer is the reason of "finding unexpected documents".
Solution:
You can search with a phrase. In this case "BIBIL1407-GREEN" will also find "BIBIL1407 GREEN"
You can use an other FieldType e.g. one with WhiteSpaceTokenizer
Hope this helps, otherwise post your search field and your definition from schema.xml...

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

How to configure SOLR queries in the conf files

My requirement is simple.
I need to search with the keyword similar to SQL LIKE.
Now the search shows results for "words" rather than checking partial characters.
Ex:-
Search query: "test"
Expected results: "test%" - Which gives "test", "tested",
"testing", etc...
Actual result: "test"
I found many query suggestions for SOLR. But I need to find the exact mechanism to put that on conf xml files.
Thanks in advance.
The quick and dirty solution is to use wildcard in your search query using an asterisk (*). For example: test*
The more proper solution would be to use stemming to remove common word endings when you index and query the data. In the default schema, the text_en_splitting field type would do this for you. Just define your field as text_en_splitting.
Are you building auto-complete?
If so, use Suggester. It's part of Solr, and it does what you're talking about extremely efficiently using either a dictionary file, or a field in your index you've designated.
http://wiki.apache.org/solr/Suggester

Resources