Is there away to use find() to search for barcode that ends with the last digits 365478 I dont care what is in front
I thought something like this.
$db.find(array('barcode'=>*365478))
but that does not seem to work. am I missing something?
A regular expression of /365478$/ would provide the right filter.
Regex will work but you won't be able to use an index for the query. I'd suggest storing the last 6 digits in a separate field, put an index on it and use that.
This Works Well /$365478/ of course you can use regex but keeping it simple pays off.
You can use a regex for this but you have to store the barcode reversed if you want to be able to use an index (only rooted regex can use an index, see http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions)
If that is unpractical for you you will have to save the last X digits seperately and do exact matching. If your database is going to be relatively small you might be able to get away without indexing.
the regex should be like this: 365478$
using PHP for eg.
$regex = new MongoDB\BSON\Regex ( '365478$');
Related
I would like to remove all numbers in a string.
For example,
I would like to convert String into String2.
Can anyone give me a small code for this?
What have you tried so far? Below are 3 methods how to achieve it (could be even more ways of solution).
UPD: updated based on comment from sweber.
Let's say I have the word "catheter". A user tries to search on my web app for that word but spells it "cathiter" or "cattiter" instead. How can I use SphinxQL to match the word from my SQL database based on the incorrectly spelled word? What would my query look like? Do I need to enable something in my index on my conf file? From my understanding, enable_star has been deprecated.
Yes, enable_star=0 has been depreciated, but not sure how that relevant!
Anyway sounds like you want the CALL SUGGEST function
http://sphinxsearch.com/blog/2016/10/03/2-3-2-feature-built-in-suggests/
The defuult settings a good place to start...
CALL QSUGGEST('cathiter','yourindex');
... if you dont min_infix_len defined on index, will need that. Alao dict=keywords - for some reason that requirement not mentioned in blog post.
I use azure search and have some document with a field like this {"Nr": "123.334.93"}.
If i search for querytype=full&search=123.334.93 then it found multiple document and if I search for querytype=full&search="123.334.93" then it found one document. This is as expected.
But if I search for querytype=full&search=123.334.9* I expect multiple document starting with 123.334.9 but none result are given back.
Do I miss somthing?
The same is when I use a regex expression like this querytype=full&search=/123\.334\.9.*/
Your query looks correct to me and should work.
A couple of things you might look into.
1) Sometimes you need to escape the * like this:
querytype=full&search=123.334.9\*
Usually, this is only necessary if you have more search terms after the *.
2) You can also narrow the fields searched down to only the field you need (for better efficiency) like this:
querytype=full&search=Nr:123.334.9\*
Hope this helps.
Based on the Comment from Yahnoosh.
The analyzer of the field was set to "de.microsoft". I change that to "standard.lucene", recreate and fill the index and it works as expected.
It seems that I have to be more carefully to set the analyzer and only use specific ones for fields with language specific content.
Thanks for your help.
I am pretty new to Solr and I am looking for a way to port the search features I have for my web application having a regular database to use Solr indexes. My problem so far is I have to customize the wildcards behaviour: for example, "?" should be "0 or 1 characters" not any character as it is now, "+" should mean any "white-space", "#" should be any digit and so on. Any good pointer?
Thanks!
There is no simple answer that I know of, I am afraid.
For 0 or 1 characters - you can replace the original query with an 'OR' query. Eg. mp? in your db search usecase becomes - 'mp OR mp?' in Solr.
White spaces are tokenized by default in text field. So, you can look at using a white space tokenizer as part of your custom 'text' field. There are several examples. text_ws in the sample schema only does whitespace tokenizing. You'd want to readup on tokenizers.
http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters
There is no digit equivalent - you can do term1* OR term2* OR term3* ... etc. You can also use function queries that support numerical functions. http://wiki.apache.org/solr/FunctionQuery
It looks like the best choice in this case is to use regular expressions in the search. More details can be found here: http://1opensourcelover.wordpress.com/2013/09/29/solr-regex-tutorial/
It's not exactly what I was looking for as I will have to build my own solr-query on the back and I have a feeling that regular expressions abuse will create a little bit more overhead on my server. For the test I did it looks pretty fast.
I will leave the question open for a while maybe someone can come up with a better answer.
I'm using solr to search for articles. I created 2 test "body" sentences which have the common word "tall", but there is no match.
The Query---> Body:"There are tall people outside" AND !UserId:2
Does not match a post with:
Body: the KU tower is really tall
UserId:3
Is this just simply a very low matching score? or is there something else going on here? In the case of a low matching score should it really be that low? The body sentences are very short and share a common word, I would have expected some match.
EDIT: I think the matching isn't happening as a result of having the !UserId: 2 condition. If I try to match body sentences without that, its very liberal. Can anyone explain this? and perhaps how to best structure a query to avoid this type of specific behavior?
Thanks!
I have seen some funky behavior with the ! operator with Solr. I would suggest you use the - (negative indicator) instead as shown in the SolrQuerySyntax Wiki Page. Try changing your original query to Body:"There are tall people outside" AND -UserId:2 to see if that works as you are expecting.
For those who come after me, I found a solution however not necessarily an explanation for its behavior.
The Solr query:
(PostBody:There are tall people outside) AND !UserId:2
worked as I desired above. Note that if the quotes are added around the body, it does not match. I believe Solr attempts to match such a query as a single string rather than individual words.