lanying56123 发表于 2018-11-1 12:44:39

Solr Tips-shadowisper

  Flexible schema for new field:
  We frequently want to expand our solr index to include new fields, normally, this requires adding new fields tosolr’s schema.xml. Solr provides a handy feature called dynamic field, which allows us to dynamically add new fields into solr index without changing schema definition, as long as the field name following certain pattern.
  We can define dynamic field for common data types and type information is built into the field name. Dynamic field’s “type” attribute maps to a “type” definition section in solr’s schema.xml which defines analyze/tokenize/filter behavior.
  Eg: we want to add user rating field to the product document. User rating is a integer value with range 1-10 and each product can have multiple user ratings. In schema.xml, we have:
  
  
  To submit document to solr:
  doc.addField(“userrate_int_mv”, rating1),doc.addField(“userrate_int_mv”, rating2)..
  In java, we can easily use reflection or annotation to generate the field name based on field type + addition metadata
  Sorting:
  Use separate fields for searching and sorting: field for searching requires a full analyzer that splits it into multiple tokens. field for sorting needs to be preserved as a single token
  Eg:
  
                 
                             
                                
                                
                                
                                
                                
                 
  
  
                 
                                
                                
                                
                                
                 
  
  
  
  
  
  
  Multi-language search:
  Use separate field and field type for multi-language support, so that each language can have different tokenizer and filter configuration
  Eg:
  
                 
                                
                                
                                
                 
  
  
                 
                                
                                
                                
                                
                                
                                
                                
                                
                                
                 
  
  
  
  Multi-language suggestion:
  Define multiple spell checkers with different names inside SpellCheckComponent. Each spell checker is for a specific language and is built on a different field with different analyzer configuration
  Eg:
  
        
              true
              default
              true
              5
              true
        
        
           suggest
        
  
  
  text_spell
                 
                                default
                                org.apache.solr.spelling.suggest.Suggester
                                org.apache.solr.spelling.suggest.tst.TSTLookup
                                autosuggest_en
                                true
                                true
                                0.35
                 
                 
                                en
                                org.apache.solr.spelling.suggest.Suggester
                                org.apache.solr.spelling.suggest.tst.TSTLookup
                                autosuggest_en
                                true
                                true
                                0.35
                 
                 
                                zh
                                org.apache.solr.spelling.suggest.Suggester
                                com.hybris.search.suggest.PinYinTSTLookupFactory
                                spellcheckdata
                                autosuggest_zh
                                true
                                true
                                0.35
                 
  
  During search time, format the query as:
  Query.setQueryType(“/suggest”)    -> matches name of the request handler
  Query.set(“spellcheck.dictionary”,“zh”) -> matches name of the spellchecker in solr configuration
  Query.set(“spellcheck.q”, autosuggest keyword)
  Multi-value>

  A field may appear in filter as well as>  Eg: q=mainquery&fq=status:public&fq=doctype:pdf&facet=on&facet.field=doctype

  Use tag and exclusion to solve the problem: still return>  Eg: q=mainquery&fq=status:public&fq={!tag=dt}doctype:pdf&facet=on&facet.field={!ex=dt}doctype

  Support>  Eg:>
  Renames doctype tomylabelwith exclusion as dt -- useful for display purpose
  Multi-core:
  It is usually good to leverage solr's multi-core feature, one core for each data entity, Eg, product, location, or multiple catalogs, provide that they are>instanceDir for configuration and dataDir for storing index etc. By using multi-core, you can have different indexing and searching configuration for each data entity which leads to greater flexibility.
  For indexing, multi-core can also be used. You can create a backup core for updating index, where the original core still serves normal request and is unaffected. Once the update completes, you perform a core swap operation, and the updated core serves user requests. This has two benefits: 1. search request's response time is not affected while indexing is performed. 2. you can easily rollback to the original index if update corrupts the index.
  
  

页: [1]
查看完整版本: Solr Tips-shadowisper