使用CJKAnalyzer的Apache Lucene Indexer搜索

时间:2018-07-02 06:13:51

标签: java apache lucene analyzer indexer

public class StudentResult
{
  public static void main(String[] args)
  {
    // Creating Student Objects
    Student student1 = new Student("Bob", 45);
    Student student2 = new Student("John", 70);

    Student[] students = { student1, student2 };

    // Using for loop to print both names and marks

    for (Student student : students)
    {

      System.out.println(student.getStudentName());
      System.out.println("The marks are " + student.getStudentMarks());

    }
  }
}

例如如果我索引了3个字。即“ぁxまn”,“ぁxま”,“まn”

             I am using Apache lucene Indexer Search to search text, and I am using
 CJKAnalyzer. It search provided word by character, It means 
 If I Search for Japanese word "ぁxまn" , then its showing all 
 the words which is having any character of the provided Japanese word.
             But I dont want this I want search whole word or the 
 word which is having above mentioned word.

现在我的情况是,如果我搜索单词“ぁ×ぁn”,那么它给出的三个结果是错误的。

-------------------索引代码-------------------------- -------

 case 1 :  If I search for "ぁxまn" then it should only give one result.
 case 2 :  If I search for "ぁx" then it should give two result.

--------致电搜索------

writer = getIndexWriter();
List<Document> documents = new ArrayList<>();
Document document1 = createDocument(1, "ぁxまn", "Richard");
writer.addDocument(document1);
writer.commit();



 private static Document createDocument(Integer id, String firstName,  String lastName)
{
    Document document = new Document();
    document.add(new StringField("id", id.toString() , Field.Store.YES));
    document.add(new TextField("firstName", firstName , Field.Store.YES));
    document.add(new TextField("lastName", lastName , Field.Store.YES));
    document.add(new TextField("website", website , Field.Store.YES));
    return document;
}


private static IndexWriter createWriter() throws IOException
{
    FSDirectory dir = FSDirectory.open(Paths.get(INDEX_DIR).toFile());
    IndexWriterConfig config = new                                         
    IndexWriterConfig(Version.LUCENE_44,new CJKAnalyzer());
    IndexWriter writer = new IndexWriter(dir, config);
    return writer;
}

0 个答案:

没有答案
相关问题