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
Related
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%
Purpose: To build a dictionary (Sample Dictionary taken from Gutenberg project). This application should have the capability to return the "word" is part of the meaning is provided. Example:
CONSOLE
Con*sole", v. t. [imp. & p.p. Consoled; p.pr. & vb.n. Consoling.]
Etym: [L. consolari,. p.p. consolatus; con- + solari to console, comfort: cf. F. consoler. See Solace.]
Defn: To cheer in distress or depression; to alleviate the grief and raise the spirits of; to relieve; to comfort; to soothe. And empty heads console with empty sound. Pope. I am much consoled by the reflection that the religion of Christ has been attacked in vain by all the wits and philosophers, and its triumph has been complete. P. Henry.
Syn. -- To comfort; solace; soothe; cheer; sustain; encourage; support. See Comfort.
So if my query is "To cheer in distress", it should return me "Console" as the output.
Am trying to build this tool using Lucene 5.5 (lower versions won't do for now). This is what I tried:
Indexing:
Document doc = new Document();<br>
doc.add(new Field(MEANING, meaningOfWord, Store.YES, Field.Index.ANALYZED));<br>
doc.add(new Field(WORD, word, Store.YES, Field.Index.ANALYZED));<br>
indexWriter.addDocument(doc);<br>
Analyzing:
Analyzer analyzer = new WhitespaceAnalyzer();<br>
QueryParser parser = new QueryParser(MEANING, analyzer);<br>
parser.setAllowLeadingWildcard(true);<br>
parser.setAutoGeneratePhraseQueries(true);<br>
Query query = parser.parse(".*" + searchString + ".*");<br>
TopDocs tophits = isearcher.search(query, null, 1000);<br>
This (tophits) is not returning me what I want. (I have been trying Lucene from last week or so, so please excuse if this is very naive). Any clues?
Sounds like a different analyzer was used when the documents were indexed. Probably KeywordAnalyzer or something. You (usually) need to pass the same analyzer to IndexWriter when indexing your documents as the one you will use when searching. Also, bear in mind, after correcting the IndexWriter's analyzer, you will need to reindex your documents in order for them to be indexed correctly.
Wrapping what should be a simple phrase query in wildcards is a extremely poor substitute for analyzing correctly.
Found the solution, use WildCardQuery, like this:
WildcardQuery wildCardQ = new WildcardQuery(new Term(MEANING, searchString));
But for incorrect words/phrases, it sometimes takes long time to come back with the answer.
I am using websockets , nodejs v0.10.12 and also PostgreSQL 9.1, with PostGIS 2.0.
Now, on websockets, on the server side, in order to gather textual data and send them to the client I perform a query using node's pg plugin.
I have something like
var query = client.query('SELECT p_name,p_date FROM pins WHERE p_id ='+ja)
//send them and render in client as html
query.on("row", function (row, result) {result.addRow(row);});
query.on("end", function (result) {
for (var i=0; i<result.rows.length; i++){
connection.send(
'Name</br>'
+result.rows[i].p_name+
'</br>Date</br>'
+result.rows[i].p_date+
'</br>'
}
client.end();
});
Now, here is the tricky part. I want to render the date like 25/02/2012.
With the above code, I get Sat Feb 02 2002 02:00:00 GMT+0200 (Χειμερινή ώρα GTB)
To get DD/MM/YYYY I have to put a line of code like
SET datestyle = "SQL, DMY";
This is apparently PHP and I am using Javascript because I work with websockets.
The only thing I could think of is editing the above query like so
var query = client.query('SET datestyle = "SQL, DMY"; SELECT p_name,p_date FROM pins WHERE p_id ='+ja)
I dont get any errors, but on the client the date renders null.
How can I fix this?
Thanks
OK. Where to start?
This:
var query = client.query('SELECT p_name,p_date FROM pins WHERE p_id ='+ja)
is not the correct way to build a query. Used a parameterised query and protect yourself from SQL injection.
SET datestyle = "SQL, DMY";
This is apparently PHP and I am using Javascript because I work with websockets.
What? I'm trying to think of something constructive about this sentence, but the best I can think of is "What?". It is far from apparent that the above is PHP, because it isn't. The fact that you are sending it to the database ought to give you a hint that it's SQL. Also, you're not using javascript because you work with websockets. You're using javascript because you're using javascript - websockets are nothing to do with anything here.
The only thing I could think of...
Doesn't include looking in the manuals.
Go to the PostgreSQL website, click through to the documentation and manuals, and on the contents page click "Functions and Operators" and then "Data type formatting functions". Here is the link for you:
http://www.postgresql.org/docs/current/static/functions-formatting.html
You'll notice that the PostgreSQL developers not only produce extensive and detailed manuals, but they keep multiple versions online and make it simple to switch back and fore to see what's changed.
There is a whole section on this page on how to format date-times in different ways, with clear descriptions of each effect. I didn't find this using the documentation search or anything clever like that - just the obvious links on each page.
If you did a search you would find plenty on the datestyle parameter, and a little further digging would show that you can set it per-session or as a default for a given user or database.
Finally though, don't do it that way at all. Return ISO-standard date formats like #mu said (YYYY-MM-DD etc). and format them in your javascript client code.
Oh - while I'm no expert, I'm not sure that </br> is valid HTML, XHTML or XML either. Did you perhaps mean <br/>?
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 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.