WildcardQuery error in lucene query (Memo)

Source: Internet
Author: User

I tested the multi-field structure query. The Code is as follows:

Try {long start = system. currenttimemillis (); directory DIC = new simplefsdirectory (new file (ilucenemanager. default_region_lucene_index_path); indexsearcher searcher = new indexsearcher (DIC); // ---------- set similarity // searcher. setsimilarity (New iksimilarity (); // ----------- the standardanalyzer analyzer tested for multi-field query is faster than ikanalyzer. analyzer = new standardanalyzer (version. lucene_current); // analyzer = new Ikanalyzer (true); string [] fields = new string [] {"name", "username", "weight", "standardname", "Address "}; multifieldqueryparser multiqparser = new multifieldqueryparser (version. lucene_current, fields, analyzer); // ---------- keyword string keyword = "? Fu "; query = multiqparser. parse (keyword); // ------------ query // searcher. search (query, receivemanagerimpl. default_query_num); topdocs tops = searcher. search (query, 10); scoredoc [] scores = tops. scoredocs; int length = tops. totalhits; For (INT I = 0; I <(length> extends emanagerimpl. default_query_num? Receivemanagerimpl. default_query_num: length); I ++) {document targetdoc=searcher.doc(scores[ I #.doc); // system. out. println (targetdoc. getfields ("name") [0]. stringvalue (); // system. out. println (targetdoc. getfields ("Address") [0]. stringvalue (); // system. out. println (targetdoc. get ("name"); system. out. println (targetdoc. get ("Address"); system. out. println (targetdoc. get ("username"); system. out. println (targetdoc. get ("name") ;}; long end = system. currenttimemillis (); system. out. println ("total search time:" + (end-Start) + "millisecond ");

My search keyword is: "? Government ". The error message is as follows:

Org. Apache. Lucene. queryparser. parseexception: cannot parse '? Fu ':' * 'or '? 'Not allowed as first character in wildcardqueryat Org. apache. lucene. queryparser. queryparser. parse (queryparser. java: 187) at com. geostar. test. poi. dao. receivemanagertest. testmultiplefieldquery (receivemanagertest. java: 79) at Sun. reflect. nativemethodaccessorimpl. invoke0 (native method) at Sun. reflect. nativemethodaccessorimpl. invoke (nativemethodaccessorimpl. java: 39) at Sun. reflect. delegatingmethodaccessorimpl. Invoke (delegatingmethodaccessorimpl. java: 25) at java. lang. reflect. method. invoke (method. java: 597) at Org. springframework. test. context. junit4.springtestmethod. invoke (springtestmethod. java: 160) at Org. springframework. test. context. junit4.springmethodroadie. runtestmethod (springmethodroadie. java: 233) at Org. springframework. test. context. junit4.springmethodroadie $ runbeforesthentestthenafters. run (springmethod Roadie. java: 333) at Org. springframework. test. context. junit4.springmethodroadie. runwithrepetitions (springmethodroadie. java: 217) at Org. springframework. test. context. junit4.springmethodroadie. runtest (springmethodroadie. java: 197) at Org. springframework. test. context. junit4.springmethodroadie. run (springmethodroadie. java: 143) at Org. springframework. test. context. junit4.springjunit4classrunner. invoketestmethod (Springjunit4classrunner. java: 160) at Org. JUnit. internal. runners. junit4classrunner. runmethods (junit4classrunner. java: 51) at Org. JUnit. internal. runners. junit4classrunner $ 1.run( junit4classrunner. java: 44) at Org. JUnit. internal. runners. classroadie. rununprotected (classroadie. java: 27) at Org. JUnit. internal. runners. classroadie. runprotected (classroadie. java: 37) at Org. JUnit. internal. runners. junit4classrunner. R UN (junit4classrunner. java: 42) at Org. springframework. test. context. junit4.springjunit4classrunner. run (springjunit4classrunner. java: 97) at Org. eclipse. jdt. internal. junit4.runner. junit4testreference. run (junit4testreference. java: 49) at Org. eclipse. jdt. internal. JUnit. runner. testexecution. run (testexecution. java: 38) at Org. eclipse. jdt. internal. JUnit. runner. remotetestrunner. runtests (remotetestrunner. java: 467) At Org. eclipse. jdt. internal. JUnit. runner. remotetestrunner. runtests (remotetestrunner. java: 683) at Org. eclipse. jdt. internal. JUnit. runner. remotetestrunner. run (remotetestrunner. java: 390) at Org. eclipse. jdt. internal. JUnit. runner. remotetestrunner. main (remotetestrunner. java: 197) caused by: Org. apache. lucene. queryparser. parseexception: '*' or '? 'Not allowed as first character in wildcardqueryat Org. apache. lucene. queryparser. queryparser. getwildcardquery (queryparser. java: 923) at Org. apache. lucene. queryparser. multifieldqueryparser. getwildcardquery (multifieldqueryparser. java: 175) at Org. apache. lucene. queryparser. multifieldqueryparser. getwildcardquery (multifieldqueryparser. java: 170) at Org. apache. lucene. queryparser. queryparser. term (queryparser. java: 1347) at Org. apache. lucene. queryparser. queryparser. clause (queryparser. java: 1250) at Org. apache. lucene. queryparser. queryparser. query (queryparser. java: 1178) at Org. apache. lucene. queryparser. queryparser. toplevelquery (queryparser. java: 1167) at Org. apache. lucene. queryparser. queryparser. parse (queryparser. java: 182 )... 24 more

The error message reminds me that when you use the WildCardQuery object to query, there cannot be "?" before the query keyword. And "*".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.