简体   繁体   中英

Solr - How to weight field entries of a multivalued field?

I store categories in documents which should be weighted in the documents itself, eg Restaurant - 0.5 (= 50%), Bar - 0.25, Music - 0.25. Unfortunately I'm new to solr and don't really know to which feature in solr it could belong.

The documents look like this:

    <str name="id">C1</str>
    <str name="name">Wine</str>
    <str name="type">Compass</str>
    <str name="geo">51.049842,13.740707</str>
    <double name="radius">5.0</double>
    <arr name="cat">
      <str>Restaurant</str>
      <str>Restaurant</str>
      <str>Bar</str>
      <str>Music</str>
    </arr>

How could I query the expected weitght? Is there an other way than store similar entries?

You can achieve this with Payload feature of Solr/Lucene. Getting Started with Payloads will give you the general idea. Your document with payloads will look like:

<str name="id">C1</str>
<str name="name">Wine</str>
<str name="type">Compass</str>
<str name="geo">51.049842,13.740707</str>
<double name="radius">5.0</double>
<arr name="cat">
  <str>Restaurant|50</str>
  <str>Bar|25</str>
  <str>Music|25</str>
</arr>

After you indexed the document you can have a custom score for your document, that can be based only on payloads or on a combination with lucene default span score.

You can find more examples of payload query usage in lucene-solr/tests .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM