java - Multiple attribute queries in Apache Lucene -
the below program satisfies query title has both lucene , action. if want search tupple isbn (considering isbn not unique) 1234 , title contains both lucene , dummies. lucene provide facility that.
standardanalyzer analyzer = new standardanalyzer(version.lucene_40); directory index = new ramdirectory(); indexwriterconfig config = new indexwriterconfig(version.lucene_40, analyzer); indexwriter w = new indexwriter(index, config); adddoc(w, "lucene in action", "193398817"); adddoc(w, "lucene dummies", "55320055z"); adddoc(w, "managing gigabytes", "55063554a"); adddoc(w, "the art of computer science", "9900333x"); w.close(); private static void adddoc(indexwriter w, string title, string isbn) throws ioexception { document doc = new document(); doc.add(new textfield("title", title, field.store.yes)); doc.add(new stringfield("isbn", isbn, field.store.yes)); w.adddocument(doc); } string querystr = args.length > 0 ? args[0] : "lucene , action"; query q = new queryparser(version.lucene_40, "title", analyzer).parse(querystr);
from top of head , queryparser
class built query title
field only, in order make query targets both title
, isbn
fields have make use of class multifieldqueryparser
, query title:(lucene , dummies) , isbn:1234
or build booleanquery
(this end with) hand multiple termquery
objects .
i hope helps
Comments
Post a Comment