Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 16c6a575

Přidáno uživatelem Jitka Poubová před více než 4 roky(ů)

Re #7917: Vyhledávání podle neúplných nebo podobných slov
- lze vyhledávat s překlepy či neúplnými slovy
- když nenalezne výsledky, hledá znovu s nejpodobnějším slovem
- vrací se vždy to případně opravené hledané slovo (to bez překlepu)

Zobrazit rozdíly:

be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/SolrService.java
9 9
import org.apache.solr.client.solrj.request.CoreAdminRequest;
10 10
import org.apache.solr.client.solrj.request.schema.SchemaRequest;
11 11
import org.apache.solr.client.solrj.response.QueryResponse;
12
import org.apache.solr.client.solrj.response.SpellCheckResponse;
12 13
import org.apache.solr.client.solrj.response.schema.SchemaResponse;
13 14
import org.apache.solr.common.SolrDocument;
14 15
import org.apache.solr.common.SolrDocumentList;
......
264 265
    public SearchResponse query(String query) throws IOException, SolrServerException  {
265 266
        LOG.trace("SolrService method query called");
266 267
        LOG.debug("Processing query - creating Solr query");
268

  
269
        query = query.toLowerCase();
267 270
        SolrQuery solrQuery = new SolrQuery();
268 271
        solrQuery.set("q", FIELD_TEXT_REGION + ":" + query);
269 272
        solrQuery.setHighlight(true);
......
277 280
        SolrDocumentList docList = response.getResults();
278 281
        Map<String, Map<String, List<String>>> highlight = response.getHighlighting();
279 282

  
283
        // if no documents found, try spell checking and call query again with first alternative
284
        if (docList.size() < 1) {
285
            LOG.info("No documents found, trying spell check...");
286
            SpellCheckResponse spellCheck = response.getSpellCheckResponse();
287

  
288
            if (spellCheck != null && spellCheck.getSuggestionMap().values().size() > 0) {
289
                SpellCheckResponse.Suggestion first = spellCheck.getSuggestionMap().values().iterator().next();
290
                List<String> alternatives = first.getAlternatives();
291

  
292
                if (alternatives.size() > 0) {
293
                    String alternative = alternatives.get(0);
294
                    LOG.info("Spell check found alternative \"" + alternative + "\", calling query again with this alternative as parameter.");
295
                    return query(alternative);
296
                }
297
            }
298

  
299
            LOG.info("Spell check found no alternative.");
300
        }
301

  
280 302
        SearchResponse searchResponse = new SearchResponse();
281 303
        searchResponse.setExpression(query);
282 304

  
solr/core-configs/documents/conf/documents-schema.xml
453 453
  <field name="doc_filename" type="text_general" multiValued="false" stored="true"/>
454 454
  <field name="id" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
455 455
  <field name="img_filename" type="text_general" multiValued="false" stored="true"/>
456
  
457
	<field name="didyoumean" type="text_general" indexed="true" stored="true" multiValued="true"/>
458
	<copyField source="text_region" dest="didyoumean"/>
459
  
456 460
  <field name="text_region" type="text_general" multiValued="false" stored="true"/>
457 461
<field name="text_region_coords" type="text_general" multiValued="false" indexed="false" stored="true"/>
458 462
  <field name="text_line_0" type="text_general" multiValued="false" stored="true"/>
solr/core-configs/documents/conf/solrconfig.xml
698 698
    <lst name="defaults">
699 699
      <str name="echoParams">explicit</str>
700 700
      <int name="rows">10</int>
701
	  
702
	  <str name="df">text_region</str>	  
703
	  
704
	  <str name="spellcheck.dictionary">default</str>
705
      <str name="spellcheck">on</str>
706
      <str name="spellcheck.extendedResults">true</str>
707
      <str name="spellcheck.count">10</str>
708
      <str name="spellcheck.alternativeTermCount">5</str>
709
      <str name="spellcheck.maxResultsForSuggest">5</str>
710
      <str name="spellcheck.collate">true</str>
711
      <str name="spellcheck.collateExtendedResults">true</str>
712
      <str name="spellcheck.maxCollationTries">10</str>
713
      <str name="spellcheck.maxCollations">5</str>
714
    </lst>
715
    <arr name="last-components">
716
      <str>spellcheck</str>
717
    </arr>
701 718
      <!-- Default search field
702 719
         <str name="df">text</str> 
703 720
        -->
704 721
      <!-- Change from JSON to XML format (the default prior to Solr 7.0)
705 722
         <str name="wt">xml</str> 
706 723
        -->
707
    </lst>
724
    <!-- </lst> -->
708 725
    <!-- In addition to defaults, "appends" params can be specified
709 726
         to identify values which should be appended to the list of
710 727
         multi-val params from the query (or the existing "defaults").
......
826 843
    -->
827 844
  <searchComponent name="spellcheck" class="solr.SpellCheckComponent">
828 845

  
829
    <str name="queryAnalyzerFieldType">text_general</str>
846
    <str name="queryAnalyzerFieldType">didyoumean</str>
830 847

  
831 848
    <!-- Multiple "Spell Checkers" can be declared and used by this
832 849
         component
......
835 852
    <!-- a spellchecker built from a field of the main index -->
836 853
    <lst name="spellchecker">
837 854
      <str name="name">default</str>
838
      <str name="field">_text_</str>
855
      <str name="field">text_region</str>
839 856
      <str name="classname">solr.DirectSolrSpellChecker</str>
840 857
      <!-- the spellcheck distance measure used, the default is the internal levenshtein -->
841 858
      <str name="distanceMeasure">internal</str>

Také k dispozici: Unified diff