2016-08-03 2 views
0

Lucene (5.4.1) MoreLikeThis를 사용하여 텍스트를 태그 지정 (분류)하려고합니다. 일종의 일이지만 좋지 않은 결과를 얻고 있습니다. 문제는 Query 개체와 관련이 있다고 생각합니다.Lucene이 검색어를 제한하고 있습니다.

예제에서는 작동하지만 최상위 topdoc은 예상 한 것이 아닙니다. 쿼리 개체를 디버깅하면 content:erro 만 표시됩니다. 완전한 포르투갈어 구문 (예제를 참조하십시오)에서 쿼리는 단 한 단어로 구성되었습니다.

나는 스톱 워드 또는 다른 종류의 필터를 사용하지 않습니다.

왜 lucene은 쿼리 용어로 에로만을 선택합니까?

try (IndexReader idxReader = DirectoryReader.open(indexDir)) { 
     IndexSearcher indexSearcher = new IndexSearcher(idxReader); 

     MoreLikeThis mlt = new MoreLikeThis(idxReader); 
     mlt.setMinTermFreq(0); 
     mlt.setMinDocFreq(0); 
     mlt.setFieldNames(new String[] { "content" }); 
     mlt.setAnalyzer(analyzer); 

     Reader sReader = new StringReader("Melhorias no controle de sessão no sistema qquercoisa quando expira, ao logar novamente no sistema é exibido o erro "xpto"); 

     Query query = mlt.like("content", sReader); 

     TopDocs topDocs = indexSearcher.search(query, 3); 
} 

답변

0

음을 검색하려면 주요 객체 인덱스

try (IndexWriter indexWriter = new IndexWriter(indexDir, config)) { 
    FieldType type = new FieldType(); 
    type.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); 
    type.setStored(true); 
    type.setStoreTermVectors(true); 

    Document doc = new Document(); 
    doc.add(new StringField("id", "880b2bbc", Store.YES)); 
    doc.add(new Field("content", "erro", type)); 
    doc.add(new Field("tag", "atag", type)); 

    indexWriter.addDocument(doc); 
    indexWriter.commit(); 
} 

으로

Analyzer analyzer = new PortugueseAnalyzer(); 

Directory indexDir = new RAMDirectory(); 

IndexWriterConfig config = new IndexWriterConfig(analyzer); 
config.setOpenMode(OpenMode.CREATE_OR_APPEND); 

를 초기화하기 위해서 MoreLoke 내부에서 살펴보기로 결심했고 그 대답을 찾았습니다.

Query query = mlt.like("content", sReader);은 MoreLokeThis 클래스에서 createQueue(Map<String, Int> words) 메서드를 호출합니다.

내부에 sReader의 토큰 화 된 단어/단어 (Map로 변환 됨)가 색인과 비교하여 검사됩니다.

색인에있는 용어/단어 만 검색어를 만드는 데 사용됩니다.

제공된 예제를 사용하면 색인에 erro이라는 단어가있는 문서 만 포함되어 있기 때문에이 단어는 내가 통과 한 문구에서 제외 된 유일한 단어입니다.

관련 문제