Amazon cloudsearch: Fuzzy search by field with boto3 - lucene

How can do fuzzy search in Amazon Cloudsearch by field?
I tried it. But it's not works
cloudsearch.search(
query="1976~100",
queryParser='simple',
partial=True,
# queryOptions='{"fields":["passport_number"]}',
queryOptions='{"operators":["fuzzy"],"fields":["passport_number"]}',
returnFields="cognito_id,pk"
)
Also I tried this
cloudsearch.search(
query="(near field=passport_number '1976')",
queryParser='structured',
partial=True,
returnFields="cognito_id,pk"
)
But this not works also.

Can use lucene as query parser along with wildcards
cloudsearch.search(
query='passport_number:*1976*',
queryParser='lucene',
partial=True,
returnFields="cognito_id,pk"
)

Related

Escaping special characters & Encoding unsafe and reserved characters Lucene query syntax Azure Search

I have words "C&&K", "So`am`I" , "Ant||Man", "A*B==AB", "Ant+Man" in index of azure search.
According to Doc for Escaping special characters + - && || ! ( ) { } [ ] ^ " ~ * ? : \ / I need to prefixing them with backslash (\) And for unsafe and reserved characters need to encode them in URL.
for "C&&K" my search url => /indexes/{index-name}/docs?api-version=2017-11-11&search=C%5C%26%5C%26K~&queryType=full
for "So`am`I" my search url => /indexes/{index-name}/docs?api-version=2017-11-11&search=So%5C%60am%5C%60I~&queryType=full
for "Ant||Man" my search url => /indexes/{index-name}/docs?api-version=2017-11-11&search=A%5C*B%3D%3DAB~&queryType=full
for "A*B==AB" my search url => /indexes/{index-name}/docs?api-version=2017-11-11&search=A%5C*B%3D%3DAB~&queryType=full
for "Ant+Man" my search url => /indexes/{index-name}/docs?api-version=2017-11-11&search=Ant%5C%2BMan~&queryType=full
For all off them I do not get search result. I get "value": []
for "C&&K" I have also tried
url => /indexes/{index-name}/docs?api-version=2017-11-11&search=C%5C%26%26K~&queryType=full
url => /indexes/{index-name}/docs?api-version=2017-11-11&search=C%26%5C%26K~&queryType=full
for "So`am`I" I have also tried
url => /indexes/{index-name}/docs?api-version=2017-11-11&search=So%60am%60I~&queryType=full
It does not work. What am I doing wrong here?
With standard analysis, all of these would be indexed as multiple terms. Fuzzy queries, however, are not analyzed, so it will attempt to find it as a single term. That is, when you index "Ant||Man", after analysis, you end up with the terms "ant" and "man" in the index. When you search for Ant||Man, it will analyze it in much the same way as at index time, but when searching for Ant||Man~, the query won't be analyzed, and since no terms like that exist in the index, you won't get any matches. Similarly, for "A*B==AB" you get the terms "b" and "ab" ("a" is a stop word with default analysis).
So, try the queries without the ~.
In addition to femtoRgon's response, you may want to consider using a custom analyzer that does not index these as multiple terms if you would always like them to be searchable as they are. There is documentation on custom analyzers here, and you can use the Analyze API to test to make sure a given analyzer works as you expect.

How to search prefix with "-" in aws structured query

I am working with amazon cloud search api. I am using "prefix" operator to search and it's working fine at some level.
Working Copy:
AWSURL/search?q=
(and
(and searchtype:'Event' server:1 )
( and
( or eventownerid:70 eventcreatedbyuserid:70 )
)
(prefix 'event')
)&size=10&q.parser=structured
Non Working / issue
AWSURL/search?q=
(and
(and searchtype:'Event' server:1 )
( and
( or eventownerid:70 eventcreatedbyuserid:70 )
)
(prefix 'event-1')
)&size=10&q.parser=structured
When I passed search term with "-" it stop giving result.
I have also tried url.Encoded for special charter but no luck with that as well.
What to do to include "-" in prefix ?
Is there any way where i can search with any part of word in all
columns of document. for example the field contain text "this is
GreatSearchTech", I want this in result when i pass "Search" as
search term / word. ?
Thank you in advance.

Using Wildcard Sql for searching a word in a TextField

To make it clearer I have this fields
Columntobesearch
aword1 bword1
aword2 bword2
aword3 bword4
Now what I want to do is search using the sql wild card so what I did is like this
%searchbox%
I placed to wildcards on both ends of my search but what it searches is just the first word on the field
when I search 'aword' all of the fields is showing but when I search 'bword' nothing is showing, Please help.
Here is my Full Code
$Input=Input::all();
$makethis=Input::flash();
$soptions=Input::get('soptions');
$searchbox=Input::get('searchbox');
$items = Gamefarm::where('roost_hen', '=',Input::get('sex'))
->where($soptions, 'LIKE','%' . $searchbox . '%')
->paginate(12);
If you use mysql you can try this:
<?php
$q = Input::get('searchbox');
$results = DB::table('table')
->whereRaw("MATCH(columntobesearch) AGAINST(? IN BOOLEAN MODE)",
array($q)
)->get();
Ofcourse you need to prepare your table for full text search in your migration file with
DB::statement('ALTER TABLE table ADD FULLTEXT search(columntobesearch)');
Any way, this is not the more scalable nor efficient way to do FTS.
For a scalable and reliable full text search I strongly recommend you see elasticsearch and implement any Laravel package to this task

FullText contains word and not part of a word

I have a full-text index over a list of urls;
http://example.com:8080/Api
http://example.com:8080/Api/CustomController
http://example.com:8080/
And I am trying to search with a full-text in SQL
SELECT * FROM urls WHERE CONTAINS(urls.Url, '"http://localhost:8080/"')
But that gives me;
http://example.com:8080/Api
http://example.com:8080/Api/CustomController
http://example.com:8080/
when I only want
http://example.com:8080/
How can I do this? I still need the capabilities that CONTAINS offers, like the OR, AND and *-wildcard
You cannot perform an exact match with contains.
You could rewrite your query as such:
SELECT * FROM urls WHERE urls.Url = 'http://localhost:8080/'
OR CONTAINS(...)

"Searching" a string on a MongoDB DB with MongoMapper

I'm making a webapp where I'm using MongoMapper and Sinatra. I wonder how could I implement a search feature against a DB's collection. I though something like SQL's:
SELECT * FROM posts WHERE match(title) against ("String to search");
How could I achieve this with MongoMapper? Thanks!
ok this is from my project and does work:
Post.where(:title => Regexp.new(/^string/i)) # Limit output with: .limit(10)
Maybe it's the Regexp?
You query for documents that match a case sensitive rooted regular expression:
Post.where(:title => /^stringtosearch/).first
MongoDB does not support full text search so this is the best you can do at the moment.