Friday 15 June 2012

java - I am storing text file in a mongodb and i want to perform search operations on content of a file. Is mongodb support content search of file? -



java - I am storing text file in a mongodb and i want to perform search operations on content of a file. Is mongodb support content search of file? -

i have created java application , through able insert file in mongodb , want perform content search on it.

here file insertion code.

import java.io.file; import com.mongodb.db; import com.mongodb.mongoclient; import com.mongodb.gridfs.gridfs; import com.mongodb.gridfs.gridfsdbfile; import com.mongodb.gridfs.gridfsinputfile; public class testfileinsert { public static void main(string[] args){ try{ // create connection mongodb mongoclient mongoclient = new mongoclient("localhost",27017); db db = mongoclient.getdb( "temp" ); system.out.println("connect database successfully"); // insert file mongo db using grid fs string newfilename = "tssmessage"; file newfile = new file("/home/n.dat"); gridfs gfsphoto = new gridfs(db, "test"); gridfsinputfile gfsfile = gfsphoto.createfile(newfile); gfsfile.setfilename(newfilename); gfsfile.save(); system.out.println("text file inserted successfully"); // file in database string getfilename = "tssmessage"; gridfs gfsphoto1 = new gridfs(db, "test"); gridfsdbfile imageforoutput = gfsphoto1.findone(getfilename); system.out.println(imageforoutput); } catch(exception e){ system.err.println( e.getclass().getname() + ": " + e.getmessage() ); } } }

how can perform content search in database?

your files seem images. content analysis of images hard problem. , mean very, hard. there progress on corner applications (text recognition, biometric face recognition...) the universal image identification algorithm can recognize image human brain can still unsolved problem of computer science , remain foreseeable future. , mongodb isn't trying provide solution sector.

but much simpler case, let's text file search, mongodbs gridfs not best tool.

when files text-based, seek create text index on fs.chunks collection, in collection each file stored multiple separate documents, each 1 (by default) 255kbyte of data. when info searching happens across chunk boundary, won't help much.

however, have ability query files metadata store them. depending on want do, extract relevant search terms files before store them , store these search terms in metadata.

java mongodb full-text-search

No comments:

Post a Comment