I have been trying to implement fuzzy search in redis search, redis om with node js.
I've gone through articles like this but I have not managed to fix it.
This is my code sample of the search that I am currently implementing.
let searchResults = await repository.search()
.where("country").equal(correctCountry)
.where("city").equal(city.toLocaleLowerCase())
.and("descriptionAndStreet")
.matches(placedescription + "*").return.page(0, 20)
I would like to implement fuzzy search when searching the "placedescription".
Any assistance would be greatly appreciated.
Found the solution
Redis OM does not have a fluent interface for fuzzy matching. However, you can always do a raw search (https://github.com/redis/redis-om-node/#running-raw-searches) and pass in pretty much any query you want:
let query = `#country:{${correctCountry}} #city:{${city}} #descriptionAndStreet:%Whatyouwanttosearch%`
let places = await placeRepository.searchRaw(query).return.page(0, 10)
If you want to search with more than one word, ie space separated
let query = `#country:{${correctCountry}} #city:{${city}}
#descriptionAndStreet:%What% %you% %want% %to% %search%`
If you get issues with that you can try removing the spaces in between
%What%%you%%want%%to%%search%
Related
I am working with Google Cloud Datastore using the latest google.cloud.ndb library
I am trying to implement pagination use Cursor using the following code.
The same is not fetching the data correctly.
[1] To Fetch Data:
query_01 = MyModel.query()
f = query_01.fetch_page_async(limit=5)
This code works fine and fetches 5 entities from MyModel
I want to implementation pagination that can be integrated with a Web frontend
[2] To Fetch Next Set of Data
from google.cloud.ndb._datastore_query import Cursor
nextpage_value = "2"
nextcursor = Cursor(cursor=nextpage_value.encode()) # Converts to bytes
query_01 = MyModel.query()
f = query_01.fetch_page_async(limit=5, start_cursor= nextcursor)
[3] To Fetch Previous Set of Data
previouspage_value = "1"
prevcursor = Cursor(cursor=previouspage_value.encode())
query_01 = MyModel.query()
f = query_01.fetch_page_async(limit=5, start_cursor=prevcursor)
The [2] & [3] sets of code do not fetch paginated data, but returns results same as results of codebase [1].
Please note I'm working with Python 3 and using the
latest "google.cloud.ndb" Client library to interact with Datastore
I have referred to the following link https://github.com/googleapis/python-ndb
I am new to Google Cloud, and appreciate all the help I can get.
Firstly, it seems to me like you are expecting to use the wrong kind of pagination. You are trying to use numeric values, whereas the datastore cursor is providing cursor-based pagination.
Instead of passing in byte-encoded integer values (like 1 or 2), the datastore is expecting tokens that look similar to this: 'CjsSNWoIb3Z5LXRlc3RyKQsSBFVzZXIYgICAgICAgAoMCxIIQ3ljbGVEYXkiCjIwMjAtMTAtMTYMGAAgAA=='
Such a cursor you can obtain from the first call to the fetch_page() method, which returns a tuple:
(results, cursor, more) where results is a list of query results, cursor is a cursor pointing just after the last result returned, and more indicates whether there are (likely) more results after that
Secondly, you should be using fetch_page() instead of fetch_page_async(), since the second method does not return you the cursors you need for pagination. Internally, fetch_page() is calling fetch_page_async() to get your query results.
Thirdly and lastly, I am not entirely sure whether the "previous page" use-case is doable using the datastore-provided pagination. It may be that you need to implement that yourself manually, by storing some of the cursors.
I hope that helps and good luck!
I have been using JavaMail quite for sometime to develop a simple Mail application. I have also developed a simple search facility using SearchTerm concept in JavaMail. I wanted to search emails by sender, recevier, date, content or subject. So, I have the following sample SearchTerm combinations for the above parameters:
SearchTerm searchSenderOrSubjectTerm = new OrTerm(termSender, termSub);
SearchTerm searchSenderOrDate = new OrTerm(termSender, termRecvDate);
SearchTerm searchSubjectOrSenderOrDate = new OrTerm(searchSenderOrSubjectTerm, searchSenderOrDate);
SearchTerm searchSubjectOrContentOrSenderOrDate = new OrTerm(searchSubjectOrSenderOrDate, termContent);
SearchTerm searchSubjectOrContentOrSenderOrRecvrOrDate = new OrTerm(searchSubjectOrContentOrSenderOrDate, termRecvr);
//return the search results
searchResults = folder.search(searchSubjectOrContentOrSenderOrRecvrOrDate);
This is working fine and returns the required results. But the problem with this approach is that it is taking too much time to search and return the results. I was just wondering whether the problem is the internal SearchTerm implementation or from the above approach. So, can you guys share me your experience on this especially on the performance issue? This is taking too much time and I am not exactly sure where the problem is.
regards,
If you're using IMAP, the searching is all done on the server, so the performance depends on the server. If you're using POP3, the searching is done by downloading all the messages to the client and searching there. Use IMAP. :-)
You can simplify your search by using a single OrTerm with an array of all the other terms. I don't know if that will make any performance difference, however.
Unless you use Google's IMAP extensions, you are applying the search criteria locally.
To search on the server with JavaMail, you'll want to do something like this:
GmailStore store = (GmailStore) session.getStore("gimap");
store.connect("imap.gmail.com", "[your-account#gmail.com", "[your-pw]");
GmailFolder inbox = (GmailFolder) store.getFolder("[Gmail]/All Mail");
inbox.open(Folder.READ_ONLY);
Message[] foundMessages = inbox.search(new GmailRawSearchTerm("to:somebody#email.com"));
A more complete example here: http://scandilabs.com/technology/knowledge/How_to_search_gmail_accounts_via_JavaMail_and_IMAP
I cannot search the twitter API for tweets which contain one of multiple tags.
Like: q="#tag1 OR #tag2 OR #tag3"
If I leave away the hashes and only search for words, the OR-ing works. For tags they don't.
When I only use spaces, the search terms will be AND-ed, what shrinks the result...
I use the twitter4j library with:
Twitter rest = new TwitterFactory().getInstance();
Query query = new Query();
query.setQuery("#win | #fail");
QueryResult result = rest.search(query);
Isn't it possible, or didn't i use it correctly?
Might just be easier to use twitter's REST API. You'll want to use the search query. Here's an example search url searching for #LA, #NYC or #Boston. Note the spaces and #s are all URL encoded. Just pop a URL like that into a getJSON call like below and you can easily extract your values from the returned JSON object as in the example.
var requestedData = "http://search.twitter.com/search.json?q=%23LA%20OR%20%23NYC%20OR%20%23Boston%22&callback=?"
$.getJSON(requestedData,function(ob)
{
var firstTweet = ob.results[0].text;
var firstTweeter = ob.results[0].from_user;
}
From there it's just a matter of looping through your results and pulling the appropriate fields which are all outlined in the JSON file if you simply visit that example search link in your browser! I don't know this TwitterFactory API but its possible they haven't updated to Twitter's new API or they're just not URL encoding appropriately. Good luck!
Try to use OR operator instead of "|":
query.setQuery("#win OR #fail");
See available Twitter search API operators here:
Using the Twitter Search API
I'd like to create a gql query through my browser dashboard to easily look up specific entries, i.e. something like:
SELECT * FROM MyEntity where mString = "SpecificEntity"
but I can't quite get the syntax right. I see a lot of examples using parameter binding/substitution (not sure what it is called), but I don't know how to simply just write it directly without getting an error when I try to query. Any help?
Update: This was for Python (and answered nicely already).
Some (python) examples from here:
query = GqlQuery("SELECT * FROM Song WHERE composer = 'Lennon, John'")
query = GqlQuery("SELECT __key__ FROM Song WHERE composer = :1", "Lennon, John")
query = GqlQuery("SELECT * FROM Song WHERE composer = :composer", composer="Lennon, John")
When in the App Engine dashboard, you have to use single quotes.
SELECT * FROM MyEntity where mString = "SpecificEntity"
Becomes
SELECT * FROM MyEntity where mString = 'SpecificEntity'
What sort of error do you get? These are easy to find in the application log (if you've uploaded it) and should tell you what's wrong.
Since you haven't given me a specific example (alongwith your entity structure) all I can point you to is the GQL reference.
I am trying to use Tweetsharp to do a search on twitter for specific keywords but I want to do a search on multiple keywords. The following code works but only for one keyword. Anyone would know how to do an "or" search with tweetsharp?
ITwitterLeafNode searchQuery = FluentTwitter.CreateRequest()
.Search().Query()
.ContainingHashTag("heart")
.Since(sinceID)
.InLanguage("EN")
.Take(tweetCount)
.AsJson();
var results = searchQuery.Request().AsSearchResult();
Twitter's standard search operators seem to work fine with TweetSharp, so you could use the Containing() method instead:
var qry = FluentTwitter.CreateRequest()
.Search().Query()
.Containing("#heart OR #soul");
Note that the "OR" needs to be in capitals.
Whoops. Looks like we forgot to implement OR. Most people use "Containing" as a rote query expression like Matt has demonstrated. If you want us to add more extensions for boolean operators, let us know by filing a bug.