Skip to content
feiben edited this page Oct 5, 2016 · 11 revisions

In order to support the natural language search for tons of text contents, we call

String table = "sales";
String column = "feedback";
db_instance.getTable(table).addFulltextSearchable(column);  

Then records that contain the column data will be indexed.

The query language introduced by LunarBase is quite similar to the counterpart of Mysql:

String table = "sales";  
String query = "feedback against(\" keyword1, keyqord2 + keyword3\")";  
 
FTQueryResult result = l_db.queryFullText(table, query);
		
		if(result.resultCount() == 0)
		{
    			System.out.println("no results found");
    			l_db.closeDB();
    			return;
		}
		
		int top_n =1000;
		ArrayList<Record32KBytes> recs = result.fetchRecords(top_n);
				
		for(int i=0 ;i<recs.size() ;i++)
		{
    			System.out.println(recs.get(i).getID() + ": "+recs.get(i).recData());
		}

Where against is the reserved keyword of the query grammar. Comma(,), space, and plus(+) stand for the binary logical relationship among keywords respectively as: or, or, and.

The search results is kept in an object of FTQueryResult , whose major interfaces are:

resultCount(): how many results falling into the range;  
fetchRecords(): get all the results as a list;
fetchRecords(int top_n): get the top n results;  
fetchRecords(int from, int count): paging the results, for rendering them on each page of screen;  

For natural languages other than English, user shall implement its own tokenizer that parses the text into entities, words, names etc. Following this complete example of full-text search to learn how to do it.

Clone this wiki locally